2019-06-11 22:24:35 +00:00
require " helper "
require " inspec/resource "
require " inspec/resources/oracledb_session "
2017-05-05 13:29:38 +00:00
2019-06-11 22:24:35 +00:00
describe " Inspec::Resources::OracledbSession " do
2019-10-31 02:11:38 +00:00
it " sqlplus Linux " do
2019-10-30 19:26:12 +00:00
resource = quick_resource ( :oracledb_session , :linux , user : " USER " , password : " password " , host : " localhost " , service : " ORCL " , port : 1527 , sqlplus_bin : " /bin/sqlplus " ) do | cmd |
cmd . strip!
case cmd
2020-02-12 18:17:04 +00:00
when " /bin/sqlplus -S \" USER \" / \" password \" @localhost:1527/ORCL <<'EOC' \n SET MARKUP CSV ON \n SET PAGESIZE 32000 \n SET FEEDBACK OFF \n SELECT NAME AS VALUE FROM v$database; \n EXIT \n EOC " then
2019-11-09 03:08:20 +00:00
stdout_file " test/fixtures/cmd/oracle-result "
2019-10-30 19:26:12 +00:00
else
raise cmd . inspect
end
end
2019-10-31 02:11:38 +00:00
_ ( resource . resource_skipped? ) . must_equal false
2019-10-30 19:26:12 +00:00
query = resource . query ( " SELECT NAME AS VALUE FROM v$database; " )
_ ( query . size ) . must_equal 1
_ ( query . row ( 0 ) . column ( " value " ) . value ) . must_equal " ORCL "
end
2019-10-31 02:11:38 +00:00
it " sqlplus Windows " do
2019-10-30 19:26:12 +00:00
resource = quick_resource ( :oracledb_session , :windows , user : " USER " , password : " password " , host : " localhost " , service : " ORCL " , port : 1527 , sqlplus_bin : " C:/sqlplus.exe " ) do | cmd |
cmd . strip!
case cmd
2020-02-12 18:17:04 +00:00
when " @' \n SET MARKUP CSV ON \n SET PAGESIZE 32000 \n SET FEEDBACK OFF \n SELECT NAME AS VALUE FROM v$database; \n EXIT \n '@ | C:/sqlplus.exe -S \" USER \" / \" password \" @localhost:1527/ORCL " then
2019-11-09 03:08:20 +00:00
stdout_file " test/fixtures/cmd/oracle-result "
2019-10-30 19:26:12 +00:00
else
raise cmd . inspect
end
end
2019-10-31 02:11:38 +00:00
_ ( resource . resource_skipped? ) . must_equal false
2019-10-30 19:26:12 +00:00
query = resource . query ( " SELECT NAME AS VALUE FROM v$database; " )
_ ( query . size ) . must_equal 1
_ ( query . row ( 0 ) . column ( " value " ) . value ) . must_equal " ORCL "
end
2019-10-31 02:11:38 +00:00
it " skipped when sqlplus Windows as_os_user " do
resource = quick_resource ( :oracledb_session , :windows , user : " USER " , password : " password " , host : " localhost " , service : " ORCL " , port : 1527 , sqlplus_bin : " C:/sqlplus.exe " , as_os_user : " Administrator " )
_ ( resource . resource_skipped? ) . must_equal true
_ ( resource . resource_exception_message ) . must_equal " Option 'as_os_user' not available in Windows "
end
it " fails when no user, password, or su " do
resource = quick_resource ( :oracledb_session , :windows , host : " localhost " , service : " ORCL " , port : 1527 , sqlplus_bin : " C:/sqlplus.exe " )
_ ( resource . resource_failed? ) . must_equal true
_ ( resource . resource_exception_message ) . must_equal " Can't run Oracle checks without authentication "
end
it " fails when no service name is provided " do
resource = quick_resource ( :oracledb_session , :windows , user : " USER " , password : " password " , host : " localhost " , port : 1527 , sqlplus_bin : " C:/sqlplus.exe " )
_ ( resource . resource_failed? ) . must_equal true
_ ( resource . resource_exception_message ) . must_equal " You must provide a service name for the session "
end
2019-06-11 22:24:35 +00:00
it " verify oracledb_session configuration " do
2019-10-31 02:11:38 +00:00
resource = quick_resource ( :oracledb_session , :linux , user : " USER " , password : " password " , host : " localhost " , service : " ORCL " , as_db_role : " dbrole " , as_os_user : " osuser " )
_ ( resource . user ) . must_equal " USER "
_ ( resource . password ) . must_equal " password "
2019-06-11 22:24:35 +00:00
_ ( resource . host ) . must_equal " localhost "
2019-10-31 02:11:38 +00:00
_ ( resource . port ) . must_equal " 1521 "
_ ( resource . service ) . must_equal " ORCL "
_ ( resource . db_role ) . must_equal " dbrole "
_ ( resource . su_user ) . must_equal " osuser "
_ ( resource . bin ) . must_equal " sqlplus "
2017-06-29 15:01:32 +00:00
end
2017-05-05 13:29:38 +00:00
end