How to authenticate Supertest requests with Passport /Facebook strategy/?

前端 未结 3 1635
南方客
南方客 2021-02-09 20:32

I\'m using Passport.js for authentication (Facebook strategy) and testing with Mocha and Supertest. How can I create a session and make authenticated requests with Supertest for

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-09 21:03

    This example shows how to do the SuperTest part of the testing:

    describe('request', function() {
      describe('persistent agent', function() {
        var agent1 = request.agent();
        var agent2 = request.agent();
        var agent3 = request.agent();
        var agent4 = request.agent();
    
        it('should gain a session on POST', function(done) {
          agent3
            .post('http://localhost:4000/signin')
            .end(function(err, res) {
              should.not.exist(err);
              res.should.have.status(200);
              should.not.exist(res.headers['set-cookie']);
              res.text.should.include('dashboard');
              done();
            });
        });
    

    Here's a blog post about it.

提交回复
热议问题