Skip to content

Commit 884c76f

Browse files
ai: apply changes for #463 (1 review thread)
Addresses: - #3715934115 at lib/DBSQLClient.ts:259 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
1 parent 81ce468 commit 884c76f

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

lib/DBSQLClient.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
254254
: [
255255
...tls.rootCertificates,
256256
...DBSQLClient.getExtraCaCerts(),
257-
normalizePemBytes(options.customCaCert, 'customCaCert', 'certificate', 'DBSQLClient').toString(),
257+
// Push the normalized Buffer as-is (Node's `ca` accepts a mixed
258+
// Array<string | Buffer>) to match the cert/key treatment and keep
259+
// byte-fidelity for Buffer inputs instead of round-tripping through utf-8.
260+
normalizePemBytes(options.customCaCert, 'customCaCert', 'certificate', 'DBSQLClient'),
258261
],
259262
// Client certificate + key for mutual TLS (mTLS). Both must be supplied together.
260263
cert: clientCert,

tests/unit/DBSQLClient.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ describe('DBSQLClient.connect', () => {
9595
const connectionOptions = client['getConnectionOptions']({ ...connectOptions, customCaCert });
9696

9797
expect(connectionOptions.ca).to.be.an('array');
98-
const ca = connectionOptions.ca as Array<string>;
99-
// The custom cert must be present...
100-
expect(ca).to.include(customCaCert);
98+
const ca = connectionOptions.ca as Array<Buffer | string>;
99+
// The custom cert must be present, pushed as a Buffer (byte-fidelity, parity with cert/key)...
100+
expect(ca.map((entry) => entry.toString('utf8'))).to.include(customCaCert);
101101
// ...alongside the built-in system roots (so public warehouses still validate).
102102
expect(ca.length).to.be.greaterThan(1);
103103
});
@@ -113,11 +113,13 @@ describe('DBSQLClient.connect', () => {
113113
try {
114114
const connectionOptions = client['getConnectionOptions']({ ...connectOptions, customCaCert });
115115

116-
const ca = connectionOptions.ca as Array<string>;
117-
expect(ca).to.include(customCaCert);
116+
const ca = connectionOptions.ca as Array<Buffer | string>;
117+
const caStrings = ca.map((entry) => entry.toString('utf8'));
118+
// The custom cert is pushed as a Buffer (byte-fidelity, parity with cert/key).
119+
expect(caStrings).to.include(customCaCert);
118120
// Roots injected via NODE_EXTRA_CA_CERTS must survive the additive rebuild,
119121
// otherwise callers relying on that env var lose their trust anchors.
120-
expect(ca).to.include(extraCaCert);
122+
expect(caStrings).to.include(extraCaCert);
121123
} finally {
122124
readFileSync.restore();
123125
if (previousEnv === undefined) {

0 commit comments

Comments
 (0)