mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
Cleanup a bit of dead code
This commit is contained in:
parent
1bc1758579
commit
2300445646
@ -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;
|
||||
|
||||
|
||||
17
lib/index.js
17
lib/index.js
@ -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;
|
||||
|
||||
@ -1 +1 @@
|
||||
module.exports = require('./client');
|
||||
module.exports = require('./client')
|
||||
|
||||
@ -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;
|
||||
};
|
||||
@ -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)
|
||||
}
|
||||
10
lib/utils.js
10
lib/utils.js
@ -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,
|
||||
};
|
||||
|
||||
@ -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');
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user