2017-05-02 14:35:54 +00:00
---
title: About the mssql_session Resource
---
# mssql_session
Use the `mssql_session` InSpec audit resource to test SQL commands run against a Microsoft SQL database.
## 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
* `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 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.
* `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
## Matchers
This InSpec audit resource has the following matchers:
### cmp
<%= partial "/shared/matcher_cmp" %>
### eq
<%= partial "/shared/matcher_eq" %>
## Examples
The following examples show how to use this InSpec audit resource.
### 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