* 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(...)
* 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.
* 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
* Added the missing connect_timeout and keepalives_idle config parameters
* Implementation and tests for keepAliveInitialDelayMillis and connectionTimeoutMillis [squashed 4]
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.
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.
* 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
* 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
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`.
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
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.
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.
* 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
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.