From c102828a998fd4513cc3cf3aba6cdfa5cae00a0a Mon Sep 17 00:00:00 2001 From: Hideki Nakamura Date: Tue, 11 Sep 2018 10:36:54 -0700 Subject: [PATCH] Add some test cases --- test/red/api/auth/index_spec.js | 168 +++++++++++++++++++++++++++++++ test/red/api/auth/tokens_spec.js | 23 +++++ 2 files changed, 191 insertions(+) diff --git a/test/red/api/auth/index_spec.js b/test/red/api/auth/index_spec.js index 9849b602c..a27cf7c29 100644 --- a/test/red/api/auth/index_spec.js +++ b/test/red/api/auth/index_spec.js @@ -114,6 +114,174 @@ describe("api/auth/index",function() { }}); }); + it("returns login details - strategy - merged a adminAuth.module object to a adminAuth object", function(done) { + auth.init({ + settings: { + adminAuth: { + type: "strategy", + strategy:{ + label:"test-strategy", + icon:"test-icon" + }, + tokens: [{ + token: "test-token", + user: "test-user", + scope: ["*"] + }] + } + }, + log:{audit:function(){}} + }); + auth.login(null,{json: function(resp) { + resp.should.have.a.property("type","strategy"); + resp.should.have.a.property("prompts"); + resp.prompts.should.have.a.lengthOf(1); + resp.prompts[0].should.have.a.property("type","button"); + resp.prompts[0].should.have.a.property("label","test-strategy"); + resp.prompts[0].should.have.a.property("icon","test-icon"); + + done(); + }}); + }); + + }); + + describe("init", function() { + var spyTokensInit; + var spyUsersInit; + beforeEach(function() { + spyTokensInit = sinon.spy(Tokens,"init"); + spyUsersInit = sinon.spy(Users,"init"); + }); + this.afterEach(function() { + spyTokensInit.restore(); + spyUsersInit.restore(); + }); + it("merges an adminAuth object and an adminAuth.module object - module object is null", function(done) { + auth.init({ + settings: { + adminAuth: { + type: "strategy", + strategy:{ + label:"test-strategy", + icon:"test-icon" + }, + tokens: [{ + token: "test-token", + user: "test-user", + scope: ["*"] + }] + } + }, + log:{audit:function(){}} + }); + spyTokensInit.args[0][0].should.have.a.property("type","strategy"); + spyTokensInit.args[0][0].should.have.a.property("strategy"); + spyTokensInit.args[0][0].strategy.should.have.a.property("label","test-strategy"); + spyTokensInit.args[0][0].strategy.should.have.a.property("icon","test-icon"); + spyTokensInit.args[0][0].should.have.a.property("tokens"); + spyTokensInit.args[0][0].tokens.should.have.a.lengthOf(1); + spyTokensInit.args[0][0].tokens[0].should.have.a.property("token","test-token"); + spyTokensInit.args[0][0].tokens[0].should.have.a.property("user","test-user"); + spyTokensInit.args[0][0].tokens[0].should.have.a.property("scope"); + spyTokensInit.args[0][0].tokens[0].scope.should.have.a.lengthOf(1); + spyUsersInit.args[0][0].should.have.a.property("type","strategy"); + spyUsersInit.args[0][0].should.have.a.property("strategy"); + spyUsersInit.args[0][0].strategy.should.have.a.property("label","test-strategy"); + spyUsersInit.args[0][0].strategy.should.have.a.property("icon","test-icon"); + spyUsersInit.args[0][0].should.have.a.property("tokens"); + spyUsersInit.args[0][0].tokens.should.have.a.lengthOf(1); + spyUsersInit.args[0][0].tokens[0].should.have.a.property("token","test-token"); + spyUsersInit.args[0][0].tokens[0].should.have.a.property("user","test-user"); + spyUsersInit.args[0][0].tokens[0].should.have.a.property("scope"); + spyUsersInit.args[0][0].tokens[0].scope.should.have.a.lengthOf(1); + done(); + }); + it("merges an adminAuth object and an adminAuth.module object - not conflict", function(done) { + auth.init({ + settings: { + adminAuth: { + module: { + type: "strategy", + strategy:{ + label:"test-strategy", + icon:"test-icon" + } + }, + tokens: [{ + token: "test-token", + user: "test-user", + scope: ["*"] + }] + } + }, + log:{audit:function(){}} + }); + spyTokensInit.args[0][0].should.have.a.property("type","strategy"); + spyTokensInit.args[0][0].should.have.a.property("strategy"); + spyTokensInit.args[0][0].strategy.should.have.a.property("label","test-strategy"); + spyTokensInit.args[0][0].strategy.should.have.a.property("icon","test-icon"); + spyTokensInit.args[0][0].should.have.a.property("tokens"); + spyTokensInit.args[0][0].tokens.should.have.a.lengthOf(1); + spyTokensInit.args[0][0].tokens[0].should.have.a.property("token","test-token"); + spyTokensInit.args[0][0].tokens[0].should.have.a.property("user","test-user"); + spyTokensInit.args[0][0].tokens[0].should.have.a.property("scope"); + spyTokensInit.args[0][0].tokens[0].scope.should.have.a.lengthOf(1); + spyUsersInit.args[0][0].should.have.a.property("type","strategy"); + spyUsersInit.args[0][0].should.have.a.property("strategy"); + spyUsersInit.args[0][0].strategy.should.have.a.property("label","test-strategy"); + spyUsersInit.args[0][0].strategy.should.have.a.property("icon","test-icon"); + spyUsersInit.args[0][0].should.have.a.property("tokens"); + spyUsersInit.args[0][0].tokens.should.have.a.lengthOf(1); + spyUsersInit.args[0][0].tokens[0].should.have.a.property("token","test-token"); + spyUsersInit.args[0][0].tokens[0].should.have.a.property("user","test-user"); + spyUsersInit.args[0][0].tokens[0].should.have.a.property("scope"); + spyUsersInit.args[0][0].tokens[0].scope.should.have.a.lengthOf(1); + done(); + }); + it("merges an adminAuth object and an adminAuth.module object - conflict", function(done) { + auth.init({ + settings: { + adminAuth: { + module: { + type: "strategy", + strategy:{ + label:"test-strategy", + icon:"test-icon" + } + }, + type: "credentials", + tokens: [{ + token: "test-token", + user: "test-user", + scope: ["*"] + }] + } + }, + log:{audit:function(){}} + }); + spyTokensInit.args[0][0].should.have.a.property("type","strategy"); + spyTokensInit.args[0][0].should.have.a.property("strategy"); + spyTokensInit.args[0][0].strategy.should.have.a.property("label","test-strategy"); + spyTokensInit.args[0][0].strategy.should.have.a.property("icon","test-icon"); + spyTokensInit.args[0][0].should.have.a.property("tokens"); + spyTokensInit.args[0][0].tokens.should.have.a.lengthOf(1); + spyTokensInit.args[0][0].tokens[0].should.have.a.property("token","test-token"); + spyTokensInit.args[0][0].tokens[0].should.have.a.property("user","test-user"); + spyTokensInit.args[0][0].tokens[0].should.have.a.property("scope"); + spyTokensInit.args[0][0].tokens[0].scope.should.have.a.lengthOf(1); + spyUsersInit.args[0][0].should.have.a.property("type","strategy"); + spyUsersInit.args[0][0].should.have.a.property("strategy"); + spyUsersInit.args[0][0].strategy.should.have.a.property("label","test-strategy"); + spyUsersInit.args[0][0].strategy.should.have.a.property("icon","test-icon"); + spyUsersInit.args[0][0].should.have.a.property("tokens"); + spyUsersInit.args[0][0].tokens.should.have.a.lengthOf(1); + spyUsersInit.args[0][0].tokens[0].should.have.a.property("token","test-token"); + spyUsersInit.args[0][0].tokens[0].should.have.a.property("user","test-user"); + spyUsersInit.args[0][0].tokens[0].should.have.a.property("scope"); + spyUsersInit.args[0][0].tokens[0].scope.should.have.a.lengthOf(1); + done(); + }); }); }); diff --git a/test/red/api/auth/tokens_spec.js b/test/red/api/auth/tokens_spec.js index a9c5a7831..fa17391c4 100644 --- a/test/red/api/auth/tokens_spec.js +++ b/test/red/api/auth/tokens_spec.js @@ -92,6 +92,29 @@ describe("api/auth/tokens", function() { }); }); }); + + it('returns a valid api token', function(done) { + Tokens.init({ + tokens: [{ + token: "1234", + user: "fred", + }] + },{ + getSessions:function() { + return when.resolve({}); + } + }).then(function() { + Tokens.get("1234").then(function(token) { + try { + token.should.have.a.property("user","fred"); + done(); + } catch(err) { + done(err); + } + }); + }); + + }); }); describe("#create",function() {