Skip to content

Commit 0709db4

Browse files
authored
Fix SCRAM-SHA-256 authentication by cloning the options object which is used to persist a nonce per connection (porsager#145)
1 parent 4d5fdc1 commit 0709db4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ function Postgres(a, b) {
218218

219219
function createConnection(options) {
220220
slots--
221-
const connection = Connection(options)
221+
// The options object gets cloned as the as the authentication in the frontend.js mutates the
222+
// options to persist a nonce and signature, which are unique per connection.
223+
const connection = Connection({...options})
222224
all.push(connection)
223225
return connection
224226
}

tests/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,15 @@ t('Login using scram-sha-256', async() => {
317317
return [true, (await postgres({ ...options, ...login_scram })`select true as x`)[0].x]
318318
})
319319

320+
t('Parallel connections using scram-sha-256', async() => {
321+
const sql = postgres({ ...options, ...login_scram })
322+
return [true, (await Promise.all([
323+
sql`select true as x, pg_sleep(0.2)`,
324+
sql`select true as x, pg_sleep(0.2)`,
325+
sql`select true as x, pg_sleep(0.2)`
326+
]))[0][0].x]
327+
})
328+
320329
t('Support dynamic password function', async() => {
321330
return [true, (await postgres({
322331
...options,

0 commit comments

Comments
 (0)