2017-05-02 14:35:54 +00:00
---
title: About the mssql_session Resource
2018-02-16 00:28:15 +00:00
platform: windows
2017-05-02 14:35:54 +00:00
---
# mssql_session
2019-04-26 18:24:29 +00:00
Use the `mssql_session` Chef InSpec audit resource to test SQL commands run against a Microsoft SQL database.
2017-05-02 14:35:54 +00:00
2017-10-03 21:35:10 +00:00
<br>
2018-08-09 12:34:49 +00:00
## Availability
### Installation
2019-04-26 18:24:29 +00:00
This resource is distributed along with Chef InSpec itself. You can use it automatically.
2018-08-09 12:34:49 +00:00
### Version
This resource first became available in v1.24.0 of InSpec.
2017-05-02 14:35:54 +00:00
## Syntax
A `mssql_session` resource block declares the username and password to use for the session, and then the command to be run:
2017-06-29 15:01:32 +00:00
describe mssql_session(user: 'username', password: 'password').query('QUERY').row(0).column('result') do
its('value') { should eq('') }
2017-05-02 14:35:54 +00:00
end
where
2019-04-26 18:24:29 +00:00
* `mssql_session` declares a username and password with permission to run the query. Omitting the username or password parameters results in the use of Windows authentication as the user Chef InSpec is executing as. You may also optionally pass a host and instance name. If omitted, they will default to host: localhost and the default instance.
2017-05-02 14:35:54 +00:00
* `query('QUERY')` contains the query to be run
2017-06-29 15:01:32 +00:00
* `its('value') { should eq('') }` compares the results of the query against the expected result in the test
2017-05-02 14:35:54 +00:00
2017-10-03 21:35:10 +00:00
<br>
2017-05-02 14:35:54 +00:00
## Examples
2019-04-26 18:24:29 +00:00
The following examples show how to use this Chef InSpec audit resource.
2017-05-02 14:35:54 +00:00
### Test for matching databases
2017-06-29 15:01:32 +00:00
sql = mssql_session(user: 'my_user', password: 'password')
2017-05-02 14:35:54 +00:00
2017-06-29 15:01:32 +00:00
describe sql.query("SELECT SERVERPROPERTY('ProductVersion') as result").row(0).column('result') do
its("value") { should cmp > '12.00.4457' }
2017-05-02 14:35:54 +00:00
end
### Test using Windows authentication
sql = mssql_session
2017-06-29 15:01:32 +00:00
describe sql.query("SELECT SERVERPROPERTY('ProductVersion') as result").row(0).column('result') do
its("value") { should cmp > '12.00.4457' }
2017-05-02 14:35:54 +00:00
end
### Test a specific host and instance
2017-06-29 15:01:32 +00:00
sql = mssql_session(user: 'my_user', password: 'password', host: 'mssqlserver', instance: 'foo')
2017-05-02 14:35:54 +00:00
2017-06-29 15:01:32 +00:00
describe sql.query("SELECT SERVERPROPERTY('ProductVersion') as result").row(0).column('result') do
its("value") { should cmp > '12.00.4457' }
2017-05-02 14:35:54 +00:00
end
2018-09-18 00:59:31 +00:00
### Test a specific database
sql = mssql_session(user: 'my_user', password: 'password', db_name: 'test')
describe sql.query("SELECT Name AS result FROM Product WHERE ProductID == 1").row(0).column('result') do
its("value") { should eq 'foo' }
end
2017-10-03 21:35:10 +00:00
<br>
## Matchers
2018-02-16 03:07:18 +00:00
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).