701 Commits

Author SHA1 Message Date
Sehrope Sarkuni
0894a3ce07 feat: Add dynamic retrieval for client password (#1926)
* feat: Add dynamic retrieval for client password

Adds option to specify a function for a client password. When the client
is connected, if the value of password is a function then it is invoked
to get the password to use for that connection.

The function must return either a string or a Promise that resolves to
a string. If the function throws or rejects with an error then it will
be bubbled up to the client.

* test: Add testAsync() helper to Suite

Add testAsync() helper function to Suite to simplify running tests that
return a Promise. The test action is executed and if a syncronous error
is thrown then it is immediately considered failed. If the Promise resolves
successfully then the test is considered successful. If the Promise
rejects with an Error then the test is considered failed.

* test: Add tests for dynamic password

* test: Simplify testAsync error handling

* fix: Clean up dynamic password error handling and misc style

* test: Remove extra semicolons

* test: Change testAsync(...) calls to use arrow functions

* fix: Wrap self.password() invocation in an arrow function

* test: Add a comment to testAsync(...)
2019-07-25 12:48:48 -05:00
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
Sehrope Sarkuni
8ba1d2c572 Enable eslint:recommended and plugin/node/recommended (#1856)
* Fix typo

* Enable eslint:recommended and remove unused eslint plugins

Enables eslint:recommended by disabling the options that would not pass. Also removes
dependencies for included but unused eslint plugins.

* Convert console.error(...) calls to use %s placeholders

* Enable eslint no-console rule

* Add and enable eslint-node-plugin

* Correct typo

* Enable eslint no-unused-vars
2019-05-10 12:23:49 -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
Sehrope Sarkuni
13c14f1de0 fix: Catch and emit query parameter prepareValue(...) errors (#1855)
Adds a try/catch block around the prepareValue(...) invocations in query.prepare(...)
to ensure that any that throw an error are caught and bubbled up to the caller.
2019-04-16 17:29:40 -05:00
Tony Wooster
566058de17 Add support for per per-query types (#1825)
The documentation states that you can pass custom type processors to
query objects. See:

https://node-postgres.com/features/queries#types

This didn't actually work. This commit adds an initial implementation
of per-query type-parsing. Caveats:

* It does not work with pg-native. That would require a separate pull
  request to pg-native, and a rather significant change to how that
  library handles query results.

* Per-query types do not "inherit" from types assigned to the Client,
  ala TypeOverrides.
2019-04-16 17:27:39 -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
Malcolm
4d84909cbd Fix integration test for v1.0.4 of postgres-date sub-dependency (#1867) 2019-04-15 18:37:33 -05:00
andreme
5a92ba3701 sasl/scram authentication (#1835) 2019-03-07 11:02:21 -06:00
Rich Harris
e6a878cbb5 compare prepared statement text with previous to prevent incorrect queries (#1814)
* compare prepared statement text with previous to prevent incorrect queries - fixes #1813

* make suggested changes to error message
2019-03-06 09:35:30 -06:00
André Cruz
eb076db5d4 Add configurable query timeout (#1760)
* Add read_timeout to connection settings

* Fix uncaught error issue

* Fix lint

* Fix "queryCallback is not a function"

* Added test and fixed error returning

* Added query timeout to native client

* Added test for timeout not reached

* Ensure error is the correct one
Correct test name

* Removed dubious check

* Added new test

* Improved test
2018-11-29 09:11:47 -06:00
Charmander
1cf1e05ab9 Allow a custom type to be used for Client promises (#1518)
Matches the Pool API.
2018-10-24 10:40:23 -05:00
Charmander
3828aa8608 Queued query errors (#1503)
* Add tests for query callbacks after connection-level errors

* Ensure callbacks are executed for all queued queries after connection-level errors

Separates socket errors from error messages, sends socket errors to all queries in the queue, marks clients as unusable after socket errors.

This is not very pleasant but should maintain backwards compatibility…?

* Always call `handleError` asynchronously

This doesn’t match the original behaviour of the type errors, but it’s correct.

* Fix return value of `Client.prototype.query` in immediate error cases

* Mark clients with closed connections as unusable consistently

* Add tests for error event when connecting Client

* Ensure the promise and callback versions of Client#connect always have the same behaviour

* Give same error to queued queries as to active query when ending

and do so in the native Client as well.

* Restore original ordering between queued query callbacks and 'end' event
2018-10-03 10:37:15 -05:00
Pat Gaffney
11a4793452 Add error handling for null params to Client.prototype.query() 2018-10-03 10:15:04 -05:00
Mike van Rossum
9bfd4bff40
[test] g/provded/provided 2018-07-17 01:07:00 +08:00
Dominic Letz
28e66ccd4b
Use pool constructor to pass pool size 2018-07-09 14:19:55 +08:00
Dominic Letz
2ea5f91f4a
Replace poolSize by max in error test 2018-07-09 11:46:56 +08:00
Sehrope Sarkuni
2dc5c6864b Change network partition test to wait for client socket creation prior to destroy 2018-06-17 11:58:37 -04: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
Sehrope Sarkuni
860928e2d5 Change test to use Buffer.from(...) 2018-05-04 12:18:31 -05:00
Sehrope Sarkuni
272e9a5998 Change network partition test to use socket.destroy() 2018-05-04 12:18:31 -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
Charmander
9870c86fde Make tests compatible with PostgreSQL 10
PostgreSQL 10 reports its version as only `major.minor`, so it can’t be parsed with semver. The `server_version_num` setting is a major version followed by a four-digit minor version since version 10, and was a three-digit major version followed by a two-digit minor version before that.
2017-11-17 14:16:03 -06:00
Charmander
0b80abacaf Specify collation when relied on in tests
Fixes #189.
2017-11-17 14:12:16 -06:00
Jan Schär
894e2f2f1e Support Uint8Array values 2017-11-04 14:18:36 -05:00
Josh
64eb77e94c new test for actual statement timeout 2017-09-03 14:14:28 -05:00
Josh
689bb25e86 fixes 2017-09-03 14:14:28 -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
Arnaud Benhamdine
4936033adf Check more default properties in configuration teset 2017-09-03 14:01:34 -05:00
Arnaud Benhamdine
d6e7dfee83 Replace poolSize by max in configuration test 2017-09-03 14:01:34 -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
Sehrope Sarkuni
3ad0680e8d Fix reference to md5 helper in test
Fixes reference to md5 helper and removes reference to js client
as the md5 function is now provided by utils.
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
Sehrope Sarkuni
6e2c1e9b98 Removes extra 'use strict' 2017-08-15 13:00:15 -07:00
Brian M. Carlson
48543bfad0 Fix vulnerability 2017-08-12 16:34:22 -05:00
caub
3a6b8416c2 allow both connectionString and additional options 2017-08-03 23:53:00 -05:00
Brian Carlson
66c6776f6e Make client.end return promise with active query 2017-07-21 16:59:24 -05:00
Brian M. Carlson
ca4ac9983a Re-implement other patch 2017-07-16 16:39:22 -05:00
Brian M. Carlson
111e08d0d7 Cleanup 2017-07-16 16:25:35 -05:00
Brian M. Carlson
ac3102eea2 Add support for pg-native multi-row result 2017-07-16 16:25:35 -05:00
Brian M. Carlson
28b330c88e Add JS driver support for multiple results 2017-07-16 16:25:35 -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 M. Carlson
f7de9ce820 Non-array query values cause query to end with an error.
This is a small change and is _kinda_ backwards compatible since the old behavior was to throw an error, but if someone was relying on anything with `.map` working as values it would break them, so it's in a major semver bump.
2017-07-15 11:19:37 -05:00