node-postgres/packages/pg/test/unit/client/md5-password-tests.js
Sehrope Sarkuni 96e2f20a1d test: Replace global BufferList with local require
Removes assigning BufferList to a global in top level test-helper and adds explicit
require in the tests that need to access it.
2020-05-16 08:43:38 -04:00

25 lines
880 B
JavaScript

'use strict'
var helper = require('./test-helper')
const BufferList = require('../../buffer-list')
var utils = require('../../../lib/utils')
test('md5 authentication', function () {
var client = helper.createClient()
client.password = '!'
var salt = Buffer.from([1, 2, 3, 4])
client.connection.emit('authenticationMD5Password', { salt: salt })
test('responds', function () {
assert.lengthIs(client.connection.stream.packets, 1)
test('should have correct encrypted data', function () {
var password = utils.postgresMd5PasswordHash(client.user, client.password, salt)
// how do we want to test this?
assert.equalBuffers(client.connection.stream.packets[0], new BufferList().addCString(password).join(true, 'p'))
})
})
})
test('md5 of utf-8 strings', function () {
assert.equal(utils.md5('😊'), '5deda34cd95f304948d2bc1b4a62c11e')
})