283 Commits

Author SHA1 Message Date
Brian C
0acaf9d8ff
Fix compare (#1923)
* Fix deepEqual compare

In node 12 assert.deepEqual against a buffer & array no longer passes if the values are the same.  This makes sense.  Updated the test to not use deepEqual in this case.
2019-07-16 18:41:54 -05:00
Peter Boromissza
0993e4b61a Added the missing connect_timeout and keepalives_idle config parameters (#1847)
* Added the missing connect_timeout and keepalives_idle config parameters

* Implementation and tests for keepAliveInitialDelayMillis and connectionTimeoutMillis [squashed 4]
2019-05-10 11:48:38 -05:00
Malcolm
43ebcfb6bc Fix input preparation for date objects with a BC year (#1864)
* test: BC date input preparation

* Fix input preparation for BC dates
2019-04-15 18:38:20 -05:00
andreme
5a92ba3701 sasl/scram authentication (#1835) 2019-03-07 11:02:21 -06:00
Pat Gaffney
11a4793452 Add error handling for null params to Client.prototype.query() 2018-10-03 10:15:04 -05:00
Justin Jaffray
831dfb1b4c Pass through portal properly
This happened to work before because `Query.portalName` was undefined,
but in order to be able to set the portal explicitly it should be using
`Query.portal`.
2018-05-04 12:30:17 -05:00
Matthew Blewitt
3eb73751f5 Expand test to check for expected and unexpected errors 2018-05-04 12:20:42 -05:00
Matthew Blewitt
7dd3b50e41 Add guard to test to not check errors for empty error messages 2018-05-04 12:20:42 -05:00
Matthew Blewitt
5d32be4a90 Handle SSL negotiation errors more robustly
This commit adds some finer grained detail to handling the postmaster's
response to SSL negotiation packets, by accounting for the possibility
of an 'E' byte being sent back, and emitting an appropriate error.

In the naive case, the postmaster will respond with either 'S' (proceed
with an SSL connection) or 'N' (SSL is not supported). However, the
current if statement doesn't account for an 'E' byte being returned
by the postmaster, where an error is encountered (perhaps unable to
fork due to being out of memory).

By adding this case, we can prevent confusing error messages when SSL is
enforced and the postmaster returns an error after successful SSL
connections.

This also brings the connection handling further in line with
libpq, where 'E' is handled similarly as of this commit:

a49fbaaf8d

Given that there are no longer pre-7.0 databases out in the wild, I
believe this is a safe change to make, and should not break backwards
compatibility (unless matching on error message content).

* Replace if statement with switch, to catch 'S', 'E' and 'N' bytes
  returned by the postmaster
* Return an Error for non 'S' or 'N' cases
* Expand and restructure unit tests for SSL negotiation packets
2018-05-04 12:20:42 -05:00
Vratislav Kalenda
0902d145f4 fix: end stream connection 2018-05-04 12:19:53 -05:00
Pasi Eronen
9825e7c733 Use Buffer.from instead of deprecated Buffer constructor 2018-01-05 13:40:25 -06:00
Pasi Eronen
4cf67b23d4 Ignore socket hangup when ending connection also with ssl (#1344). 2018-01-05 13:40:25 -06:00
Jan Schär
894e2f2f1e Support Uint8Array values 2017-11-04 14:18:36 -05:00
Josh
8839d42547 fixed test failure message 2017-09-03 14:14:28 -05:00
Josh
ad36063ca5 support statement_timeout 2017-09-03 14:14:28 -05:00
Sehrope Sarkuni
e74c13ddad Centralize password md5 hashing logic
Centralize logic for md5 hashing of passwords for authentication. Adds
a new function postgresMd5PasswordHash(user, password, salt) to utils
and updates client.js and tests to use it.
2017-08-30 15:30:36 -05:00
Tobias Gurtzick
7d1342e03b verify that sslrootcert is added to libpqConnectionString 2017-08-26 12:26:08 -05:00
Sehrope Sarkuni
884e21e1ca Refactor addCommandComplete
Refactors addCommandComplete to tighten parsing regex start anchor and
handle edge case where no row count is specified (pre 8.2 COPY).
2017-08-26 12:24:59 -05:00
caub
3a6b8416c2 allow both connectionString and additional options 2017-08-03 23:53:00 -05:00
Brian M. Carlson
ca4ac9983a Re-implement other patch 2017-07-16 16:39:22 -05:00
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
Brian Carlson
27450d07e6 Throw on reconnect attempt
Clients are not reusable.  This changes the client to raise errors whenever you try to reconnect a client that's already been used.  They're cheap to create: just instantiate a new one (or use the pool) 😉.

Closes #1352
2017-07-15 11:02:09 -05:00
Brian M. Carlson
bd87cddc72 Fix connection / disconnection issues 2017-06-18 16:48:14 -05:00
Brian M. Carlson
0f1f8626cf Add use strict to every file 2017-06-18 16:48:14 -05:00
Brian M. Carlson
2300445646 Cleanup a bit of dead code 2017-06-18 16:48:14 -05:00
Brian M. Carlson
0ce8a6c675 Fix brittle unit tests 2017-06-16 21:43:45 -05:00
Brian M. Carlson
d615ebee17 Start cleaning up tests 2017-06-15 10:32:38 -05:00
Brian M. Carlson
96b7fc38a6 Fix unit tests 2017-06-15 10:32:38 -05:00
Brian M. Carlson
a829eee334 Merge origin/master 2017-06-09 16:24:39 -05:00
Brian Carlson
76c59a01f2 Emit error when backend unexpectedly disconnects 2017-06-09 12:27:47 -05:00
Brian C
aeb0c759f5 Remove fallbacks for unsupported Node versions (#1304) (#1313)
* Add client connectionString tests (#1310)

* Remove redundant tests

* Add client connectionString test

Add test to ensure { connectionString } is respected as an argument to the client constructor

* Add test for connection string property

Also fixed some legacy require statements.

* Normalize native error properties

Map native error properties to the same property names we use for errors from the JS driver.

Fixes #972
Fixes #938
2017-06-08 21:53:47 -05:00
Brian C
f2b87e02f1 Add client connectionString tests (#1310)
* Remove redundant tests

* Add client connectionString test

Add test to ensure { connectionString } is respected as an argument to the client constructor

* Add test for connection string property

Also fixed some legacy require statements.
2017-06-07 22:58:03 -05:00
Charmander
934ca3af16 Remove fallbacks for unsupported Node versions (#1304)
* Remove unsupported Node versions 0.10 and 0.12 from CI

* Replace deprecated Buffer constructor with .from/.alloc

* Remove Promise polyfill

* Make use of Object.assign

* Remove checks for versions of Node earlier than 4

* Remove Buffer#indexOf fallback for Node 0.10
2017-06-07 22:45:32 -05:00
Sehrope Sarkuni
ee8193673c Libpq connection string escaping (#1285)
* Fix escaping of libpq connection string properties

Fix handlings of libpq connection properties to properly escape single
quotes and backslashes. Previously the values were surrounded in single
quotes which handled whitespace within the property value, but internal
single quotes and backslashes would cause invalid connection strings to
be generated.

* Update expected output in test to be quoted

Update the expect host output in the connection parameter test
to expect it to be surrounded by single quotes.

* Add test for configs with quotes and backslashes
2017-05-15 12:19:13 -05:00
Brian Carlson
80d136a531 Add test & documentation for replicationStart message 2017-04-24 13:33:38 -05:00
Linus Unnebäck
5cb38f5892 Handle throws in type parsers (#1218)
* Handle throws in type parsers

* Fix throw in type parsers test for Node 0.x
2017-03-06 11:04:16 -06:00
Brian C
7f35240a5c Fix for utf-8 characters in md5 passwords (#1183)
This is the same fix as supplied in 1178 but includes a test.

Closes #1178
2016-12-13 11:51:36 -06:00
Charmander
48a9738a0b Run inbound parser tests (#1182)
They were disabled by 4cdd7a116bab03c6096ab1af8f0f522b04993768 without comment; it seems that this might have been unintentional?

In any case, they should probably be enabled, updated, or removed.
2016-12-13 07:36:13 -06:00
Brian C
0aa62f2854 Make tcp-keepalive configurable (#1058) 2016-06-21 21:38:10 -05:00
Konstantin Petryaev
ad65c7b1bc Fix of pool leaking by TCP-keepalive (#918)
* fix of bug with pool leaking by TCP keep-alives

* add test for check setKeepAlive on connect

* fix mistake with var

* fix mistake with var
2016-06-21 14:49:41 -05:00
Brian C
796a44f54f Remove internal pool (#1049)
* Initial work on removing internal pool

* Port backwards-compabible properties

* Cleanup test execution & makefile cruft

* Attempt to fix flakey error test
2016-06-21 09:53:09 -05:00
Jos Kuijpers
1596a933eb Fix SSL configuration error and add tests. #848 (#1055) 2016-06-21 09:42:30 -05:00
Brian Dunavant
01e5d726da Support for defaults.connectionString (#910) 2016-06-07 16:09:22 -05:00
Brian C
a8bd44a6ec Requiring native bindings polutes 'global' (#984)
There was some nasty global-ish variable reference updating happening when the native module 'initializes' after its require with `require('pg').native`

This fixes the issue by making sure both `require('pg')` and `require('pg').native` each initialize their own context in isolation and no weird global-ish references are used & subsequently stomped on.
2016-04-08 18:46:10 -05:00
Seth Pollack
909c0f1872 add option to parse input Dates as UTC 2016-02-23 17:02:08 -08:00
Michael Nahkies
fa16966f91 add failing test that shows the issue 2016-01-27 18:06:22 +13:00
Oliver Salzburg
e5a63ab58d Don't emit error events parsed out of data stream 2015-08-24 17:24:52 +02:00
Brian M. Carlson
0b2344b6b5 Remove COPY TO / COPY FROM 2014-10-11 14:27:03 -04:00
Brian C
732e720d54 Merge pull request #608 from gurjeet/misc_unit_test_improvements
Miscellaneous improvements in unit tests.
2014-07-06 19:25:27 -04:00
Gurjeet Singh
ef40b6f3e9 Re-add the test for SELECT tag; I was wrong in my assumption.
Postgres generally does not emit a SELECT tag after a SELECT query, but
it does emit that tag after a CREATE TABLE x AS SELECT query.

Example:

postgres=# create table t as select 1;
SELECT 1
2014-06-22 08:19:26 -04:00