Skip to content

Commit

Permalink
Merge pull request #464 from node-saml/csh-issue-459-attr-value-regre…
Browse files Browse the repository at this point in the history
…ssion-some

Only make an attribute an object if it has child elements
  • Loading branch information
mans0954 authored Oct 13, 2020
2 parents df8eb78 + 384b28d commit cbd1bc3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/passport-saml/saml.js
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,8 @@ SAML.prototype.processValidlySignedAssertion = function(xml, samlResponseXml, in
);

var attrValueMapper = function(value) {
return value._ ? value._ : value;
const hasChildren = Object.keys(value).some((cur)=> { return (cur!=='_' && cur!=='$'); });
return (hasChildren) ? value : value._;
};

if (attributes) {
Expand Down
24 changes: 23 additions & 1 deletion test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,29 @@ describe( 'passport-saml /', function() {
});
});


it( 'An undefined value given with an object should still be undefined', function( done ) {
const xml =
'<Response>' +
'<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" Version="2.0">' +
'<saml2:AttributeStatement>' +
'<saml2:Attribute Name="attributeName" ' +
'NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">' +
'<saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:type="xs:string"/>' +
'</saml2:Attribute>' +
'</saml2:AttributeStatement>' +
'</saml2:Assertion>' +
'</Response>';
var base64xml = Buffer.from( xml ).toString('base64');
var container = { SAMLResponse: base64xml };
var samlObj = new SAML();
samlObj.validatePostResponse( container, function( err, profile, logout ) {
should.not.exist( err );
should(profile['attributeName']).be.undefined();
done();
});
});
});

describe( 'getAuthorizeUrl request signature checks /', function() {
Expand Down

0 comments on commit cbd1bc3

Please sign in to comment.