@@ -641,15 +641,23 @@ describe('samlp', function () {
641641 } ) ;
642642
643643 describe ( 'response signing' , function ( ) {
644- function doSAMLRequest ( testSamlResponse ) {
644+
645+ function doRawSAMLRequest ( testResponse ) {
645646 request . get ( {
646647 jar : request . jar ( ) ,
647648 uri : 'http://localhost:5050/samlp?SAMLRequest=fZBPb4MwDMW%2FSuQ7fxrYhCygYqumVeo0VOgOu2U0WpEgYXGo9vGXwdDaS2%2BO7fi990vX333HztJQq1UGKz8EJlWjj636zOBQP3kJrPOURN8NWIz2pPbya5RkmfunCKdBBqNRqAW1hEr0ktA2WBUvO%2BR%2BiIPRVje6A1YQSWOd0KNWNPbSVNKc20Ye9rsMTtYOhEEgGgK2cQqtEnYytUyO%2F01g241zy6P4zpVEo9wqskLZDHi4irww9nhSc45xhDH3o%2BT%2BHVj5Z%2BShVXO8W64%2F5iXC57ouvfK1qoG9LZjcAsxQcBI3FzRunxULAsh%2FY7lUNKTBxaV8fl3Dzn8A&RelayState=123'
648- } , function ( err , response , body ) {
649+ } , function ( err , response ) {
649650 expect ( err ) . to . equal ( null ) ;
651+
652+ testResponse ( response ) ;
653+ } ) ;
654+ }
655+
656+ function doSAMLRequest ( testSamlResponse ) {
657+ doRawSAMLRequest ( function ( response ) {
650658 expect ( response . statusCode ) . to . equal ( 200 ) ;
651659
652- var SAMLResponse = cheerio . load ( body ) ( 'input[name="SAMLResponse"]' ) . attr ( 'value' ) ;
660+ var SAMLResponse = cheerio . load ( response . body ) ( 'input[name="SAMLResponse"]' ) . attr ( 'value' ) ;
653661 var samlResponse = new Buffer ( SAMLResponse , 'base64' ) . toString ( ) ;
654662 var doc = new xmldom . DOMParser ( ) . parseFromString ( samlResponse ) ;
655663 testSamlResponse ( doc ) ;
@@ -670,6 +678,20 @@ describe('samlp', function () {
670678 done ( ) ;
671679 } ) ;
672680 } ) ;
681+
682+ describe ( 'when invalid signing key is used' , function ( ) {
683+ before ( function ( ) {
684+ server . options . key = 'invalid_signing_key' ;
685+ } ) ;
686+
687+ it ( 'should return an error' , function ( done ) {
688+ doRawSAMLRequest ( function ( response ) {
689+ expect ( response . statusCode ) . to . equal ( 400 ) ;
690+ expect ( response . body ) . to . match ( / e r r o r : \w + : P E M r o u t i n e s : \w + : n o s t a r t l i n e / ) ;
691+ done ( ) ;
692+ } ) ;
693+ } ) ;
694+ } ) ;
673695 } ) ;
674696
675697 describe ( 'signResponse=true and signAssertion is undefined' , function ( ) {
@@ -701,6 +723,24 @@ describe('samlp', function () {
701723 done ( ) ;
702724 } ) ;
703725 } ) ;
726+
727+ describe ( 'when invalid signing key is used' , function ( ) {
728+ before ( function ( ) {
729+ server . options . key = 'invalid_signing_key' ;
730+ } ) ;
731+
732+ after ( function ( ) {
733+ delete server . options . key ;
734+ } ) ;
735+
736+ it ( 'should return an error' , function ( done ) {
737+ doRawSAMLRequest ( function ( response ) {
738+ expect ( response . statusCode ) . to . equal ( 400 ) ;
739+ expect ( response . body ) . to . match ( / e r r o r : \w + : P E M r o u t i n e s : \w + : n o s t a r t l i n e / ) ;
740+ done ( ) ;
741+ } ) ;
742+ } ) ;
743+ } ) ;
704744 } ) ;
705745
706746 describe ( 'signResponse=false and signAssertion=true' , function ( ) {
0 commit comments