Repository navigation
feat(gax): export ensurePqcCurvesConfigured and verify TLS secure context - #9800
danieljbruce wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request exports the ensurePqcCurvesConfigured function from the main entry point and adds a unit test to verify that a valid TLS secure context is created supporting both X25519MLKEM768 and MLKEM1024. The review feedback recommends avoiding direct mutation of the imported tls module (tls.DEFAULT_ECDH_CURVE) within the test, as mutating shared built-in modules can cause runtime errors in environments with frozen module namespaces and lead to flaky tests.
| it('creates a valid TLS secure context supporting both X25519MLKEM768 (0x11ec) and MLKEM1024 (0x0202)', () => { | ||
| tls.DEFAULT_ECDH_CURVE = 'auto'; | ||
| ensurePqcCurvesConfigured(); | ||
| const defaultCtx = tls.createSecureContext({ | ||
| ecdhCurve: tls.DEFAULT_ECDH_CURVE, | ||
| }); | ||
| const mlkem1024Ctx = tls.createSecureContext({ | ||
| ecdhCurve: 'MLKEM1024', | ||
| }); | ||
| assert.ok(defaultCtx); | ||
| assert.ok(mlkem1024Ctx); | ||
| }); |
There was a problem hiding this comment.
Avoid directly mutating imported or shared built-in modules (such as the 'tls' module) in tests, as this can cause runtime errors in environments with frozen module namespaces (like native ES Modules) and lead to flaky tests. Instead, verify behavior through other side effects or use proper mocking/stubbing libraries.
References
- Avoid directly mutating imported or shared built-in modules (such as the 'path' module) in tests, as this can cause runtime errors in environments with frozen module namespaces (like native ES Modules) and lead to flaky tests. Instead, verify behavior through other side effects (e.g., monitoring file system cleanup operations) or use proper mocking/stubbing libraries.
| export { | ||
| ClientStub, | ||
| ClientStubOptions, | ||
| ensurePqcCurvesConfigured, |
There was a problem hiding this comment.
[Generated] Re-exports ensurePqcCurvesConfigured from ./grpc at the top-level google-gax package entry point.
|
|
||
| it('creates a valid TLS secure context supporting both X25519MLKEM768 (0x11ec) and MLKEM1024 (0x0202)', () => { | ||
| tls.DEFAULT_ECDH_CURVE = 'auto'; | ||
| ensurePqcCurvesConfigured(); | ||
| const defaultCtx = tls.createSecureContext({ | ||
| ecdhCurve: tls.DEFAULT_ECDH_CURVE, | ||
| }); | ||
| const mlkem1024Ctx = tls.createSecureContext({ | ||
| ecdhCurve: 'MLKEM1024', | ||
| }); | ||
| assert.ok(defaultCtx); | ||
| assert.ok(mlkem1024Ctx); | ||
| }); |
There was a problem hiding this comment.
[Generated] Verifies that tls.createSecureContext succeeds both with the configured tls.DEFAULT_ECDH_CURVE (supporting X25519MLKEM768 0x11ec and MLKEM1024 0x0202) and with explicit ecdhCurve: 'MLKEM1024'.
…gured export and guard runtime support
b7d3fc3 to
fa3e49c
Compare
| import { | ||
| ensurePqcCurvesConfigured as indexEnsurePqcCurvesConfigured, | ||
| protobuf, | ||
| } from '../../src/index'; |
There was a problem hiding this comment.
[Generated] Update core/packages/gax/test/unit/grpc.ts (lines 30-33 in import {afterEach, describe, it, beforeEach} from 'mocha';): +4/-1 line(s) for this stacked change block.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request exports ensurePqcCurvesConfigured from the package index and adds a unit test to verify that valid TLS secure contexts are created supporting both X25519MLKEM768 and MLKEM1024. Feedback suggests avoiding direct mutation of the imported tls module's properties (specifically tls.DEFAULT_ECDH_CURVE) within tests, as this can cause runtime errors in environments with frozen module namespaces and lead to flaky tests.
| tls.DEFAULT_ECDH_CURVE = 'auto'; | ||
| ensurePqcCurvesConfigured(); | ||
| const defaultCtx = tls.createSecureContext({ | ||
| ecdhCurve: tls.DEFAULT_ECDH_CURVE, | ||
| }); | ||
| const mlkem1024Ctx = tls.createSecureContext({ | ||
| ecdhCurve: 'MLKEM1024', | ||
| }); | ||
| assert.ok(defaultCtx); | ||
| assert.ok(mlkem1024Ctx); |
There was a problem hiding this comment.
Avoid directly mutating imported or shared built-in modules (such as the 'tls' module) in tests, as this can cause runtime errors in environments with frozen module namespaces (like native ES Modules) and lead to flaky tests. Instead, use proper mocking/stubbing libraries to stub tls.DEFAULT_ECDH_CURVE or verify behavior through other side effects.
References
- Avoid directly mutating imported or shared built-in modules (such as the 'path' module) in tests, as this can cause runtime errors in environments with frozen module namespaces (like native ES Modules) and lead to flaky tests. Instead, verify behavior through other side effects (e.g., monitoring file system cleanup operations) or use proper mocking/stubbing libraries.
Description
This change exports the PQC curve helper from the package root.
Impact
Consumers and tests can directly invoke and verify PQC curve setup.
Stack
feat/gax-pqc-mlkem1024-part-1mainsrc/grpc.tsensurePqcCurvesConfigured)feat/gax-pqc-mlkem1024-part-2feat/gax-pqc-mlkem1024-part-1GrpcClientconstructor PQC curve check)feat/gax-pqc-mlkem1024-part-3feat/gax-pqc-mlkem1024-part-2src/index.tsexport & TLS context verification)feat/gax-pqc-mlkem1024-part-3-style-maintenancefeat/gax-pqc-mlkem1024-part-3[Style Maintenance]PRChanges
ensurePqcCurvesConfiguredfromcore/packages/gax/src/index.tsalongsideGrpcClient.core/packages/gax/test/unit/grpc.tsverifyingtls.createSecureContextsucceeds with both the configuredtls.DEFAULT_ECDH_CURVEand explicit'MLKEM1024'.Testing
MLKEM1024(0x0202) TLS 1.3 advertisement and handshake negotiation from the terminal by runningpnpm --dir core/packages/gax run compile && curl -fsSL https://gist.githubusercontent.com/danieljbruce/3880337b200084e1da370a616e9b211c/raw/repro-pqc-mlkem1024.mjs | node --input-type=module -(see repro-pqc-mlkem1024.mjs Gist).node bin/run-test.cjs --no-c8 core/packages/gax/build/test/unit/grpc.js) and Bun (JS_RUNTIME=bun MOCHA_PARALLEL=false bun --bun bin/run-test.cjs --no-c8 core/packages/gax/build/test/unit/grpc.js).node ./bin/linter.mjs --strict.Alternatives
ensurePqcCurvesConfiguredinternal tosrc/grpc.tswas rejected because exporting it fromgoogle-gaxallows REST-only callers and integration tests to explicitly verify or re-trigger PQC curve configuration.