2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/postgres_session"
|
2020-06-29 22:43:10 +00:00
|
|
|
require "inspec/resources/command"
|
2017-07-03 06:10:27 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::PostgresSession" do
|
|
|
|
it "verify postgres_session create_psql_cmd with a basic query" do
|
|
|
|
resource = load_resource("postgres_session", "myuser", "mypass", "127.0.0.1")
|
|
|
|
_(resource.send(:create_psql_cmd, "SELECT * FROM STUDENTS;", ["testdb"])).must_equal "PGPASSWORD='mypass' psql -U myuser -d testdb -h 127.0.0.1 -A -t -c SELECT\\ \\*\\ FROM\\ STUDENTS\\;"
|
2017-07-03 06:10:27 +00:00
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify postgres_session escaped_query with a complex query" do
|
|
|
|
resource = load_resource("postgres_session", "myuser", "mypass", "127.0.0.1")
|
|
|
|
_(resource.send(:create_psql_cmd, "SELECT current_setting('client_min_messages')", ["testdb"])).must_equal "PGPASSWORD='mypass' psql -U myuser -d testdb -h 127.0.0.1 -A -t -c SELECT\\ current_setting\\(\\'client_min_messages\\'\\)"
|
2017-07-03 06:10:27 +00:00
|
|
|
end
|
2020-06-29 22:43:10 +00:00
|
|
|
it "verify postgres_session redacts output" do
|
|
|
|
cmd = %q{PGPASSWORD='mypass' psql -U myuser -d testdb -h 127.0.0.1 -A -t -c "SELECT current_setting('client_min_messages')"}
|
|
|
|
options = { redact_regex: /(PGPASSWORD=').+(' psql .*)/ }
|
|
|
|
resource = load_resource("command", cmd, options)
|
|
|
|
|
|
|
|
expected_to_s = %q{Command: `PGPASSWORD='REDACTED' psql -U myuser -d testdb -h 127.0.0.1 -A -t -c "SELECT current_setting('client_min_messages')"`}
|
|
|
|
_(resource.to_s).must_equal(expected_to_s)
|
|
|
|
end
|
2017-07-03 06:10:27 +00:00
|
|
|
end
|