let there be tests

Signed-off-by: Miah Johnson <miah@chia-pet.org>
This commit is contained in:
Miah Johnson 2019-10-30 19:11:38 -07:00
parent 6bab53cbd3
commit 314715d9f8

View file

@ -3,7 +3,7 @@ require "inspec/resource"
require "inspec/resources/oracledb_session"
describe "Inspec::Resources::OracledbSession" do
it "Linux" do
it "sqlplus Linux" do
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
@ -14,12 +14,13 @@ describe "Inspec::Resources::OracledbSession" do
end
end
_(resource.resource_skipped?).must_equal false
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
it "Windows" do
it "sqlplus Windows" do
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
@ -30,16 +31,42 @@ describe "Inspec::Resources::OracledbSession" do
end
end
_(resource.resource_skipped?).must_equal false
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
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
it "verify oracledb_session configuration" do
resource = load_resource("oracledb_session", user: "SYSTEM", password: "supersecurepass", host: "localhost", service: "ORCL.localdomain")
_(resource.user).must_equal "SYSTEM"
_(resource.password).must_equal "supersecurepass"
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"
_(resource.host).must_equal "localhost"
_(resource.service).must_equal "ORCL.localdomain"
_(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"
end
end