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

Only make an attribute an object if it has child elements #464

Merged
merged 2 commits into from
Oct 13, 2020
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
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