passport
passport copied to clipboard
How to test req.isAuthenticated() in express3 sample
Hello,
I'm wondering how to test authentication with passport. I'm using mocha ( and supertest ) and I didn't find a way to test controllers that depend on req.isAuthenticated()?
It would be really useful to see the test on the example here, https://github.com/jaredhanson/passport-local/tree/master/examples/express3
Bests regards, olivier
+1
+1
Hello, I wrote a simple sample that demonstrate authentication during the test.
var app = require("../app");
describe("session", function(){
var request= require('supertest');
var cookie;
it('POST authorized /login should return 200',function(done){
request(app)
.post('/login')
.send({ email:"[email protected]", provider:'local', password:'password' })
.end(function(err,res){
res.should.have.status(200);
cookie = res.headers['set-cookie'];
done();
});
});
it('GET /v1/users/me should return 200',function(done){
request(app)
.get('/v1/users/me')
.set('cookie', cookie)
.expect(200,done);
});
it('GET /v1/users/me should return 401',function(done){
request(app)
.get('/v1/users/me')
.expect(401,done);
});
Is there a way to "mock an authenticated user" without having to post to /login?
Any ideas how to workaround this
+1