在摩卡和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"))
- 使用NodeJS服务器devise移动身份validation
- 用户和来宾两个不同的模板? 或者dynamic改变视图使用客户端variables?
- 通过未定义的POST API的身体价值?
- 节点+快递+护照:req.user未定义,但在邮递员的作品
- 节点护照邀请策略
- node.js connect-auth应用程序? 例子(用户注册/用户/会话pipe理)
- 套接字build立后的socket.ioauthentication
- SPA(angular度)身份validation与OAuth2提供商的独立域上的API和身份validation服务器; Google,Facebook
- 使用app.set('app_secret',data)将密钥存储在nodejs中是否安全?