@@ -364,6 +364,56 @@ describe('saml 2.0', function () {
364364 assert . equal ( 'saml:Conditions' , signature [ 0 ] . previousSibling . nodeName ) ;
365365 } ) ;
366366
367+ 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+ prefix : '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 . prefix + ':Signature' ) ;
389+ assert . equal ( 'saml:Conditions' , signature [ 0 ] . previousSibling . nodeName ) ;
390+ } ) ;
391+
392+ it ( 'should ignore prefix if not a string' , function ( ) {
393+ var options = {
394+ cert : fs . readFileSync ( __dirname + '/test-auth0.pem' ) ,
395+ key : fs . readFileSync ( __dirname + '/test-auth0.key' ) ,
396+ xpathToNodeBeforeSignature : "//*[local-name(.)='Conditions']" ,
397+ prefix : 123 ,
398+ attributes : {
399+ 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress' :
'[email protected] ' , 400+ 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name' : 'Foo Bar' ,
401+ 'http://example.org/claims/testemptyarray' : [ ] , // should dont include empty arrays
402+ 'http://example.org/claims/testaccent' : 'fóo' , // should supports accents
403+ 'http://undefinedattribute/ws/com.com' : undefined
404+ }
405+ } ;
406+
407+ var signedAssertion = saml . create ( options ) ;
408+
409+ var isValid = utils . isValidSignature ( signedAssertion , options . cert ) ;
410+ assert . equal ( true , isValid ) ;
411+
412+ var doc = new xmldom . DOMParser ( ) . parseFromString ( signedAssertion ) ;
413+ var signature = doc . documentElement . getElementsByTagName ( 'Signature' ) ;
414+ assert . equal ( 'saml:Conditions' , signature [ 0 ] . previousSibling . nodeName ) ;
415+ } ) ;
416+
367417 describe ( 'encryption' , function ( ) {
368418
369419 it ( 'should create a saml 2.0 signed and encrypted assertion' , function ( done ) {
0 commit comments