Skip to content

Commit 49432be

Browse files
committed
Add informative error when SASL password is empty string
1 parent 16b2ecf commit 49432be

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

packages/pg/lib/sasl.js

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ function continueSession(session, password, serverData) {
2323
if (typeof password !== 'string') {
2424
throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string')
2525
}
26+
if (password === '') {
27+
throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a non-empty string')
28+
}
2629
if (typeof serverData !== 'string') {
2730
throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: serverData must be a string')
2831
}

packages/pg/test/unit/client/sasl-scram-tests.js

+18
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ test('sasl/scram', function () {
100100
}
101101
})
102102

103+
test('fails when client password is an empty string', function () {
104+
assert.throws(
105+
function () {
106+
sasl.continueSession(
107+
{
108+
message: 'SASLInitialResponse',
109+
clientNonce: 'a',
110+
},
111+
'',
112+
'r=1,i=1'
113+
)
114+
},
115+
{
116+
message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a non-empty string',
117+
}
118+
)
119+
})
120+
103121
test('fails when iteration is missing in server message', function () {
104122
assert.throws(
105123
function () {

0 commit comments

Comments
 (0)