Passport JWT auth in unit test - socket hang up
|Added at||2016-12-30 16:12|
I'm having an emotional time trying to test protected routes that use passport's JWT strategy, with Authorization header.
I've tried axios, supertest, superagent and I get the same error - 'socket hang up':
This works perfectly in dev environment, this only happens in test environment - unit tests or dev env pointing to test DB/users.
I know this error means that the connection was closed by a crash on the server or a syntax error, however there are no syntax errors. The endpoint doesn't get past the passport auth:
Why? How can this be resolved?
If I remove the
The logs show that the request is sent with a correct JWT in Authorization header.
I have a different DB/users for dev and test. Using the test DB in dev, i'm able to replicate the issue seen in the unit tests. If I exclude an authorization header, as expected I get an 'Unauthorized' response (from a token check function).
As soon as I add an authorization header with JWT, I don't get any response at all :(
It seems that my api is no longer able to do any GET requests, in test environment, if there is an authorization header. With no header, all works fine. I suspect this is to do with some recent dependency updates.