Skip to content

Commit 2300445

Browse files
committed
Cleanup a bit of dead code
1 parent 1bc1758 commit 2300445

File tree

7 files changed

+34
-43
lines changed

7 files changed

+34
-43
lines changed

lib/client.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* README.md file in the root directory of this source tree.
77
*/
88

9-
var crypto = require('crypto');
109
var EventEmitter = require('events').EventEmitter;
1110
var util = require('util');
11+
var utils = require('./utils')
1212
var pgPass = require('pgpass');
1313
var TypeOverrides = require('./type-overrides');
1414

@@ -97,8 +97,8 @@ Client.prototype.connect = function(callback) {
9797

9898
//password request handling
9999
con.on('authenticationMD5Password', checkPgPass(function(msg) {
100-
var inner = Client.md5(self.password + self.user);
101-
var outer = Client.md5(Buffer.concat([Buffer.from(inner), msg.salt]));
100+
var inner = utils.md5(self.password + self.user);
101+
var outer = utils.md5(Buffer.concat([Buffer.from(inner), msg.salt]));
102102
var md5password = "md5" + outer;
103103
con.password(md5password);
104104
}));
@@ -406,10 +406,6 @@ Client.prototype.end = function (cb) {
406406
}
407407
};
408408

409-
Client.md5 = function (string) {
410-
return crypto.createHash('md5').update(string, 'utf-8').digest('hex');
411-
};
412-
413409
// expose a Query constructor
414410
Client.Query = Query;
415411

lib/index.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,22 @@ var Client = require('./client');
1212
var defaults = require('./defaults');
1313
var Connection = require('./connection');
1414
var ConnectionParameters = require('./connection-parameters');
15-
var poolFactory = require('./pool-factory');
15+
var Pool = require('pg-pool');
16+
17+
const poolFactory = (Client) => {
18+
var BoundPool = function(options) {
19+
var config = { Client: Client };
20+
for (var key in options) {
21+
config[key] = options[key];
22+
}
23+
Pool.call(this, config);
24+
};
25+
26+
util.inherits(BoundPool, Pool);
27+
28+
return BoundPool;
29+
};
30+
1631

1732
var PG = function(clientConstructor) {
1833
this.defaults = defaults;

lib/native/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./client');
1+
module.exports = require('./client')

lib/pool-factory.js

-17
This file was deleted.

lib/promise.js

-12
This file was deleted.

lib/utils.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
*/
88

99
const util = require('util')
10-
var defaults = require('./defaults');
10+
const crypto = require('crypto');
11+
12+
const defaults = require('./defaults');
1113

1214
function escapeElement(elementRepresentation) {
1315
var escaped = elementRepresentation
@@ -138,11 +140,17 @@ function normalizeQueryConfig (config, values, callback) {
138140
return config;
139141
}
140142

143+
144+
const md5 = function (string) {
145+
return crypto.createHash('md5').update(string, 'utf-8').digest('hex');
146+
};
147+
141148
module.exports = {
142149
prepareValue: function prepareValueWrapper (value) {
143150
//this ensures that extra arguments do not get passed into prepareValue
144151
//by accident, eg: from calling values.map(utils.prepareValue)
145152
return prepareValue(value);
146153
},
147154
normalizeQueryConfig: normalizeQueryConfig,
155+
md5: md5,
148156
};

test/unit/client/md5-password-tests.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require(__dirname + '/test-helper');
1+
require('./test-helper');
2+
var utils = require('../../../lib/utils')
23

34
test('md5 authentication', function() {
45
var client = createClient();
@@ -9,8 +10,8 @@ test('md5 authentication', function() {
910
test('responds', function() {
1011
assert.lengthIs(client.connection.stream.packets, 1);
1112
test('should have correct encrypted data', function() {
12-
var encrypted = Client.md5(client.password + client.user);
13-
encrypted = Client.md5(encrypted + salt.toString('binary'));
13+
var encrypted = utils.md5(client.password + client.user);
14+
encrypted = utils.md5(encrypted + salt.toString('binary'));
1415
var password = "md5" + encrypted
1516
//how do we want to test this?
1617
assert.equalBuffers(client.connection.stream.packets[0], new BufferList()
@@ -20,5 +21,5 @@ test('md5 authentication', function() {
2021
});
2122

2223
test('md5 of utf-8 strings', function() {
23-
assert.equal(Client.md5('😊'), '5deda34cd95f304948d2bc1b4a62c11e');
24+
assert.equal(utils.md5('😊'), '5deda34cd95f304948d2bc1b4a62c11e');
2425
});

0 commit comments

Comments
 (0)