Fix connectOptions dropped to tls.connect via Object.create#25
Conversation
Object.create(config.connectOptions) placed caller-supplied options on the prototype chain rather than as own properties. tls.connect() spreads (`...options`), which copies only own enumerable properties, so TLS options such as rejectUnauthorized, ca, key, and cert were silently dropped and Node's defaults were used instead. Use a shallow spread copy so caller options become own enumerable properties while keeping the caller's original object immutable. A shallow copy (not the JSON-based copyJsonMaybe helper) is required so Buffer options (ca/key/cert) and function options (checkServerIdentity) survive intact. Adds regression tests asserting caller options reach impl.connect() as own enumerable properties (including a Buffer value) and that the caller's connectOptions object is not mutated. Fixes #24
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe constructor of ChangesconnectOptions shallow-copy fix
Estimated code review effort: 1 (Trivial) | ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes #24.
IrcSocketbuilt its connect options withObject.create(config.connectOptions), which placed all caller-supplied options on the prototype of the new object rather than as own properties. At connect time this object is handed toimpl.connect(...); whenimplis Node'stlsmodule,tls.connect()internally spreads...options, copying only own enumerable properties. As a result, TLS options such asrejectUnauthorized,ca,key, andcertwere silently dropped and Node's defaults were used instead.Fix
Replace
Object.createwith a shallow spread copy ({ ...config.connectOptions }) so caller options become own enumerable properties while the caller's original object stays immutable.A shallow copy is used deliberately — the repo's
copyJsonMaybehelper (JSON.parse(JSON.stringify(...))) would corruptBufferoptions (ca/key/cert) and drop function options likecheckServerIdentity. A!== nullguard is added sincetypeof null === "object".Tests
Adds a
connectOptionsregression suite:Bufferca) reachimpl.connect()as own enumerable properties and survive a spread — mirroring exactly whattls.connect()doesconnectOptionsobject is not mutatedVerified the first test fails on the pre-fix
Object.createcode and passes after the fix. Full suite: 51 passing.Summary by CodeRabbit
Bug Fixes
Tests