Skip to content

Commit b141092

Browse files
committed
cleanup: Add missing awaits when using assert.rejects in tests; remove unneeded function wrappers
1 parent 635f425 commit b141092

1 file changed

Lines changed: 61 additions & 78 deletions

File tree

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

Lines changed: 61 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -58,118 +58,101 @@ suite.test('sasl/scram', function () {
5858
})
5959

6060
suite.test('continueSession', function () {
61-
suite.test('fails when last session message was not SASLInitialResponse', async function () {
62-
assert.rejects(
63-
function () {
64-
return sasl.continueSession({}, '', '')
65-
},
66-
{
67-
message: 'SASL: Last message was not SASLInitialResponse',
68-
}
69-
)
61+
suite.test('fails when last session message was not SASLInitialResponse', async () => {
62+
await assert.rejects(sasl.continueSession({}, '', ''), {
63+
message: 'SASL: Last message was not SASLInitialResponse',
64+
})
7065
})
7166

72-
suite.test('fails when nonce is missing in server message', function () {
73-
assert.rejects(
74-
function () {
75-
return sasl.continueSession(
76-
{
77-
message: 'SASLInitialResponse',
78-
},
79-
'bad-password',
80-
's=1,i=1'
81-
)
82-
},
67+
suite.test('fails when nonce is missing in server message', async () => {
68+
await assert.rejects(
69+
sasl.continueSession(
70+
{
71+
message: 'SASLInitialResponse',
72+
},
73+
'bad-password',
74+
's=1,i=1'
75+
),
8376
{
8477
message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce missing',
8578
}
8679
)
8780
})
8881

89-
suite.test('fails when salt is missing in server message', function () {
90-
assert.rejects(
91-
function () {
92-
return sasl.continueSession(
93-
{
94-
message: 'SASLInitialResponse',
95-
},
96-
'bad-password',
97-
'r=1,i=1'
98-
)
99-
},
82+
suite.test('fails when salt is missing in server message', async () => {
83+
await assert.rejects(
84+
sasl.continueSession(
85+
{
86+
message: 'SASLInitialResponse',
87+
},
88+
'bad-password',
89+
'r=1,i=1'
90+
),
10091
{
10192
message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: salt missing',
10293
}
10394
)
10495
})
10596

106-
suite.test('fails when client password is not a string', function () {
97+
suite.test('fails when client password is not a string', async () => {
10798
for (const badPasswordValue of [null, undefined, 123, new Date(), {}]) {
108-
assert.rejects(
109-
function () {
110-
return sasl.continueSession(
111-
{
112-
message: 'SASLInitialResponse',
113-
clientNonce: 'a',
114-
},
115-
badPasswordValue,
116-
'r=1,i=1'
117-
)
118-
},
99+
await assert.rejects(
100+
sasl.continueSession(
101+
{
102+
message: 'SASLInitialResponse',
103+
clientNonce: 'a',
104+
},
105+
badPasswordValue,
106+
'r=1,i=1'
107+
),
119108
{
120109
message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string',
121110
}
122111
)
123112
}
124113
})
125114

126-
suite.test('fails when client password is an empty string', function () {
127-
assert.rejects(
128-
function () {
129-
return sasl.continueSession(
130-
{
131-
message: 'SASLInitialResponse',
132-
clientNonce: 'a',
133-
},
134-
'',
135-
'r=1,i=1'
136-
)
137-
},
115+
suite.test('fails when client password is an empty string', async () => {
116+
await assert.rejects(
117+
sasl.continueSession(
118+
{
119+
message: 'SASLInitialResponse',
120+
clientNonce: 'a',
121+
},
122+
'',
123+
'r=1,i=1'
124+
),
138125
{
139126
message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a non-empty string',
140127
}
141128
)
142129
})
143130

144-
suite.test('fails when iteration is missing in server message', function () {
145-
assert.rejects(
146-
function () {
147-
return sasl.continueSession(
148-
{
149-
message: 'SASLInitialResponse',
150-
},
151-
'bad-password',
152-
'r=1,s=abcd'
153-
)
154-
},
131+
suite.test('fails when iteration is missing in server message', async () => {
132+
await assert.rejects(
133+
sasl.continueSession(
134+
{
135+
message: 'SASLInitialResponse',
136+
},
137+
'bad-password',
138+
'r=1,s=abcd'
139+
),
155140
{
156141
message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: iteration missing',
157142
}
158143
)
159144
})
160145

161-
suite.test('fails when server nonce does not start with client nonce', function () {
162-
assert.rejects(
163-
function () {
164-
return sasl.continueSession(
165-
{
166-
message: 'SASLInitialResponse',
167-
clientNonce: '2',
168-
},
169-
'bad-password',
170-
'r=1,s=abcd,i=1'
171-
)
172-
},
146+
suite.test('fails when server nonce does not start with client nonce', async () => {
147+
await assert.rejects(
148+
sasl.continueSession(
149+
{
150+
message: 'SASLInitialResponse',
151+
clientNonce: '2',
152+
},
153+
'bad-password',
154+
'r=1,s=abcd,i=1'
155+
),
173156
{
174157
message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce does not start with client nonce',
175158
}

0 commit comments

Comments
 (0)