Skip to content

Commit bbbdf41

Browse files
committed
Fix tests and special character username test
Add URI encoding of user and db name in tests that use the connection URI to access a container, test that it works with both spaces and special characters. This is because postgres 18 does not accept spaces in the connection URI but earlier versions do.
1 parent 9965e02 commit bbbdf41

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

test/run_test

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@ function get_ip_from_cid() {
110110
}
111111

112112
function postgresql_cmd() {
113-
docker run --rm -e PGPASSWORD="$PASS" "$IMAGE_NAME" psql -v ON_ERROR_STOP=1 "postgresql://$PGUSER@$CONTAINER_IP:5432/${DB-db}" "$@"
113+
# URI encode the values used inside the connection URI to avoid special
114+
# characters causing the tests using them to fail.
115+
# These tests should not fail because the container is created just fine
116+
# as it uses just environment variables. We need both the creation and
117+
# connection to use the same values, which this use of `jq` ensures.
118+
USERENC=$(jq -rn --arg x "$PGUSER" '$x|@uri')
119+
DBENC=$(jq -rn --arg x "${DB-db}" '$x|@uri')
120+
docker run --rm -e PGPASSWORD="$PASS" "$IMAGE_NAME" psql -v ON_ERROR_STOP=1 "postgresql://$USERENC@$CONTAINER_IP:5432/$DBENC" "$@"
114121
}
115122

116123
function test_connection() {
@@ -647,7 +654,10 @@ VERY_LONG_IDENTIFIER="very_long_identifier_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
647654
assert_container_creation_succeeds -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db -e POSTGRESQL_ADMIN_PASSWORD="\"" || ret=8
648655

649656
assert_container_creation_succeeds -e POSTGRESQL_ADMIN_PASSWORD="the @password" || ret=9
657+
# Postgres <18 accepts spaces in the connection URI just fine,
658+
# but 18 does not and tells you to use %20 instead, so we encode every DB- and username.
650659
assert_container_creation_succeeds -e POSTGRESQL_PASSWORD="the pass" -e POSTGRESQL_USER="the user" -e POSTGRESQL_DATABASE="the db" || ret=10
660+
assert_container_creation_succeeds -e POSTGRESQL_PASSWORD="the pass" -e POSTGRESQL_USER="the@user" -e POSTGRESQL_DATABASE="the/db" || ret=10
651661

652662
if [ $ret -eq 0 ]; then
653663
echo " Success!"

0 commit comments

Comments
 (0)