|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var sinon = require('sinon'); |
| 4 | +var should = require( 'should' ); |
| 5 | +var SamlStrategy = require( '../lib/passport-saml/index.js' ).Strategy; |
| 6 | +var MultiSamlStrategy = require( '../lib/passport-saml/index.js' ).MultiSamlStrategy; |
| 7 | + |
| 8 | +function verify () {} |
| 9 | + |
| 10 | +describe('Strategy()', function() { |
| 11 | + it('extends passport Strategy', function() { |
| 12 | + function getSamlOptions () { return {} } |
| 13 | + var strategy = new MultiSamlStrategy({ getSamlOptions: getSamlOptions }, verify); |
| 14 | + strategy.should.be.an.instanceOf(SamlStrategy); |
| 15 | + }); |
| 16 | + |
| 17 | + it('throws if wrong finder is provided', function() { |
| 18 | + function createStrategy (){ return new MultiSamlStrategy({}, verify) }; |
| 19 | + should.throws(createStrategy); |
| 20 | + }); |
| 21 | +}); |
| 22 | + |
| 23 | +describe('strategy#authenticate', function() { |
| 24 | + beforeEach(function() { |
| 25 | + this.superAuthenticateStub = sinon.stub(SamlStrategy.prototype, 'authenticate'); |
| 26 | + }); |
| 27 | + |
| 28 | + afterEach(function() { |
| 29 | + this.superAuthenticateStub.restore(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('calls super with request and auth options', function(done) { |
| 33 | + var superAuthenticateStub = this.superAuthenticateStub; |
| 34 | + function getSamlOptions (req, fn) { |
| 35 | + fn(); |
| 36 | + sinon.assert.calledOnce(superAuthenticateStub); |
| 37 | + done(); |
| 38 | + }; |
| 39 | + |
| 40 | + var strategy = new MultiSamlStrategy({ getSamlOptions: getSamlOptions }, verify); |
| 41 | + strategy.authenticate(); |
| 42 | + }); |
| 43 | + |
| 44 | + it('passes options on to saml strategy', function(done) { |
| 45 | + var passportOptions = { |
| 46 | + passReqToCallback: true, |
| 47 | + authnRequestBinding: 'HTTP-POST', |
| 48 | + getSamlOptions: function (req, fn) { |
| 49 | + fn(); |
| 50 | + strategy._passReqToCallback.should.eql(true); |
| 51 | + strategy._authnRequestBinding.should.eql('HTTP-POST'); |
| 52 | + done(); |
| 53 | + } |
| 54 | + }; |
| 55 | + |
| 56 | + var strategy = new MultiSamlStrategy(passportOptions, verify); |
| 57 | + strategy.authenticate(); |
| 58 | + }); |
| 59 | + |
| 60 | + it('uses geted options to setup internal saml provider', function(done) { |
| 61 | + var samlOptions = { |
| 62 | + issuer: 'http://foo.issuer', |
| 63 | + callbackUrl: 'http://foo.callback', |
| 64 | + cert: 'deadbeef', |
| 65 | + host: 'lvh', |
| 66 | + acceptedClockSkewMs: -1, |
| 67 | + identifierFormat: |
| 68 | + 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress', |
| 69 | + path: '/saml/callback', |
| 70 | + logoutUrl: 'http://foo.slo', |
| 71 | + signatureAlgorithm: 'sha256' |
| 72 | + }; |
| 73 | + |
| 74 | + function getSamlOptions (req, fn) { |
| 75 | + fn(null, samlOptions); |
| 76 | + strategy._saml.options.should.containEql(samlOptions); |
| 77 | + done(); |
| 78 | + } |
| 79 | + |
| 80 | + var strategy = new MultiSamlStrategy( |
| 81 | + { getSamlOptions: getSamlOptions }, |
| 82 | + verify |
| 83 | + ); |
| 84 | + strategy.authenticate(); |
| 85 | + }); |
| 86 | +}); |
| 87 | + |
| 88 | +describe('strategy#logout', function() { |
| 89 | + beforeEach(function() { |
| 90 | + this.superAuthenticateStub = sinon.stub(SamlStrategy.prototype, 'logout'); |
| 91 | + }); |
| 92 | + |
| 93 | + afterEach(function() { |
| 94 | + this.superAuthenticateStub.restore(); |
| 95 | + }); |
| 96 | + |
| 97 | + it('calls super with request and auth options', function(done) { |
| 98 | + var superAuthenticateStub = this.superAuthenticateStub; |
| 99 | + function getSamlOptions (req, fn) { |
| 100 | + fn(); |
| 101 | + sinon.assert.calledOnce(superAuthenticateStub); |
| 102 | + done(); |
| 103 | + }; |
| 104 | + |
| 105 | + var strategy = new MultiSamlStrategy({ getSamlOptions: getSamlOptions }, verify); |
| 106 | + strategy.logout(); |
| 107 | + }); |
| 108 | + |
| 109 | + it('passes options on to saml strategy', function(done) { |
| 110 | + var passportOptions = { |
| 111 | + passReqToCallback: true, |
| 112 | + authnRequestBinding: 'HTTP-POST', |
| 113 | + getSamlOptions: function (req, fn) { |
| 114 | + fn(); |
| 115 | + strategy._passReqToCallback.should.eql(true); |
| 116 | + strategy._authnRequestBinding.should.eql('HTTP-POST'); |
| 117 | + done(); |
| 118 | + } |
| 119 | + }; |
| 120 | + |
| 121 | + var strategy = new MultiSamlStrategy(passportOptions, verify); |
| 122 | + strategy.logout(); |
| 123 | + }); |
| 124 | + |
| 125 | + it('uses geted options to setup internal saml provider', function(done) { |
| 126 | + var samlOptions = { |
| 127 | + issuer: 'http://foo.issuer', |
| 128 | + callbackUrl: 'http://foo.callback', |
| 129 | + cert: 'deadbeef', |
| 130 | + host: 'lvh', |
| 131 | + acceptedClockSkewMs: -1, |
| 132 | + identifierFormat: |
| 133 | + 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress', |
| 134 | + path: '/saml/callback', |
| 135 | + logoutUrl: 'http://foo.slo', |
| 136 | + signatureAlgorithm: 'sha256' |
| 137 | + }; |
| 138 | + |
| 139 | + function getSamlOptions (req, fn) { |
| 140 | + fn(null, samlOptions); |
| 141 | + strategy._saml.options.should.containEql(samlOptions); |
| 142 | + done(); |
| 143 | + } |
| 144 | + |
| 145 | + var strategy = new MultiSamlStrategy( |
| 146 | + { getSamlOptions: getSamlOptions }, |
| 147 | + verify |
| 148 | + ); |
| 149 | + strategy.logout(); |
| 150 | + }); |
| 151 | +}); |
0 commit comments