Skip to content

Commit d7f720c

Browse files
author
Marcos Castany
committed
Renamed option.prefix to option.signaturePrefix
1 parent 463371d commit d7f720c

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

lib/saml20.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ exports.create = function(options, callback) {
6767

6868
options.includeAttributeNameFormat = (typeof options.includeAttributeNameFormat !== 'undefined') ? options.includeAttributeNameFormat : true;
6969
options.typedAttributes = (typeof options.typedAttributes !== 'undefined') ? options.typedAttributes : true;
70-
options.prefix = options.prefix && (typeof options.prefix === 'string') ? options.prefix : '' ;
70+
71+
// 0.10.1 added prefix, but we want to name it signatureNamespacePrefix - This is just to keep supporting prefix
72+
options.signatureNamespacePrefix = options.signatureNamespacePrefix || options.prefix;
73+
options.signatureNamespacePrefix = typeof options.signatureNamespacePrefix === 'string' ? options.signatureNamespacePrefix : '' ;
7174

7275
var cert = utils.pemToCert(options.cert);
7376

@@ -190,7 +193,7 @@ exports.create = function(options, callback) {
190193
reference: options.xpathToNodeBeforeSignature || "//*[local-name(.)='Issuer']",
191194
action: 'after'
192195
},
193-
prefix: options.prefix
196+
prefix: options.signatureNamespacePrefix
194197
};
195198

196199
sig.computeSignature(token, opts);

test/saml20.tests.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,31 @@ describe('saml 2.0', function () {
365365
});
366366

367367
it('should place signature with prefix where specified', function () {
368+
var options = {
369+
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
370+
key: fs.readFileSync(__dirname + '/test-auth0.key'),
371+
xpathToNodeBeforeSignature: "//*[local-name(.)='Conditions']",
372+
signatureNamespacePrefix: 'anyprefix',
373+
attributes: {
374+
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress': '[email protected]',
375+
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name': 'Foo Bar',
376+
'http://example.org/claims/testemptyarray': [], // should dont include empty arrays
377+
'http://example.org/claims/testaccent': 'fóo', // should supports accents
378+
'http://undefinedattribute/ws/com.com': undefined
379+
}
380+
};
381+
382+
var signedAssertion = saml.create(options);
383+
384+
var isValid = utils.isValidSignature(signedAssertion, options.cert);
385+
assert.equal(true, isValid);
386+
387+
var doc = new xmldom.DOMParser().parseFromString(signedAssertion);
388+
var signature = doc.documentElement.getElementsByTagName(options.signatureNamespacePrefix + ':Signature');
389+
assert.equal('saml:Conditions', signature[0].previousSibling.nodeName);
390+
});
391+
392+
it('should place signature with prefix where specified (backwards compat)', function () {
368393
var options = {
369394
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
370395
key: fs.readFileSync(__dirname + '/test-auth0.key'),
@@ -385,7 +410,7 @@ describe('saml 2.0', function () {
385410
assert.equal(true, isValid);
386411

387412
var doc = new xmldom.DOMParser().parseFromString(signedAssertion);
388-
var signature = doc.documentElement.getElementsByTagName(options.prefix + ':Signature');
413+
var signature = doc.documentElement.getElementsByTagName(options.signatureNamespacePrefix + ':Signature');
389414
assert.equal('saml:Conditions', signature[0].previousSibling.nodeName);
390415
});
391416

@@ -394,7 +419,7 @@ describe('saml 2.0', function () {
394419
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
395420
key: fs.readFileSync(__dirname + '/test-auth0.key'),
396421
xpathToNodeBeforeSignature: "//*[local-name(.)='Conditions']",
397-
prefix: 123,
422+
signatureNamespacePrefix: 123,
398423
attributes: {
399424
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress': '[email protected]',
400425
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name': 'Foo Bar',

0 commit comments

Comments
 (0)