node-postgres/test/unit/client/md5-password-tests.js
Brian C 8798e50ad3 Re-enable eslint with standard format (#1367)
* Work on converting lib to standard

* Finish updating lib

* Finish linting lib

* Format test files

* Add .eslintrc with standard format

* Supply full path to eslint bin

* Move lint command to package.json

* Add eslint as dev dependency
2017-07-15 12:05:58 -05:00

27 lines
935 B
JavaScript

'use strict'
var helper = require('./test-helper')
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 encrypted = utils.md5(client.password + client.user)
encrypted = utils.md5(encrypted + salt.toString('binary'))
var password = 'md5' + encrypted
// 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')
})