Skip to content

Commit aed4a3d

Browse files
authored
Return object for XML-valued AttributeValues (#447)
* Return XML object for AttributeValue if not a string * Test XML-valued AttributeValue returns object
1 parent bb025e6 commit aed4a3d

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/passport-saml/saml.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ SAML.prototype.processValidlySignedAssertion = function(xml, samlResponseXml, in
10091009
);
10101010

10111011
var attrValueMapper = function(value) {
1012-
return typeof value === 'string' ? value : value._;
1012+
return value._ ? value._ : value;
10131013
};
10141014

10151015
if (attributes) {

test/tests.js

+34
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,40 @@ describe( 'passport-saml /', function() {
13481348
}
13491349
});
13501350
});
1351+
1352+
it( 'XML AttributeValue should return object', function( done ) {
1353+
const nameid_opaque_string = '*******************************'
1354+
const nameQualifier = 'https://idp.example.org/idp/saml'
1355+
const spNameQualifier = 'https://sp.example.org/sp/entity'
1356+
const format = 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
1357+
const xml =
1358+
'<Response>' +
1359+
'<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" Version="2.0">' +
1360+
'<saml2:AttributeStatement>' +
1361+
'<saml2:Attribute FriendlyName="eduPersonTargetedID" Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.10" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">' +
1362+
'<saml2:AttributeValue>' +
1363+
'<saml2:NameID Format="'+format+'" NameQualifier="'+nameQualifier+'" SPNameQualifier="'+spNameQualifier+'">' +
1364+
nameid_opaque_string +
1365+
'</saml2:NameID>' +
1366+
'</saml2:AttributeValue>' +
1367+
'</saml2:Attribute>' +
1368+
'</saml2:AttributeStatement>' +
1369+
'</saml2:Assertion>' +
1370+
'</Response>';
1371+
var base64xml = Buffer.from( xml ).toString('base64');
1372+
var container = { SAMLResponse: base64xml };
1373+
var samlObj = new SAML();
1374+
samlObj.validatePostResponse( container, function( err, profile, logout ) {
1375+
should.not.exist( err );
1376+
const eptid = profile['urn:oid:1.3.6.1.4.1.5923.1.1.1.10'];
1377+
const nameid = eptid['NameID'][0]
1378+
nameid._.should.eql(nameid_opaque_string)
1379+
nameid.$.NameQualifier.should.equal(nameQualifier)
1380+
nameid.$.SPNameQualifier.should.equal(spNameQualifier)
1381+
nameid.$.Format.should.equal(format)
1382+
done();
1383+
});
1384+
});
13511385
});
13521386

13531387

0 commit comments

Comments
 (0)