Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken tests #367

Merged
merged 2 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/passport-saml/saml.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ SAML.prototype.validateRedirect = function(container, callback) {
var dom = new xmldom.DOMParser().parseFromString(inflated.toString());
var parserConfig = {
explicitRoot: true,
explicitCharKey: true,
explicitCharkey: true,
tagNameProcessors: [xml2js.processors.stripPrefix]
};
var parser = new xml2js.Parser(parserConfig);
Expand Down Expand Up @@ -1154,7 +1154,7 @@ function processValidlySignedPostRequest(self, doc, callback) {
}
var sessionIndex = request.SessionIndex;
if (sessionIndex) {
profile.sessionIndex = sessionIndex[0];
profile.sessionIndex = sessionIndex[0]._;
}

callback(null, profile, true);
Expand Down
20 changes: 12 additions & 8 deletions multiSamlStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,33 @@ MultiSamlStrategy.prototype.authenticate = function (req, options) {
});
};

MultiSamlStrategy.prototype.logout = function (req, options) {
MultiSamlStrategy.prototype.logout = function (req, callback) {
var self = this;

this._options.getSamlOptions(req, function (err, samlOptions) {
if (err) {
return self.error(err);
return callback(err);
}

self._saml = new saml.SAML(Object.assign({}, self._options, samlOptions));
self.constructor.super_.prototype.logout.call(self, req, options);
self.constructor.super_.prototype.logout.call(self, req, callback);
});
};

MultiSamlStrategy.prototype.generateServiceProviderMetadata = function( req, decryptionCert, signingCert, next ) {
MultiSamlStrategy.prototype.generateServiceProviderMetadata = function( req, decryptionCert, signingCert, callback ) {
if (typeof callback !== 'function') {
throw new Error("Metadata can't be provided synchronously for MultiSamlStrategy.");
}

var self = this;

return this._getSamlOptions(req, function (err, samlOptions) {
return this._options.getSamlOptions(req, function (err, samlOptions) {
if (err) {
return next(err);
return callback(err);
}

self._saml = new saml.SAML(samlOptions);
return next(null, self.constructor.super_.prototype.generateServiceProviderMetadata.call(self, decryptionCert, signingCert ));
self._saml = new saml.SAML(Object.assign({}, self._options, samlOptions));
return callback(null, self.constructor.super_.prototype.generateServiceProviderMetadata.call(self, decryptionCert, signingCert ));
});
};

Expand Down
112 changes: 76 additions & 36 deletions test/multiSamlStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ describe('strategy#authenticate', function() {
it('calls super with request and auth options', function(done) {
var superAuthenticateStub = this.superAuthenticateStub;
function getSamlOptions (req, fn) {
fn();
sinon.assert.calledOnce(superAuthenticateStub);
done();
try {
fn();
sinon.assert.calledOnce(superAuthenticateStub);
done();
} catch (err2) {
done(err2);
}
};

var strategy = new MultiSamlStrategy({
Expand All @@ -48,10 +52,14 @@ describe('strategy#authenticate', function() {
passReqToCallback: true,
authnRequestBinding: 'HTTP-POST',
getSamlOptions: function (req, fn) {
fn();
strategy._passReqToCallback.should.eql(true);
strategy._authnRequestBinding.should.eql('HTTP-POST');
done();
try {
fn();
strategy._passReqToCallback.should.eql(true);
strategy._authnRequestBinding.should.eql('HTTP-POST');
done();
} catch (err2) {
done(err2);
}
}
};

Expand All @@ -74,12 +82,16 @@ describe('strategy#authenticate', function() {
};

function getSamlOptions (req, fn) {
fn(null, samlOptions);
strategy._saml.options.should.containEql(Object.assign({},
{ cacheProvider: 'mock cache provider' },
samlOptions
));
done();
try {
fn(null, samlOptions);
strategy._saml.options.should.containEql(Object.assign({},
{ cacheProvider: 'mock cache provider' },
samlOptions
));
done();
} catch (err2) {
done(err2);
}
}

var strategy = new MultiSamlStrategy(
Expand All @@ -102,9 +114,13 @@ describe('strategy#logout', function() {
it('calls super with request and auth options', function(done) {
var superAuthenticateStub = this.superAuthenticateStub;
function getSamlOptions (req, fn) {
fn();
sinon.assert.calledOnce(superAuthenticateStub);
done();
try {
fn();
sinon.assert.calledOnce(superAuthenticateStub);
done();
} catch (err2) {
done(err2);
}
};

var strategy = new MultiSamlStrategy({ getSamlOptions: getSamlOptions }, verify);
Expand All @@ -116,10 +132,14 @@ describe('strategy#logout', function() {
passReqToCallback: true,
authnRequestBinding: 'HTTP-POST',
getSamlOptions: function (req, fn) {
fn();
strategy._passReqToCallback.should.eql(true);
strategy._authnRequestBinding.should.eql('HTTP-POST');
done();
try {
fn();
strategy._passReqToCallback.should.eql(true);
strategy._authnRequestBinding.should.eql('HTTP-POST');
done();
} catch (err2) {
done(err2);
}
}
};

Expand All @@ -142,9 +162,13 @@ describe('strategy#logout', function() {
};

function getSamlOptions (req, fn) {
fn(null, samlOptions);
strategy._saml.options.should.containEql(samlOptions);
done();
try {
fn(null, samlOptions);
strategy._saml.options.should.containEql(samlOptions);
done();
} catch (err2) {
done(err2);
}
}

var strategy = new MultiSamlStrategy(
Expand All @@ -167,11 +191,15 @@ describe('strategy#generateServiceProviderMetadata', function() {
it('calls super with request and generateServiceProviderMetadata options', function(done) {
var superGenerateServiceProviderMetadata = this.superGenerateServiceProviderMetadata;
function getSamlOptions (req, fn) {
fn();
sinon.assert.calledOnce(superGenerateServiceProviderMetadata);
superGenerateServiceProviderMetadata.calledWith('bar', 'baz');
req.should.eql('foo');
done();
try {
fn();
sinon.assert.calledOnce(superGenerateServiceProviderMetadata);
superGenerateServiceProviderMetadata.calledWith('bar', 'baz');
req.should.eql('foo');
done();
} catch (err2) {
done(err2);
}
};


Expand All @@ -184,10 +212,14 @@ describe('strategy#generateServiceProviderMetadata', function() {
passReqToCallback: true,
authnRequestBinding: 'HTTP-POST',
getSamlOptions: function (req, fn) {
fn();
strategy._passReqToCallback.should.eql(true);
strategy._authnRequestBinding.should.eql('HTTP-POST');
done();
try {
fn();
strategy._passReqToCallback.should.eql(true);
strategy._authnRequestBinding.should.eql('HTTP-POST');
done();
} catch (err2) {
done(err2);
}
}
};

Expand All @@ -204,8 +236,12 @@ describe('strategy#generateServiceProviderMetadata', function() {

var strategy = new MultiSamlStrategy(passportOptions, verify);
strategy.generateServiceProviderMetadata('foo', 'bar', 'baz', function (error, result) {
should(error).equal('My error');
done();
try {
should(error).equal('My error');
done();
} catch (err2) {
done(err2);
}
});
});

Expand All @@ -218,8 +254,12 @@ describe('strategy#generateServiceProviderMetadata', function() {

var strategy = new MultiSamlStrategy(passportOptions, verify);
strategy.generateServiceProviderMetadata('foo', 'bar', 'baz', function (error, result) {
should(result).equal('My Metadata Result');
done();
try {
should(result).equal('My Metadata Result');
done();
} catch (err2) {
done(err2);
}
});
});
});
Loading