-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
mitm doesn't intercept connection from Net.Socket#connect() #42
Comments
Hey, Thanks for taking the time to create an issue. That's indeed the case right now. Mitm.js currently creates a new |
The only problem for me using I've made a shitty workaround based on mitm code that works just for the connect test purpose: const Socket = require('net').Socket
describe('Some Socket Class', () => {
beforeEach(function() {
this.mitm = Mitm()
this.mitm.stubs.stub(
Socket.prototype, 'connect',
this.mitm.tcpConnect.bind(this.mitm, Socket.prototype.connect)
)
})
} But the problem is that any other interaction between the socket and the fake server created by mitm is ignored as the new Socket client object returned from Maybe the solution is to replace the Net.Socket by a mocked one: require('net').Socket = mitmSocket I don't know for other Node implementations. What do you think? |
You say you're reusing the same Replacing |
I'm using socket.on('close', (error) => {
this.connected = false
if (error) log.error(error)
this.attemptToReconnect = setInterval(() => {
if (!this.connected && !socket.connecting) {
socket.connect(this.host, this.port, () => {
this.connected = true
clearInterval(this.attemptToReconnect)
})
}
}, 2000)
}) Maybe it isn't the best way to do it, but it works for me since I started playing with these things (about 4 months ago). I've created also a function that changes the host that it's connected to by calling The node documentation says that |
Sending traffic also works, right? It's a little iffy to be honest, because once However, I don't see a problem of supporting |
Hey @moll |
@m-szyszka, I'm not sure if they're related. It could also be related to Redis using ES6 You're trying to intercept the Redis library's connections, right? To debug this, I suppose you could try to add a few print statements to Redis' code and log out the |
@moll You are right, problem was that |
After writing some tests using mitm, I stumbled upon this simple problem:
Net.Socket#connect()
isn't stubbed by mitm, therefore the connection won't be intercepted.The text was updated successfully, but these errors were encountered: