Cleanup a bit of dead code

This commit is contained in:
Brian M. Carlson 2017-06-18 14:30:39 -05:00 committed by Brian C
parent 1bc1758579
commit 2300445646
7 changed files with 34 additions and 43 deletions

View File

@ -6,9 +6,9 @@
* README.md file in the root directory of this source tree.
*/
var crypto = require('crypto');
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var utils = require('./utils')
var pgPass = require('pgpass');
var TypeOverrides = require('./type-overrides');
@ -97,8 +97,8 @@ Client.prototype.connect = function(callback) {
//password request handling
con.on('authenticationMD5Password', checkPgPass(function(msg) {
var inner = Client.md5(self.password + self.user);
var outer = Client.md5(Buffer.concat([Buffer.from(inner), msg.salt]));
var inner = utils.md5(self.password + self.user);
var outer = utils.md5(Buffer.concat([Buffer.from(inner), msg.salt]));
var md5password = "md5" + outer;
con.password(md5password);
}));
@ -406,10 +406,6 @@ Client.prototype.end = function (cb) {
}
};
Client.md5 = function (string) {
return crypto.createHash('md5').update(string, 'utf-8').digest('hex');
};
// expose a Query constructor
Client.Query = Query;

View File

@ -12,7 +12,22 @@ var Client = require('./client');
var defaults = require('./defaults');
var Connection = require('./connection');
var ConnectionParameters = require('./connection-parameters');
var poolFactory = require('./pool-factory');
var Pool = require('pg-pool');
const poolFactory = (Client) => {
var BoundPool = function(options) {
var config = { Client: Client };
for (var key in options) {
config[key] = options[key];
}
Pool.call(this, config);
};
util.inherits(BoundPool, Pool);
return BoundPool;
};
var PG = function(clientConstructor) {
this.defaults = defaults;

View File

@ -1 +1 @@
module.exports = require('./client');
module.exports = require('./client')

View File

@ -1,17 +0,0 @@
var Client = require('./client');
var util = require('util');
var Pool = require('pg-pool');
module.exports = function(Client) {
var BoundPool = function(options) {
var config = { Client: Client };
for (var key in options) {
config[key] = options[key];
}
Pool.call(this, config);
};
util.inherits(BoundPool, Pool);
return BoundPool;
};

View File

@ -1,12 +0,0 @@
const util = require('util')
const deprecationMessage = 'Using the promise result as an event emitter is deprecated and will be removed in pg@8.0'
module.exports = function(emitter, callback) {
const promise = new global.Promise(callback)
promise.on = util.deprecate(function () {
emitter.on.apply(emitter, arguments)
}, deprecationMessage);
promise.once = util.deprecate(function () {
emitter.once.apply(emitter, arguments)
}, deprecationMessage)
}

View File

@ -7,7 +7,9 @@
*/
const util = require('util')
var defaults = require('./defaults');
const crypto = require('crypto');
const defaults = require('./defaults');
function escapeElement(elementRepresentation) {
var escaped = elementRepresentation
@ -138,6 +140,11 @@ function normalizeQueryConfig (config, values, callback) {
return config;
}
const md5 = function (string) {
return crypto.createHash('md5').update(string, 'utf-8').digest('hex');
};
module.exports = {
prepareValue: function prepareValueWrapper (value) {
//this ensures that extra arguments do not get passed into prepareValue
@ -145,4 +152,5 @@ module.exports = {
return prepareValue(value);
},
normalizeQueryConfig: normalizeQueryConfig,
md5: md5,
};

View File

@ -1,4 +1,5 @@
require(__dirname + '/test-helper');
require('./test-helper');
var utils = require('../../../lib/utils')
test('md5 authentication', function() {
var client = createClient();
@ -9,8 +10,8 @@ test('md5 authentication', function() {
test('responds', function() {
assert.lengthIs(client.connection.stream.packets, 1);
test('should have correct encrypted data', function() {
var encrypted = Client.md5(client.password + client.user);
encrypted = Client.md5(encrypted + salt.toString('binary'));
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()
@ -20,5 +21,5 @@ test('md5 authentication', function() {
});
test('md5 of utf-8 strings', function() {
assert.equal(Client.md5('😊'), '5deda34cd95f304948d2bc1b4a62c11e');
assert.equal(utils.md5('😊'), '5deda34cd95f304948d2bc1b4a62c11e');
});