mirror of
https://github.com/inspec/inspec
synced 2024-11-26 14:40:26 +00:00
* Add support for custom port with a socket connection Signed-off-by: Pg <pg.developper.fr@gmail.com> * Add tests for the postgres_session with custom port Signed-off-by: Pg <pg.developper.fr@gmail.com> --------- Signed-off-by: Pg <pg.developper.fr@gmail.com>
This commit is contained in:
parent
30fa76a5af
commit
869e1902a1
2 changed files with 7 additions and 2 deletions
|
@ -81,7 +81,8 @@ module Inspec::Resources
|
|||
# Socket path and empty host in the connection string establishes socket connection
|
||||
# Socket connection only enabled for non-windows platforms
|
||||
# Windows does not support unix domain sockets
|
||||
"psql -d postgresql://#{@user}:#{@pass}@/#{dbs}?host=#{@socket_path} -A -t -w -c #{escaped_query(query)}"
|
||||
option_port = @port.nil? ? "" : "-p #{@port}" # add explicit port if specified
|
||||
"psql -d postgresql://#{@user}:#{@pass}@/#{dbs}?host=#{@socket_path} #{option_port} -A -t -w -c #{escaped_query(query)}"
|
||||
else
|
||||
# Host in connection string establishes tcp/ip connection
|
||||
if inspec.os.windows?
|
||||
|
|
|
@ -39,7 +39,11 @@ describe "Inspec::Resources::PostgresSession" do
|
|||
end
|
||||
it "verify postgres_session create_psql_cmd in socket connection" do
|
||||
resource = load_resource("postgres_session", "myuser", "mypass", "127.0.0.1", 5432, "/var/run/postgresql")
|
||||
_(resource.send(:create_psql_cmd, "SELECT * FROM STUDENTS;", ["testdb"])).must_equal "psql -d postgresql://myuser:mypass@/testdb?host=/var/run/postgresql -A -t -w -c SELECT\\ \\*\\ FROM\\ STUDENTS\\;"
|
||||
_(resource.send(:create_psql_cmd, "SELECT * FROM STUDENTS;", ["testdb"])).must_equal "psql -d postgresql://myuser:mypass@/testdb?host=/var/run/postgresql -p 5432 -A -t -w -c SELECT\\ \\*\\ FROM\\ STUDENTS\\;"
|
||||
end
|
||||
it "verify postgres_session create_psql_cmd in socket connection" do
|
||||
resource = load_resource("postgres_session", "myuser", "mypass", "127.0.0.1", 1234, "/var/run/postgresql")
|
||||
_(resource.send(:create_psql_cmd, "SELECT * FROM STUDENTS;", ["testdb"])).must_equal "psql -d postgresql://myuser:mypass@/testdb?host=/var/run/postgresql -p 1234 -A -t -w -c SELECT\\ \\*\\ FROM\\ STUDENTS\\;"
|
||||
end
|
||||
|
||||
it "fails when no connection established in linux" do
|
||||
|
|
Loading…
Reference in a new issue