@@ -17,22 +17,26 @@ describe('Signatures', function() {
17
17
done ( ex ) ;
18
18
}
19
19
} ,
20
- testOneResponse = ( pathToXml , shouldErrorWith , amountOfSignatureChecks = 1 ) => {
20
+ testOneResponseBody = ( samlResponseBody , shouldErrorWith , amountOfSignatureChecks = 1 ) => {
21
21
return done => {
22
22
//== Instantiate new instance before every test
23
23
const samlObj = new SAML ( { cert } ) ;
24
24
//== Spy on `validateSignature` to be able to count how many times it has been called
25
25
const validateSignatureSpy = sinon . spy ( samlObj , 'validateSignature' ) ;
26
26
27
- //== Create a body bases on an XML an run the test in `func`
28
- samlObj . validatePostResponse ( createBody ( pathToXml ) , tryCatchTest ( done , function ( error ) {
27
+ //== Run the test in `func`
28
+ samlObj . validatePostResponse ( samlResponseBody , tryCatchTest ( done , function ( error ) {
29
29
//== Assert error. If the error is `SAML assertion expired` we made it past the certificate validation
30
30
shouldErrorWith ? error . should . eql ( new Error ( shouldErrorWith ) ) : error . should . eql ( new Error ( 'SAML assertion expired' ) ) ;
31
31
//== Assert times `validateSignature` was called
32
32
validateSignatureSpy . callCount . should . eql ( amountOfSignatureChecks ) ;
33
33
done ( ) ;
34
34
} ) ) ;
35
35
} ;
36
+ } ,
37
+ testOneResponse = ( pathToXml , ...args ) => {
38
+ //== Create a body based on an XML and run the test
39
+ return testOneResponseBody ( createBody ( pathToXml ) , ...args ) ;
36
40
} ;
37
41
38
42
describe ( 'Signatures on saml:Response - Only 1 saml:Assertion' , ( ) => {
@@ -80,4 +84,20 @@ describe('Signatures', function() {
80
84
81
85
} ) ;
82
86
87
+ describe ( 'Signature on saml:Response with non-LF line endings' , ( ) => {
88
+ const samlResponseXml = fs . readFileSync ( __dirname + '/static/signatures/valid/response.root-signed.assertion-signed.xml' ) . toString ( ) ;
89
+ const makeBody = str => ( { SAMLResponse : Buffer . from ( str ) . toString ( 'base64' ) } ) ;
90
+
91
+ it ( 'CRLF line endings' , done => {
92
+ const body = makeBody ( samlResponseXml . replace ( / \n / g, '\r\n' ) ) ;
93
+ testOneResponseBody ( body , false , 1 ) ( done ) ;
94
+ } ) ;
95
+
96
+ it ( 'CR line endings' , done => {
97
+ const body = makeBody ( samlResponseXml . replace ( / \n / g, '\r' ) ) ;
98
+ testOneResponseBody ( body , false , 1 ) ( done ) ;
99
+ } ) ;
100
+
101
+ } ) ;
102
+
83
103
} ) ;
0 commit comments