diff --git a/lib/passport-wsfed-saml2/samlp.js b/lib/passport-wsfed-saml2/samlp.js index b8338f4..53d00b9 100644 --- a/lib/passport-wsfed-saml2/samlp.js +++ b/lib/passport-wsfed-saml2/samlp.js @@ -195,6 +195,11 @@ Samlp.prototype = { getSamlRequestUrl: function (opts, callback) { var options = xtend(opts || {}, this.options); + + if (!options.identityProviderUrl) { + return callback(new Error('Missing value for the identity provider login URL')); + } + var parsedUrl = url.parse(options.identityProviderUrl, true); this.getSamlRequestParams(options, function (err, params) { diff --git a/test/samlp.tests.js b/test/samlp.tests.js index 692fd65..209733f 100644 --- a/test/samlp.tests.js +++ b/test/samlp.tests.js @@ -180,7 +180,7 @@ describe('samlp (unit tests)', function () { var xmlWithNoSamlResponse = 'somedata'; var xmlWithSeveralSamlResponseElements = 'urn:fixture-testurn:fixture-test'; - it('shuold return error for AuthnFailed status with generic message', function(done){ + it('should return error for AuthnFailed status with generic message', function(done){ var samlp = new Samlp({ checkDestination: false }); samlp.validateSamlResponse(samlpResponseWithStatusResponderAndAuthnFailed, function (err) { expect(err).to.be.ok; @@ -190,7 +190,7 @@ describe('samlp (unit tests)', function () { }); }); - it('shuold return error for AuthnFailed status with specific message', function(done){ + it('should return error for AuthnFailed status with specific message', function(done){ var samlp = new Samlp({ checkDestination: false }); samlp.validateSamlResponse(samlpResponseWithStatusResponderAndAuthnFailedWithMessage, function (err) { expect(err).to.be.ok; @@ -471,6 +471,38 @@ describe('samlp (unit tests)', function () { }); }); + describe('getSamlRequestUrl', function(){ + before(function(){ + this.samlp = new Samlp({}); + }); + it('should be OK if the identityProviderUrl is a URL', function(done) { + var options = {identityProviderUrl: 'https://example.com'}; + this.samlp.getSamlRequestUrl(options, function(err, result) { + expect(err).to.not.exist; + expect(result).to.match(/^https:\/\/example.com\?SAMLRequest\=.*&RelayState=.*/); + done(); + }); + }); + it('should error if the identityProviderUrl is null', function(done) { + var options = {identityProviderUrl: null}; + this.samlp.getSamlRequestUrl(options, function(err, result) { + expect(err).to.be.an.Error; + expect(err.message).to.equal('Missing value for the identity provider login URL'); + expect(result).to.not.exist; + done(); + }); + }); + it('should error if the identityProviderUrl is missing', function(done) { + var options = {}; + this.samlp.getSamlRequestUrl(options, function(err, result) { + expect(err).to.be.an.Error; + expect(err.message).to.equal('Missing value for the identity provider login URL'); + expect(result).to.not.exist; + done(); + }); + }); + }); + describe('getSamlStatus', function(){ before(function(){ this.samlp = new Samlp({});