Merge pull request #5619 from inspec/vasundhara/fix_postgres_session_error

Fix postgres_session error Unable to connect to database
This commit is contained in:
Clinton Wolfe 2021-08-23 08:11:22 -04:00 committed by GitHub
commit ebfb89bd65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 8 deletions

View file

@ -46,8 +46,6 @@ module Inspec::Resources
@host = host || "localhost"
@port = port || 5432
raise Inspec::Exceptions::ResourceFailed, "Can't run PostgreSQL SQL checks without authentication." if @user.nil? || @pass.nil?
test_connection
end
def query(query, db = [])
@ -65,10 +63,6 @@ module Inspec::Resources
private
def test_connection
query("select now()\;")
end
def escaped_query(query)
Shellwords.escape(query)
end

View file

@ -35,7 +35,6 @@ describe "Inspec::Resources::PostgresSession" do
end
it "fails when no connection established" do
resource = load_resource("postgres_session", "postgres", "postgres", "localhost", 5432)
_(resource.resource_failed?).must_equal true
_(resource.resource_exception_message).must_include "PostgreSQL query with errors"
_(proc { resource.send(:query, "Select 5;", ["mydatabase"]) }).must_raise Inspec::Exceptions::ResourceFailed
end
end