Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ static bool send_client_authreq(PgSocket *client)
return false;
}

if (!res)
if (!res) {
slog_noise(client, "No authentication response received");
disconnect_client(client, false, "failed to send auth req");
} else {
slog_noise(client, "Auth request sent successfully");
}
return res;
}

Expand Down Expand Up @@ -804,7 +808,7 @@ static bool handle_client_startup(PgSocket *client, PktHdr *pkt)
return false;
if (scram_client_final(client, length, data)) {
/* save SCRAM keys for user */
if (!client->scram_state.adhoc) {
if (!client->scram_state.adhoc && !client->db->fake) {
memcpy(client->pool->user->scram_ClientKey,
client->scram_state.ClientKey,
sizeof(client->scram_state.ClientKey));
Expand Down
47 changes: 47 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,50 @@ test_no_database_auth_user() {
return 0
}

test_no_database_md5_auth_scram_pw_success() {
# Testing what happens on successful SCRAM auth connection to non-existent DB
# Segfaults have been seen after mock authentication was put in place
# with md5 auth and a scram PW when saving SCRAM credentials. Including this test to check for the
# condition repeating.

$have_getpeereid || return 77

admin "set auth_type='md5'"
PGPASSWORD=foo psql -X -U scramuser1 -d nosuchdb1 -c "select 1" && return 1
grep -F "no such database: nosuchdb1" $BOUNCER_LOG || return 1

return 0
}

test_no_database_scram_auth_scram_pw_success() {
# Testing what happens on successful SCRAM auth with a SCRAM PW connection to non-existent DB
# Segfaults have been seen after mock authentication was put in place
# with md5 auth and a scram PW. Including this test for completeness

$have_getpeereid || return 77

admin "set auth_type='scram-sha-256'"
PGPASSWORD=foo psql -X -U scramuser1 -d nosuchdb1 -c "select 1" && return 1
grep -F "no such database: nosuchdb1" $BOUNCER_LOG || return 1

return 0
}

test_no_database_md5_auth_md5_pw_success() {
# Testing what happens on successful MD5 auth with a MD5 pw connection to non-existent DB
# Segfaults have been seen after mock authentication was put in place
# with md5 auth and a scram PW. Including this test for completeness

$have_getpeereid || return 77

admin "set auth_type='md5'"
PGPASSWORD=foo psql -X -U muser1 -d nosuchdb1 -c "select 1" && return 1
grep -F "no such database: nosuchdb1" $BOUNCER_LOG || return 1

return 0
}


test_cancel() {
case `uname` in MINGW*) return 77;; esac

Expand Down Expand Up @@ -1442,6 +1486,9 @@ test_auto_database
test_no_database
test_no_database_authfail
test_no_database_auth_user
test_no_database_md5_auth_scram_pw_success
test_no_database_scram_auth_scram_pw_success
test_no_database_md5_auth_md5_pw_success
test_cancel
test_cancel_wait
test_cancel_pool_size
Expand Down