2017-05-02 14:35:54 +00:00
|
|
|
|
|
|
|
require 'helper'
|
2019-05-25 08:33:26 +00:00
|
|
|
require 'inspec/resource'
|
|
|
|
require 'inspec/resources/mssql_session'
|
2017-05-02 14:35:54 +00:00
|
|
|
|
|
|
|
describe 'Inspec::Resources::MssqlSession' do
|
2018-01-16 22:04:00 +00:00
|
|
|
it 'verify default mssql_session configuration' do
|
|
|
|
resource = load_resource('mssql_session', user: 'sa', password: 'yourStrong(!)Password')
|
2017-06-29 15:01:32 +00:00
|
|
|
_(resource.user).must_equal 'sa'
|
|
|
|
_(resource.password).must_equal 'yourStrong(!)Password'
|
|
|
|
_(resource.host).must_equal 'localhost'
|
2018-01-16 22:04:00 +00:00
|
|
|
_(resource.port).must_equal '1433'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'verify mssql_session configuration with custom hostname' do
|
|
|
|
resource = load_resource('mssql_session', user: 'sa', password: 'yourStrong(!)Password', host: 'inspec.domain.tld')
|
|
|
|
_(resource.user).must_equal 'sa'
|
|
|
|
_(resource.password).must_equal 'yourStrong(!)Password'
|
|
|
|
_(resource.host).must_equal 'inspec.domain.tld'
|
|
|
|
_(resource.port).must_equal '1433'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'verify mssql_session configuration with custom instance' do
|
|
|
|
resource = load_resource('mssql_session', user: 'sa', password: 'yourStrong(!)Password', instance: 'SQL2012INSPEC')
|
|
|
|
_(resource.user).must_equal 'sa'
|
|
|
|
_(resource.password).must_equal 'yourStrong(!)Password'
|
|
|
|
_(resource.host).must_equal 'localhost'
|
|
|
|
_(resource.port).must_equal '1433'
|
|
|
|
_(resource.instance).must_equal 'SQL2012INSPEC'
|
2017-06-29 15:01:32 +00:00
|
|
|
end
|
|
|
|
|
2018-05-31 17:47:28 +00:00
|
|
|
it 'verify mssql_session configuration with custom instance and port' do
|
|
|
|
resource = load_resource('mssql_session', user: 'sa', password: 'yourStrong(!)Password', instance: 'SQL2012INSPEC', port: '1691')
|
|
|
|
_(resource.user).must_equal 'sa'
|
|
|
|
_(resource.password).must_equal 'yourStrong(!)Password'
|
|
|
|
_(resource.host).must_equal 'localhost'
|
|
|
|
_(resource.port).must_equal '1691'
|
|
|
|
_(resource.instance).must_equal 'SQL2012INSPEC'
|
|
|
|
end
|
|
|
|
|
2017-09-18 19:49:20 +00:00
|
|
|
it 'verify mssql_session configuration with custom sqlserver port and user in domain' do
|
2018-01-16 22:04:00 +00:00
|
|
|
resource = load_resource('mssql_session', user: 'DOMAIN\sa', password: 'yourStrong(!)Password', host: 'localhost', port: '1533')
|
2017-09-18 19:49:20 +00:00
|
|
|
_(resource.user).must_equal 'DOMAIN\sa'
|
|
|
|
_(resource.password).must_equal 'yourStrong(!)Password'
|
2018-01-16 22:04:00 +00:00
|
|
|
_(resource.host).must_equal 'localhost'
|
|
|
|
_(resource.port).must_equal '1533'
|
2017-09-18 19:49:20 +00:00
|
|
|
end
|
|
|
|
|
2018-05-31 17:47:28 +00:00
|
|
|
it 'verify mssql_session configuration with port explicitly nil' do
|
|
|
|
resource = load_resource('mssql_session', user: 'sa', password: 'yourStrong(!)Password', host: 'localhost', port: nil)
|
|
|
|
_(resource.user).must_equal 'sa'
|
|
|
|
_(resource.password).must_equal 'yourStrong(!)Password'
|
|
|
|
_(resource.host).must_equal 'localhost'
|
|
|
|
_(resource.port).must_be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'verify mssql_session configuration with local mode' do
|
|
|
|
resource = load_resource('mssql_session', local_mode: true)
|
|
|
|
_(resource.user).must_be_nil
|
|
|
|
_(resource.password).must_be_nil
|
|
|
|
_(resource.host).must_be_nil
|
|
|
|
_(resource.port).must_be_nil
|
|
|
|
_(resource.local_mode).must_equal true
|
|
|
|
end
|
|
|
|
|
2017-06-29 15:01:32 +00:00
|
|
|
it 'run a SQL query' do
|
|
|
|
resource = load_resource('mssql_session', user: 'sa', password: 'yourStrong(!)Password', host: 'localhost')
|
|
|
|
query = resource.query("SELECT SERVERPROPERTY('ProductVersion') as result")
|
|
|
|
_(query.size).must_equal 1
|
|
|
|
_(query.row(0).column('result').value).must_equal '14.0.600.250'
|
2017-05-02 14:35:54 +00:00
|
|
|
end
|
|
|
|
end
|