Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
143
rated 0 times [  147] [ 4]  / answers: 1 / hits: 16907  / 9 Years ago, fri, february 27, 2015, 12:00:00

I'm trying to set us a test to verify the username and password of a path blocked by the basic auth of a username and password.



it('should receive a status code of 200 with login', function(done) {
request(url)
.get(/staging)
.expect(200)
.set('Authorization', 'Basic username:password')
.end(function(err, res) {
if (err) {
throw err;
}

done();
});
});

More From » node.js

 Answers
8

Using the auth method


SuperTest is based on SuperAgent which provides the auth method to facilitate Basic Authentication:


it('should receive a status code of 200 with login', function(done) {
request(url)
.get('/staging')
.auth('the-username', 'the-password')
.expect(200, done);
});

Source: http://visionmedia.github.io/superagent/#basic-authentication




PS: You can pass done straight to any of the .expect() calls


[#67650] Wednesday, February 25, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kylanalis

Total Points: 438
Total Questions: 85
Total Answers: 102

Location: Barbados
Member since Sun, Nov 27, 2022
1 Year ago
;