New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support custom peer certificates on mock socket #2227
Comments
Thanks for the request @pke Some things to come to mind right off the bat:
@pke if the Nock Socket class simply added a nock(hostname)[method](path).reply(statusCode, body).on("socket", socket => {
console.log("inside secureSocket")
socket.setPeerCertificate({
raw: <Buffer ... >
subject: { ... }
....
}) Or if you're using Node v15.6.0+, you could use the new, fancy nock(hostname)[method](path).reply(statusCode, body).on("socket", socket => {
console.log("inside secureSocket")
const x509 = new X509Certificate('{... pem encoded cert ...}');
socket.setPeerCertificate(x509.toLegacyObject())
}) |
Yes Matt, that looks good enough for me! Didn't know about the X509Certificate class until now, thanks! All I really need is the Maybe we can type the argument in a way that it is back compatible with older node versions? |
Is there anything actionable left for us to do here? |
yes. despite my best intentions, I never added this functionality. This should be marked as a solid feature request. |
The back-compatible way would be fine with me, as I stated before ;) |
Context
My node app checks peer-certificates on the socket level like this:
I tried to use nock like this:
But it does not override the getPeerCertificate function. It still returns the random string from the mock socket.
If the feature request is accepted, would you be willing to submit a PR?
Yes, I think it could be similary implemented like the socket delay.
nock(...).peerCertificate(...).reply()
or when creating the scope:nock(base, { peerCertificate })
The text was updated successfully, but these errors were encountered: