commit
3eef52dd1e
@ -0,0 +1,10 @@
|
|||||||
|
var pg = require('./test-helper').pg
|
||||||
|
|
||||||
|
var sql = 'SELECT 1 AS "\\\'/*", 2 AS "\\\'*/\n + process.exit(-1)] = null;\n//"'
|
||||||
|
|
||||||
|
var client = new pg.Client()
|
||||||
|
client.connect()
|
||||||
|
client.query(sql, function (err, res) {
|
||||||
|
if (err) throw err
|
||||||
|
client.end()
|
||||||
|
})
|
@ -1,39 +0,0 @@
|
|||||||
var helper = require(__dirname + '/../test-helper');
|
|
||||||
|
|
||||||
// Path to the password file
|
|
||||||
var passfile = __dirname + '/heroku.pgpass';
|
|
||||||
|
|
||||||
// Export the path to the password file
|
|
||||||
process.env.PGPASSFILE = passfile;
|
|
||||||
|
|
||||||
// Do a chmod 660, because git doesn't track those permissions
|
|
||||||
require('fs').chmodSync(passfile, 384);
|
|
||||||
|
|
||||||
var pg = helper.pg;
|
|
||||||
|
|
||||||
var host = 'ec2-107-20-224-218.compute-1.amazonaws.com';
|
|
||||||
var database = 'db6kfntl5qhp2';
|
|
||||||
var user = 'kwdzdnqpdiilfs';
|
|
||||||
|
|
||||||
var config = {
|
|
||||||
host: host,
|
|
||||||
database: database,
|
|
||||||
user: user,
|
|
||||||
ssl: true
|
|
||||||
};
|
|
||||||
|
|
||||||
test('uses password file when PGPASSFILE env variable is set', function() {
|
|
||||||
// connect & disconnect from heroku
|
|
||||||
pg.connect(config, assert.calls(function(err, client, done) {
|
|
||||||
assert.isNull(err);
|
|
||||||
client.query('SELECT NOW() as time', assert.success(function(res) {
|
|
||||||
assert(res.rows[0].time.getTime());
|
|
||||||
|
|
||||||
// cleanup ... remove the env variable
|
|
||||||
delete process.env.PGPASSFILE;
|
|
||||||
|
|
||||||
done();
|
|
||||||
pg.end();
|
|
||||||
}))
|
|
||||||
}));
|
|
||||||
});
|
|
@ -1,28 +0,0 @@
|
|||||||
var helper = require(__dirname + '/../test-helper');
|
|
||||||
var pg = helper.pg;
|
|
||||||
|
|
||||||
var host = 'ec2-107-20-224-218.compute-1.amazonaws.com';
|
|
||||||
var database = 'db6kfntl5qhp2';
|
|
||||||
var user = 'kwdzdnqpdiilfs';
|
|
||||||
var port = 5432;
|
|
||||||
|
|
||||||
var config = {
|
|
||||||
host: host,
|
|
||||||
port: port,
|
|
||||||
database: database,
|
|
||||||
user: user,
|
|
||||||
password: 'uaZoSSHgi7mVM7kYaROtusClKu',
|
|
||||||
ssl: true
|
|
||||||
};
|
|
||||||
|
|
||||||
test('connection with config ssl = true', function() {
|
|
||||||
//connect & disconnect from heroku
|
|
||||||
pg.connect(config, assert.calls(function(err, client, done) {
|
|
||||||
assert.isNull(err);
|
|
||||||
client.query('SELECT NOW() as time', assert.success(function(res) {
|
|
||||||
assert(res.rows[0].time.getTime());
|
|
||||||
done();
|
|
||||||
pg.end();
|
|
||||||
}))
|
|
||||||
}));
|
|
||||||
});
|
|
@ -1 +0,0 @@
|
|||||||
ec2-107-20-224-218.compute-1.amazonaws.com:5432:db6kfntl5qhp2:kwdzdnqpdiilfs:uaZoSSHgi7mVM7kYaROtusClKu
|
|
@ -0,0 +1,112 @@
|
|||||||
|
var helper = require(__dirname + "/test-helper");
|
||||||
|
var types = require('pg-types')
|
||||||
|
|
||||||
|
test('handles throws in type parsers', function() {
|
||||||
|
var typeParserError = new Error('TEST: Throw in type parsers');
|
||||||
|
|
||||||
|
types.setTypeParser('special oid that will throw', function () {
|
||||||
|
throw typeParserError;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('emits error', function() {
|
||||||
|
var handled;
|
||||||
|
var client = helper.client();
|
||||||
|
var con = client.connection;
|
||||||
|
var query = client.query('whatever');
|
||||||
|
|
||||||
|
handled = con.emit('readyForQuery');
|
||||||
|
assert.ok(handled, "should have handled ready for query");
|
||||||
|
|
||||||
|
con.emit('rowDescription',{
|
||||||
|
fields: [{
|
||||||
|
name: 'boom',
|
||||||
|
dataTypeID: 'special oid that will throw'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
assert.ok(handled, "should have handled row description");
|
||||||
|
|
||||||
|
assert.emits(query, 'error', function(err) {
|
||||||
|
assert.equal(err, typeParserError);
|
||||||
|
});
|
||||||
|
|
||||||
|
handled = con.emit('dataRow', { fields: ["hi"] });
|
||||||
|
assert.ok(handled, "should have handled first data row message");
|
||||||
|
|
||||||
|
handled = con.emit('commandComplete', { text: 'INSERT 31 1' });
|
||||||
|
assert.ok(handled, "should have handled command complete");
|
||||||
|
|
||||||
|
handled = con.emit('readyForQuery');
|
||||||
|
assert.ok(handled, "should have handled ready for query");
|
||||||
|
});
|
||||||
|
|
||||||
|
test('calls callback with error', function() {
|
||||||
|
var handled;
|
||||||
|
|
||||||
|
var callbackCalled = 0;
|
||||||
|
|
||||||
|
var client = helper.client();
|
||||||
|
var con = client.connection;
|
||||||
|
var query = client.query('whatever', assert.calls(function (err) {
|
||||||
|
callbackCalled += 1;
|
||||||
|
|
||||||
|
assert.equal(callbackCalled, 1);
|
||||||
|
assert.equal(err, typeParserError);
|
||||||
|
}));
|
||||||
|
|
||||||
|
handled = con.emit('readyForQuery');
|
||||||
|
assert.ok(handled, "should have handled ready for query");
|
||||||
|
|
||||||
|
handled = con.emit('rowDescription',{
|
||||||
|
fields: [{
|
||||||
|
name: 'boom',
|
||||||
|
dataTypeID: 'special oid that will throw'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
assert.ok(handled, "should have handled row description");
|
||||||
|
|
||||||
|
handled = con.emit('dataRow', { fields: ["hi"] });
|
||||||
|
assert.ok(handled, "should have handled first data row message");
|
||||||
|
|
||||||
|
handled = con.emit('dataRow', { fields: ["hi"] });
|
||||||
|
assert.ok(handled, "should have handled second data row message");
|
||||||
|
|
||||||
|
con.emit('commandComplete', { text: 'INSERT 31 1' });
|
||||||
|
assert.ok(handled, "should have handled command complete");
|
||||||
|
|
||||||
|
handled = con.emit('readyForQuery');
|
||||||
|
assert.ok(handled, "should have handled ready for query");
|
||||||
|
});
|
||||||
|
|
||||||
|
test('rejects promise with error', function() {
|
||||||
|
var handled;
|
||||||
|
var client = helper.client();
|
||||||
|
var con = client.connection;
|
||||||
|
var query = client.query('whatever');
|
||||||
|
var queryPromise = query.promise();
|
||||||
|
|
||||||
|
handled = con.emit('readyForQuery');
|
||||||
|
assert.ok(handled, "should have handled ready for query");
|
||||||
|
|
||||||
|
handled = con.emit('rowDescription',{
|
||||||
|
fields: [{
|
||||||
|
name: 'boom',
|
||||||
|
dataTypeID: 'special oid that will throw'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
assert.ok(handled, "should have handled row description");
|
||||||
|
|
||||||
|
handled = con.emit('dataRow', { fields: ["hi"] });
|
||||||
|
assert.ok(handled, "should have handled first data row message");
|
||||||
|
|
||||||
|
handled = con.emit('commandComplete', { text: 'INSERT 31 1' });
|
||||||
|
assert.ok(handled, "should have handled command complete");
|
||||||
|
|
||||||
|
handled = con.emit('readyForQuery');
|
||||||
|
assert.ok(handled, "should have handled ready for query");
|
||||||
|
|
||||||
|
queryPromise.catch(assert.calls(function (err) {
|
||||||
|
assert.equal(err, typeParserError);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in new issue