1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Update adminAuth tokensStrategy test spec

This commit is contained in:
KAZUHIRO ITO 2020-02-27 16:01:57 +09:00
parent bba6855872
commit 95982ad464

View File

@ -130,10 +130,13 @@ describe("api/auth/strategies", function() {
});
describe("Tokens Strategy", function() {
it('Succeeds if tokens user enabled',function(done) {
var userDefault = sinon.stub(Users,"tokens",function(token) {
it('Succeeds if tokens user enabled custom header',function(done) {
var userTokens = sinon.stub(Users,"tokens",function(token) {
return when.resolve("tokens-"+token);
});
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
return "x-test-token";
});
strategies.tokensStrategy._success = strategies.tokensStrategy.success;
strategies.tokensStrategy.success = function(user) {
user.should.equal("tokens-1234");
@ -141,12 +144,31 @@ describe("api/auth/strategies", function() {
delete strategies.tokensStrategy._success;
done();
};
strategies.tokensStrategy.authenticate({headers:{"authorization":"1234"}});
strategies.tokensStrategy.authenticate({headers:{"x-test-token":"1234"}});
});
it('Succeeds if tokens user enabled default header',function(done) {
var userTokens = sinon.stub(Users,"tokens",function(token) {
return when.resolve("tokens-"+token);
});
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
return "authorization";
});
strategies.tokensStrategy._success = strategies.tokensStrategy.success;
strategies.tokensStrategy.success = function(user) {
user.should.equal("tokens-1234");
strategies.tokensStrategy.success = strategies.tokensStrategy._success;
delete strategies.tokensStrategy._success;
done();
};
strategies.tokensStrategy.authenticate({headers:{"authorization":"Bearer 1234"}});
});
it('Fails if tokens user not enabled',function(done) {
var userDefault = sinon.stub(Users,"tokens",function() {
var userTokens = sinon.stub(Users,"tokens",function() {
return when.resolve(null);
});
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
return "authorization";
});
strategies.tokensStrategy._fail = strategies.tokensStrategy.fail;
strategies.tokensStrategy.fail = function(err) {
err.should.equal(401);
@ -154,10 +176,11 @@ describe("api/auth/strategies", function() {
delete strategies.tokensStrategy._fail;
done();
};
strategies.tokensStrategy.authenticate({headers:{"authorization":"1234"}});
strategies.tokensStrategy.authenticate({headers:{"authorization":"Bearer 1234"}});
});
afterEach(function() {
Users.tokens.restore();
Users.tokenHeader.restore();
})
});