Node.js testing - mocking authenticated passport.js users uses passport.js extensively for login with google, github as well as connecting twitter, stackoverflow & linkedin accounts. But oauth handshakes are not so easy to fake. Furthermore, a lot of our code is protected by middleware that stops execution if the user is not logged in.

    So I spent a few hours digging through the passport.js source code and here’s a solution I came up with for mocking out an authenticated user.