diff --git a/lib/passport-saml/saml.js b/lib/passport-saml/saml.js index 3c782c4e..9b21ed8a 100644 --- a/lib/passport-saml/saml.js +++ b/lib/passport-saml/saml.js @@ -663,7 +663,11 @@ SAML.prototype.processValidlySignedAssertion = function(xml, inResponseTo, callb var attributeStatement = assertion.AttributeStatement; if (attributeStatement) { - var attributes = attributeStatement[0].Attribute; + var attributes = [].concat.apply([], attributeStatement.filter(function (attr) { + return Array.isArray(attr.Attribute); + }).map(function (attr) { + return attr.Attribute; + })); var attrValueMapper = function(value) { return typeof value === 'string' ? value : value._; diff --git a/test/tests.js b/test/tests.js index 5d626936..82d7f21d 100644 --- a/test/tests.js +++ b/test/tests.js @@ -1016,6 +1016,40 @@ describe( 'passport-saml /', function() { }); }); + it( 'xml document with multiple AttributeStatements should have all attributes present on profile', function(done){ + var requestId = '_dfab47d5d46374cd4b71'; + var xml = 'Verizon IDP HubVerizon IDP HubUIS/jochen-workUIS/jochen-workUIS usere9aba0c4-ece8-4b44-9526-d24418aa95dctestorgTest User::1qD+sVCaEdy1dTJoUQdo6o+tYsuU=aLl+1yT7zdT4WnRXKh9cx7WWZnUi/NoxMJWhXP5d+Zu9A4/fjKApSywimU0MTTQxYpvZLjOZPsSwmvc1boJOlXveDsL7A3YWi/f7/zqlVWOfXLE8TVLqUE4jtLsJHFWIJXmh8CI0loqQNf6QcYi9BwCK82FhhXC+qWA5WCZIIWUUMxjxnPbunQ7mninEeW568wqyhb9pLV8QkThzZrZINCqxNvWyGuK/XGPx7ciD6ywbBkdOjlDbwRMaKQ9YeCzZGGzJwOe/NuCXj+oUyzfmzUCobIIR0HYLc4B5UplL7XIKQzpOA2lDDsLe6ZzdTv1qjxSm+dlVfo24onmiPlQUgA=='; + var base64xml = new Buffer( xml ).toString('base64'); + var container = { SAMLResponse: base64xml }; + + var samlConfig = { + entryPoint: 'https://app.onelogin.com/trust/saml2/http-post/sso/371755', + cert: 'MIIDtTCCAp2gAwIBAgIJAKg4VeVcIDz1MA0GCSqGS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+JzKEM1BlRcn42sjJkijeFp7DpI7pU+PnYeiaXpRv5pJo8ogM1iFxN+SnfEs0EuQ7fhKIG9aHKi7bKZ7L6SyX7MDIGLeulEU6lf5D9BfXNmcMambiS0pXhL2QXajt96UBq8FT2KNXY8XNtR4y6MyyCzhaiZZcc8=', + validateInResponseTo: true + }; + var samlObj = new SAML( samlConfig ); + + fakeClock = sinon.useFakeTimers(Date.parse('2014-06-05T12:07:07.662Z')); + + // Mock the SAML request being passed through Passport-SAML + samlObj.cacheProvider.save(requestId, new Date().toISOString(), function(){}); + + samlObj.validatePostResponse( container, function( err, profile, logout ) { + should.not.exist( err ); + profile.nameID.should.startWith( 'UIS/jochen-work' ); + profile['vz::identity'].should.equal( 'UIS/jochen-work' ); + profile['vz::subjecttype'].should.equal( 'UIS user' ); + profile['vz::account'].should.equal( 'e9aba0c4-ece8-4b44-9526-d24418aa95dc' ); + profile['vz::org'].should.equal( 'testorg' ); + profile['vz::name'].should.equal( 'Test User' ); + profile['net::ip'].should.equal( '::1' ); + samlObj.cacheProvider.get(requestId, function(err, value){ + should.not.exist(value); + done(); + }); + }); + }); + describe( 'InResponseTo server cache expiration tests /', function() { it( 'should expire a cached request id after the time', function(done){ var requestId = '_dfab47d5d46374cd4b71';