2017-05-01 18:02:15 +00:00
---
2017-05-05 17:11:07 +00:00
title: About the oracledb_session Resource
2017-05-01 18:02:15 +00:00
---
2017-05-05 17:11:07 +00:00
# oracledb_session
2017-05-01 18:02:15 +00:00
2017-05-05 17:11:07 +00:00
Use the `oracledb_session` InSpec audit resource to test SQL commands run against a Oracle database.
2017-05-01 18:02:15 +00:00
## Syntax
2017-05-05 17:11:07 +00:00
A `oracledb_session` resource block declares the username and password to use for the session with an optional service to connect to, and then the command to be run:
2017-05-01 18:02:15 +00:00
2017-05-05 17:11:07 +00:00
describe oracledb_session(user: 'username', pass: 'password').query('QUERY') do
2017-05-01 18:02:15 +00:00
its('output') { should eq('') }
end
where
2017-05-05 17:11:07 +00:00
* `oracledb_session` declares a username and password with permission to run the query (required), and an optional parameters for host (default: `localhost`), SID (default: `nil`, which uses the default SID, and path to the sqlplus binary (default: `sqlplus`).
2017-05-01 18:02:15 +00:00
* `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
## Matchers
This InSpec audit resource has the following matchers:
### be
<%= partial "/shared/matcher_be" %>
### cmp
<%= partial "/shared/matcher_cmp" %>
### eq
<%= partial "/shared/matcher_eq" %>
### include
<%= partial "/shared/matcher_include" %>
### match
<%= partial "/shared/matcher_match" %>
### output
The `output` matcher tests the results of the query:
its('output') { should eq(/^0/) }
## Examples
The following examples show how to use this InSpec audit resource.
### Test for matching databases
2017-05-05 17:11:07 +00:00
sql = oracledb_session(user: 'my_user', pass: 'password')
2017-05-05 13:29:38 +00:00
describe sql.query('SELECT NAME FROM v$database;') do
its('stdout') { should_not match(/test/) }
end
### Test for matching databases with custom host, SID and sqlplus binary location
2017-05-05 17:11:07 +00:00
sql = oracledb_session(user: 'my_user', pass: 'password', host: 'oraclehost', sid: 'mysid', sqlplus_bin: '/u01/app/oracle/product/12.1.0/dbhome_1/bin/sqlplus')
2017-05-01 18:02:15 +00:00
describe sql.query('SELECT NAME FROM v$database;') do
its('stdout') { should_not match(/test/) }
end