Skip to content
Merged
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
29 changes: 2 additions & 27 deletions packages/pg/test/integration/client/promise-api-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ suite.test('valid connection completes promise', () => {
})
})

suite.test('valid connection completes promise', () => {
const client = new pg.Client()
return client.connect().then(() => {
return client.end().then(() => {})
})
})

suite.test('valid connection returns the client in a promise', () => {
const client = new pg.Client()
return client.connect().then((clientInside) => {
Expand All @@ -28,25 +21,7 @@ suite.test('valid connection returns the client in a promise', () => {
})
})

suite.test('invalid connection rejects promise', (done) => {
suite.test('invalid connection rejects promise', async () => {
const client = new pg.Client({ host: 'alksdjflaskdfj', port: 1234 })
return client.connect().catch((e) => {
assert(e instanceof Error)
done()
})
})

suite.test('connected client does not reject promise after connection', (done) => {
const client = new pg.Client()
return client.connect().then(() => {
setTimeout(() => {
client.on('error', (e) => {
assert(e instanceof Error)
client.end()
done()
})
// manually kill the connection
client.emit('error', new Error('something bad happened...but not really'))
}, 50)
})
await assert.rejects(client.connect(), Error)
})
8 changes: 6 additions & 2 deletions packages/pg/test/integration/gh-issues/3174-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ const testErrorBuffer = (bufferName, errorBuffer) => {
if (!cli.native) {
assert(errorHit)
// further queries on the client should fail since its in an invalid state
await assert.rejects(() => client.query('SELECTR NOW()'), 'Further queries on the client should reject')
await assert.rejects(client.query('SELECT NOW()'), {
message: 'Client has encountered a connection error and is not queryable',
})
}

await closeServer()
Expand All @@ -129,7 +131,9 @@ const testErrorBuffer = (bufferName, errorBuffer) => {
if (!cli.native) {
assert(errorHit)
// further queries on the client should fail since its in an invalid state
await assert.rejects(() => client.query('SELECTR NOW()'), 'Further queries on the client should reject')
await assert.rejects(client.query('SELECT NOW()'), {
message: 'Client has encountered a connection error and is not queryable',
})
}

await client.end()
Expand Down
139 changes: 61 additions & 78 deletions packages/pg/test/unit/client/sasl-scram-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,118 +58,101 @@ suite.test('sasl/scram', function () {
})

suite.test('continueSession', function () {
suite.test('fails when last session message was not SASLInitialResponse', async function () {
assert.rejects(
function () {
return sasl.continueSession({}, '', '')
},
{
message: 'SASL: Last message was not SASLInitialResponse',
}
)
suite.test('fails when last session message was not SASLInitialResponse', async () => {
await assert.rejects(sasl.continueSession({}, '', ''), {
message: 'SASL: Last message was not SASLInitialResponse',
})
})

suite.test('fails when nonce is missing in server message', function () {
assert.rejects(
function () {
return sasl.continueSession(
{
message: 'SASLInitialResponse',
},
'bad-password',
's=1,i=1'
)
},
suite.test('fails when nonce is missing in server message', async () => {
await assert.rejects(
sasl.continueSession(
{
message: 'SASLInitialResponse',
},
'bad-password',
's=1,i=1'
),
{
message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce missing',
}
)
})

suite.test('fails when salt is missing in server message', function () {
assert.rejects(
function () {
return sasl.continueSession(
{
message: 'SASLInitialResponse',
},
'bad-password',
'r=1,i=1'
)
},
suite.test('fails when salt is missing in server message', async () => {
await assert.rejects(
sasl.continueSession(
{
message: 'SASLInitialResponse',
},
'bad-password',
'r=1,i=1'
),
{
message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: salt missing',
}
)
})

suite.test('fails when client password is not a string', function () {
suite.test('fails when client password is not a string', async () => {
for (const badPasswordValue of [null, undefined, 123, new Date(), {}]) {
assert.rejects(
function () {
return sasl.continueSession(
{
message: 'SASLInitialResponse',
clientNonce: 'a',
},
badPasswordValue,
'r=1,i=1'
)
},
await assert.rejects(
sasl.continueSession(
{
message: 'SASLInitialResponse',
clientNonce: 'a',
},
badPasswordValue,
'r=1,i=1'
),
{
message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string',
}
)
}
})

suite.test('fails when client password is an empty string', function () {
assert.rejects(
function () {
return sasl.continueSession(
{
message: 'SASLInitialResponse',
clientNonce: 'a',
},
'',
'r=1,i=1'
)
},
suite.test('fails when client password is an empty string', async () => {
await assert.rejects(
sasl.continueSession(
{
message: 'SASLInitialResponse',
clientNonce: 'a',
},
'',
'r=1,i=1'
),
{
message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a non-empty string',
}
)
})

suite.test('fails when iteration is missing in server message', function () {
assert.rejects(
function () {
return sasl.continueSession(
{
message: 'SASLInitialResponse',
},
'bad-password',
'r=1,s=abcd'
)
},
suite.test('fails when iteration is missing in server message', async () => {
await assert.rejects(
sasl.continueSession(
{
message: 'SASLInitialResponse',
},
'bad-password',
'r=1,s=abcd'
),
{
message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: iteration missing',
}
)
})

suite.test('fails when server nonce does not start with client nonce', function () {
assert.rejects(
function () {
return sasl.continueSession(
{
message: 'SASLInitialResponse',
clientNonce: '2',
},
'bad-password',
'r=1,s=abcd,i=1'
)
},
suite.test('fails when server nonce does not start with client nonce', async () => {
await assert.rejects(
sasl.continueSession(
{
message: 'SASLInitialResponse',
clientNonce: '2',
},
'bad-password',
'r=1,s=abcd,i=1'
),
{
message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce does not start with client nonce',
}
Expand Down
Loading