在摩卡和SuperTest中设置基本身份validation
我试图设置一个testing,以validation用户名和密码的基本身份validation阻止的path的用户名和密码。
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(); }); });
使用auth方法
SuperTest基于SuperAgent ,它提供了基于身份validation的auth方法:
it('should receive a status code of 200 with login', function(done) { request(url) .get('/staging') .auth('the-username', 'the-password') .expect(200, done); });
来源: http : //visionmedia.github.io/superagent/#basic-authentication
PS:你可以直接传递任何.expect()
调用
“用户名:密码”部分必须是base64编码的
你可以使用类似的东西
.set("Authorization", "basic " + new Buffer("username:password").toString("base64"))
- 在处理POST请求时确定谁在Node上使用basicAuth进行了身份validation
- Express:一个路由的基本authentication
- 使用Firebase身份validation和Express身份validation社交login?
- 如何在Express.js中设置authentication中间件
- Nodemailer不断拒绝无效login身份validation(不使用Gmail)
- 设置第三方node.jsauthentication服务器
- Passport-js如何创build自定义策略
- 用户使用socket.io进行身份validation
- 基本node.js表示authentication不起作用