mirror of
https://github.com/inspec/inspec
synced 2024-11-27 15:10:44 +00:00
9cfc86d2ab
Light formatting changes, change order of example and matchers, slight color changes Signed-off-by: hannah-radish <hmaddy@chef.io>
61 lines
1.6 KiB
Text
61 lines
1.6 KiB
Text
---
|
|
title: About the mysql_session Resource
|
|
---
|
|
|
|
# mysql_session
|
|
|
|
Use the `mysql_session` InSpec audit resource to test SQL commands run against a MySQL database.
|
|
|
|
<br>
|
|
|
|
## Syntax
|
|
|
|
A `mysql_session` resource block declares the username and password to use for the session, and then the command to be run:
|
|
|
|
describe mysql_session('username', 'password').query('QUERY') do
|
|
its('output') { should eq('') }
|
|
end
|
|
|
|
where
|
|
|
|
* `mysql_session` declares a username and password with permission to run the query
|
|
* `query('QUERY')` contains the query to be run
|
|
* `its('output') { should eq('') }` compares the results of the query against the expected result in the test
|
|
|
|
<br>
|
|
|
|
## Examples
|
|
|
|
The following examples show how to use this InSpec audit resource.
|
|
|
|
### Test for matching databases
|
|
|
|
sql = mysql_session('my_user','password')
|
|
|
|
describe sql.query('show databases like \'test\';') do
|
|
its('stdout') { should_not match(/test/) }
|
|
end
|
|
|
|
### Alternate Connection: Different Host
|
|
|
|
sql = mysql_session('my_user','password','db.example.com')
|
|
|
|
### Alternate Connection: Different Port
|
|
|
|
sql = mysql_seesion('my_user','password','localhost',3307)
|
|
|
|
### Alternate Connection: Using a socket
|
|
|
|
sql = mysql_session('my_user','password', nil, nil, '/var/lib/mysql-default/mysqld.sock')
|
|
|
|
<br>
|
|
|
|
## Matchers
|
|
|
|
This InSpec audit resource has the following matchers. For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
|
|
|
### output
|
|
|
|
The `output` matcher tests the results of the query:
|
|
|
|
its('output') { should eq(/^0/) }
|