Skip to content

Commit 736173f

Browse files
committed
Fix SCRAM tests
Removes custom assert.throws(...) so that the real one from the assert package is used and fixes the SCRAM tests to reflect the updated error messages and actual checking of errors. Previously the custom assert.throws(...) was ignoring the error signature validation.
1 parent 0a5498b commit 736173f

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

Diff for: packages/pg/test/test-helper.js

-10
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,6 @@ assert.success = function (callback) {
111111
}
112112
}
113113

114-
assert.throws = function (offender) {
115-
try {
116-
offender()
117-
} catch (e) {
118-
assert.ok(e instanceof Error, 'Expected ' + offender + ' to throw instances of Error')
119-
return
120-
}
121-
assert.ok(false, 'Expected ' + offender + ' to throw exception')
122-
}
123-
124114
assert.lengthIs = function (actual, expectedLength) {
125115
assert.equal(actual.length, expectedLength)
126116
}

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

+31-10
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test('sasl/scram', function () {
3838
test('fails when last session message was not SASLInitialResponse', function () {
3939
assert.throws(
4040
function () {
41-
sasl.continueSession({})
41+
sasl.continueSession({}, '', '')
4242
},
4343
{
4444
message: 'SASL: Last message was not SASLInitialResponse',
@@ -53,6 +53,7 @@ test('sasl/scram', function () {
5353
{
5454
message: 'SASLInitialResponse',
5555
},
56+
'bad-password',
5657
's=1,i=1'
5758
)
5859
},
@@ -69,6 +70,7 @@ test('sasl/scram', function () {
6970
{
7071
message: 'SASLInitialResponse',
7172
},
73+
'bad-password',
7274
'r=1,i=1'
7375
)
7476
},
@@ -85,7 +87,8 @@ test('sasl/scram', function () {
8587
{
8688
message: 'SASLInitialResponse',
8789
},
88-
'r=1,s=1'
90+
'bad-password',
91+
'r=1,s=abcd'
8992
)
9093
},
9194
{
@@ -102,7 +105,8 @@ test('sasl/scram', function () {
102105
message: 'SASLInitialResponse',
103106
clientNonce: '2',
104107
},
105-
'r=1,s=1,i=1'
108+
'bad-password',
109+
'r=1,s=abcd,i=1'
106110
)
107111
},
108112
{
@@ -117,12 +121,12 @@ test('sasl/scram', function () {
117121
clientNonce: 'a',
118122
}
119123

120-
sasl.continueSession(session, 'password', 'r=ab,s=x,i=1')
124+
sasl.continueSession(session, 'password', 'r=ab,s=abcd,i=1')
121125

122126
assert.equal(session.message, 'SASLResponse')
123-
assert.equal(session.serverSignature, 'TtywIrpWDJ0tCSXM2mjkyiaa8iGZsZG7HllQxr8fYAo=')
127+
assert.equal(session.serverSignature, 'jwt97IHWFn7FEqHykPTxsoQrKGOMXJl/PJyJ1JXTBKc=')
124128

125-
assert.equal(session.response, 'c=biws,r=ab,p=KAEPBUTjjofB0IM5UWcZApK1dSzFE0o5vnbWjBbvFHA=')
129+
assert.equal(session.response, 'c=biws,r=ab,p=mU8grLfTjDrJer9ITsdHk0igMRDejG10EJPFbIBL3D0=')
126130
})
127131
})
128132

@@ -138,15 +142,32 @@ test('sasl/scram', function () {
138142
)
139143
})
140144

145+
test('fails when server signature is not valid base64', function () {
146+
assert.throws(
147+
function () {
148+
sasl.finalizeSession(
149+
{
150+
message: 'SASLResponse',
151+
serverSignature: 'abcd',
152+
},
153+
'v=x1' // Purposefully invalid base64
154+
)
155+
},
156+
{
157+
message: 'SASL: SCRAM-SERVER-FINAL-MESSAGE: server signature must be base64',
158+
}
159+
)
160+
})
161+
141162
test('fails when server signature does not match', function () {
142163
assert.throws(
143164
function () {
144165
sasl.finalizeSession(
145166
{
146167
message: 'SASLResponse',
147-
serverSignature: '3',
168+
serverSignature: 'abcd',
148169
},
149-
'v=4'
170+
'v=xyzq'
150171
)
151172
},
152173
{
@@ -159,9 +180,9 @@ test('sasl/scram', function () {
159180
sasl.finalizeSession(
160181
{
161182
message: 'SASLResponse',
162-
serverSignature: '5',
183+
serverSignature: 'abcd',
163184
},
164-
'v=5'
185+
'v=abcd'
165186
)
166187
})
167188
})

0 commit comments

Comments
 (0)