-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathpassword-callback-tests.js
More file actions
70 lines (65 loc) · 1.74 KB
/
password-callback-tests.js
File metadata and controls
70 lines (65 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const helper = require('./test-helper')
const assert = require('assert')
const suite = new helper.Suite()
const pgpass = require('pgpass')
class Wait {
constructor() {
this.promise = new Promise((resolve) => {
this.resolve = resolve
})
}
until() {
return this.promise
}
done(time) {
if (time) {
setTimeout(this.resolve.bind(this), time)
} else {
this.resolve()
}
}
}
suite.test('password callback is called with conenction params', async function () {
const wait = new Wait()
const client = helper.client({
user: 'foo',
database: 'bar',
host: 'baz',
password: async (params) => {
assert.equal(params.user, 'foo')
assert.equal(params.database, 'bar')
assert.equal(params.host, 'baz')
wait.done(10)
return 'password'
},
})
client.connection.emit('authenticationCleartextPassword')
await wait.until()
assert.equal(client.user, 'foo')
assert.equal(client.database, 'bar')
assert.equal(client.host, 'baz')
assert.equal(client.connectionParameters.password, 'password')
})
suite.test('cleartext password auth does not crash with null password using pg-pass', async function () {
process.env.PGPASSFILE = `${__dirname}/pgpass.file`
// set this to undefined so pgpass will use the file
delete process.env.PGPASSWORD
const wait = new Wait()
const client = helper.client({
host: 'foo',
port: 5432,
database: 'bar',
user: 'baz',
password: (params) => {
return new Promise((resolve) => {
pgpass(params, (pass) => {
wait.done(10)
resolve(pass)
})
})
},
})
client.connection.emit('authenticationCleartextPassword')
await wait.until()
assert.equal(client.password, 'quz')
})