1 | 'use strict';
|
2 |
|
3 | var expect = require('chai').expect;
|
4 | var winston = require('winston');
|
5 | var cache = require('../lib/cache');
|
6 |
|
7 | var RemoteUserAuthority = require('../lib/remote-user-authority');
|
8 |
|
9 | describe('RemoteUserAuthority', function(){
|
10 | var authority, mockAuthentic, mockAuthScope;
|
11 | var sig, context;
|
12 |
|
13 | beforeEach(function(){
|
14 | cache.disable();
|
15 | mockAuthScope = { verify: function(_, cb) { cb(null, context); } };
|
16 |
|
17 | sig = { params: { jwt: { } } };
|
18 | mockAuthentic = {};
|
19 | context = {verified: true, isExpired: false};
|
20 |
|
21 | authority = RemoteUserAuthority(mockAuthScope, mockAuthentic, winston);
|
22 | });
|
23 |
|
24 | describe('#create', function(){
|
25 | it('should return verified auth context', function(){
|
26 | return authority.create(sig).then(function(val){
|
27 | expect(val).to.eql(context);
|
28 | });
|
29 | });
|
30 | it('should return undefined when sig is missing', function(){
|
31 | return authority.create(null).then(function(val){
|
32 | expect(val).to.be.undefined;
|
33 | });
|
34 | });
|
35 | it('should return null when context is not verified', function(){
|
36 | context.verified = false;
|
37 | return authority.create(sig).then(function(val){
|
38 | expect(val).to.be.undefined;
|
39 | });
|
40 | });
|
41 | it('should return undefined when context is expired', function(){
|
42 | context.isExpired = true;
|
43 | return authority.create(sig).then(function(val){
|
44 | expect(val).to.be.undefined;
|
45 | });
|
46 | });
|
47 | });
|
48 | });
|