mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
Merge pull request #5943 from inspec/cw/backport-oracle-empty-query-fix-inspec-4
Backport Oracle session resource fix when empty results and zero rows
This commit is contained in:
commit
814259f3a4
3 changed files with 42 additions and 3 deletions
|
@ -61,9 +61,13 @@ module Inspec::Resources
|
||||||
raise Inspec::Exceptions::ResourceFailed, "Oracle query with errors: #{out}"
|
raise Inspec::Exceptions::ResourceFailed, "Oracle query with errors: #{out}"
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
DatabaseHelper::SQLQueryResult.new(inspec_cmd, parse_csv_result(inspec_cmd.stdout))
|
unless inspec_cmd.stdout.empty?
|
||||||
rescue
|
DatabaseHelper::SQLQueryResult.new(inspec_cmd, parse_csv_result(inspec_cmd.stdout))
|
||||||
raise Inspec::Exceptions::ResourceFailed, "Oracle query with errors: #{out}"
|
else
|
||||||
|
inspec_cmd.stdout
|
||||||
|
end
|
||||||
|
rescue Exception => ex
|
||||||
|
raise Inspec::Exceptions::ResourceFailed, "Oracle query with exception: #{ex}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
1
test/fixtures/cmd/oracle-empty-result
vendored
Normal file
1
test/fixtures/cmd/oracle-empty-result
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
""
|
|
@ -54,6 +54,23 @@ describe "Inspec::Resources::OracledbSession" do
|
||||||
_(query.row(1).column("value").value).must_equal "ORCL"
|
_(query.row(1).column("value").value).must_equal "ORCL"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "sqlplus Linux with empty output" do
|
||||||
|
resource = quick_resource(:oracledb_session, :linux, as_os_user: "OSUSER", as_db_role: "DBA", host: "localhost", service: "ORCL", port: 1527, sqlplus_bin: "/bin/sqlplus") do |cmd|
|
||||||
|
cmd.strip!
|
||||||
|
case cmd
|
||||||
|
when "su - OSUSER -c \"echo 'oracle_query_string'; env ORACLE_SID=ORCL /bin/sqlplus -S / as DBA <<'EOC'\nSET PAGESIZE 32000\nSET FEEDBACK OFF\nSET UNDERLINE OFF\nSELECT NAME AS VALUE FROM v\\$database;\nEXIT\nEOC\"" then
|
||||||
|
stdout_file "test/fixtures/cmd/oracle-empty-result"
|
||||||
|
else
|
||||||
|
raise cmd.inspect
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
_(resource.resource_skipped?).must_equal false
|
||||||
|
query = resource.query("SELECT NAME AS VALUE FROM v$database;")
|
||||||
|
_(query.size).must_equal 0
|
||||||
|
_(query.row(1).column("value").value).must_equal ""
|
||||||
|
end
|
||||||
|
|
||||||
it "sqlplus 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|
|
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!
|
cmd.strip!
|
||||||
|
@ -88,6 +105,23 @@ describe "Inspec::Resources::OracledbSession" do
|
||||||
_(query.row(1).column("value").value).must_equal "ORCL"
|
_(query.row(1).column("value").value).must_equal "ORCL"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "sqlplus Windows with empty output" 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
|
||||||
|
when "@'\nSET PAGESIZE 32000\nSET FEEDBACK OFF\nSET UNDERLINE OFF\nSELECT NAME AS VALUE FROM v$database;\nEXIT\n'@ | C:/sqlplus.exe -S USER/password@localhost:1527/ORCL" then
|
||||||
|
stdout_file "test/fixtures/cmd/oracle-empty-result"
|
||||||
|
else
|
||||||
|
raise cmd.inspect
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
_(resource.resource_skipped?).must_equal false
|
||||||
|
query = resource.query("SELECT NAME AS VALUE FROM v$database;")
|
||||||
|
_(query.size).must_equal 0
|
||||||
|
_(query.row(1).column("value").value).must_equal ""
|
||||||
|
end
|
||||||
|
|
||||||
it "skipped when sqlplus Windows as_os_user" do
|
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 = quick_resource(:oracledb_session, :windows, user: "USER", password: "password", host: "localhost", service: "ORCL", port: 1527, sqlplus_bin: "C:/sqlplus.exe", as_os_user: "Administrator")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue