support custom peer certificates on mock socket
See original GitHub issueContext
My node app checks peer-certificates on the socket level like this:
req.on("socket", (socket: TLSSocket) => {
socket.on("secureConnect", () => {
// socket.getPeerCertificate()
})
})
I tried to use nock like this:
nock(hostname)[method](path).reply(statusCode, body).on("socket", socket => {
console.log("inside secureSocket")
socket.getPeerCertificate = function() {
return {}
}
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 })
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to mock tls.PeerCertificate with Jest using Typescript?
Oops, don't need to do this ♂️ socket.getCertificate = spyOnGetCertificate.
Read more >ssl — TLS/SSL wrapper for socket objects — Python 3.11.1 ...
It supports additional methods such as getpeercert() , which retrieves the certificate of the other ... Client socket example with custom context and...
Read more >HTTPS & TLS - MockServer
MockServer has support for TLS (i.e. HTTPS) in three areas: ... MockServer achieves this by dynamically generating its X.509 Certificate using an in-memory ......
Read more >Retrofit 2 — How to Trust Unsafe SSL certificates (Self-signed ...
This includes revoked, expired or self-signed SSL certificates. ... Authentication; Caching; Testing & Mocking; Java Basics for Retrofit.
Read more >HTTPS in Java with a self-signed certificate - Brice Dutheil
In plain english, this server (wiremock) exposes a certificate, ... with a SSL socket factory that is itself configured with a custom trust ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the request @pke
Some things to come to mind right off the bat:
getPeerCertificate
on Nock’s mockSocket
class is just flat out wrong. It returns a random base64 string, but per the docs this method has always returned a plain object with the cert info.Socket
instance is created, attached to the router, and emitted on the request (req.emit('socket', socket)
) before a singleScope
orInterceptor
is selected. This is going to be a big challenge with the feature request, unless we add some global cert registry.@pke if the Nock Socket class simply added a
setPeerCertificate
method that you could call in a ‘socket’ event handler (like your example) would that work for you? It wouldn’t have the same API as some of the other Nock settings, but all those settings affect the reply which happen later in the flow. Your implementation would then look like the following:Or if you’re using Node v15.6.0+, you could use the new, fancy
X509Certificate
class.The back-compatible way would be fine with me, as I stated before 😉