Skip to content
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

fix(MockHttpSocket): forward tls socket properties #556

Merged

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Apr 17, 2024

Forwards the following TLS socket properties onto the MockHttpSocket (for both mocked and passthrough responses):

  • encrypted
  • authorized
  • getSession()
  • getProtocol()
  • isSessionReused()

@kettanaito kettanaito changed the base branch from main to feat/yet-another-socket-interceptor April 17, 2024 17:38
Reflect.set(this, 'encrypted', true)
// The server certificate is not the same as a CA
// passed to the TLS socket connection options.
Reflect.set(this, 'authorized', false)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikicho, note that the .authorized must be set to false. It's false in a bypassed HTTPS communication as well.

It will only be true if the certificate you pass to socket options is the same one that has signed the server you are requesting. That's false in most cases.

@kettanaito kettanaito requested a review from mikicho April 17, 2024 17:44
@kettanaito kettanaito changed the title fix(MockHttpSocket): forward tls properties fix(MockHttpSocket): forward tls socket properties Apr 17, 2024
@@ -169,6 +169,28 @@ export class MockHttpSocket extends MockSocket {
}
}

// Forward TLS Socket properties onto this Socket instance
// in the case of a TLS/SSL connection.
if (Reflect.get(socket, 'encrypted')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check the protocol instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can but that should be the discerning property to tell apart Socket from TLSSocket, per Node.js docs:

This may be used to distinguish TLS sockets from regular net.Socket instances.
Node.js docs / TLS

I don't mind checking the protocol but if the HTTPS request does have a TLSSocket, it's constructed incorrectly.

Is there a particular test case that fails with this check?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's a weird choice by Node. But if it's official, I'm in.

@kettanaito kettanaito merged commit 430c65e into feat/yet-another-socket-interceptor Apr 17, 2024
2 checks passed
@kettanaito kettanaito deleted the fix/tls-properties-forward branch April 17, 2024 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants