@@ -12,36 +12,45 @@ describe("SAML response tests", function () {
12
12
"/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']" ,
13
13
doc ,
14
14
) ;
15
- const sig = new SignedXml ( ) ;
16
- sig . publicCert = fs . readFileSync ( "./test/static/feide_public.pem" ) ;
17
- // @ts -expect-error FIXME
18
- sig . loadSignature ( signature ) ;
19
- const result = sig . checkSignature ( xml ) ;
15
+ if ( xpath . isNodeLike ( signature ) ) {
16
+ const sig = new SignedXml ( ) ;
17
+ sig . publicCert = fs . readFileSync ( "./test/static/feide_public.pem" ) ;
18
+ sig . loadSignature ( signature ) ;
19
+ const result = sig . checkSignature ( xml ) ;
20
20
21
- expect ( result ) . to . be . true ;
21
+ expect ( result ) . to . be . true ;
22
+ } else {
23
+ expect ( xpath . isNodeLike ( signature ) ) . to . be . true ;
24
+ }
22
25
} ) ;
23
26
24
27
it ( "test validating wrapped assertion signature" , function ( ) {
25
28
const xml = fs . readFileSync ( "./test/static/valid_saml_signature_wrapping.xml" , "utf-8" ) ;
26
29
const doc = new xmldom . DOMParser ( ) . parseFromString ( xml ) ;
27
30
const assertion = xpath . select1 ( "//*[local-name(.)='Assertion']" , doc ) ;
28
- const signature = xpath . select1 (
29
- "//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']" ,
30
- // @ts -expect-error FIXME
31
- assertion ,
32
- ) ;
33
- const sig = new SignedXml ( ) ;
34
- sig . publicCert = fs . readFileSync ( "./test/static/feide_public.pem" ) ;
35
- // @ts -expect-error FIXME
36
- sig . loadSignature ( signature ) ;
37
- expect (
38
- function ( ) {
39
- sig . checkSignature ( xml ) ;
40
- } ,
41
- "Should not validate a document which contains multiple elements with the " +
42
- "same value for the ID / Id / Id attributes, in order to prevent " +
43
- "signature wrapping attack." ,
44
- ) . to . throw ( ) ;
31
+ if ( xpath . isNodeLike ( assertion ) ) {
32
+ const signature = xpath . select1 (
33
+ "//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']" ,
34
+ assertion ,
35
+ ) ;
36
+ if ( xpath . isNodeLike ( signature ) ) {
37
+ const sig = new SignedXml ( ) ;
38
+ sig . publicCert = fs . readFileSync ( "./test/static/feide_public.pem" ) ;
39
+ sig . loadSignature ( signature ) ;
40
+ expect (
41
+ function ( ) {
42
+ sig . checkSignature ( xml ) ;
43
+ } ,
44
+ "Should not validate a document which contains multiple elements with the " +
45
+ "same value for the ID / Id / Id attributes, in order to prevent " +
46
+ "signature wrapping attack." ,
47
+ ) . to . throw ( ) ;
48
+ } else {
49
+ expect ( xpath . isNodeLike ( signature ) ) . to . be . true ;
50
+ }
51
+ } else {
52
+ expect ( xpath . isNodeLike ( assertion ) ) . to . be . true ;
53
+ }
45
54
} ) ;
46
55
47
56
it ( "test validating SAML response where a namespace is defined outside the signed element" , function ( ) {
@@ -51,30 +60,39 @@ describe("SAML response tests", function () {
51
60
"//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']" ,
52
61
doc ,
53
62
) ;
54
- const sig = new SignedXml ( ) ;
55
- sig . publicCert = fs . readFileSync ( "./test/static/saml_external_ns.pem" ) ;
56
- // @ts -expect-error FIXME
57
- sig . loadSignature ( signature ) ;
58
- const result = sig . checkSignature ( xml ) ;
59
- expect ( result ) . to . be . true ;
63
+ if ( xpath . isNodeLike ( signature ) ) {
64
+ const sig = new SignedXml ( ) ;
65
+ sig . publicCert = fs . readFileSync ( "./test/static/saml_external_ns.pem" ) ;
66
+ sig . loadSignature ( signature ) ;
67
+ const result = sig . checkSignature ( xml ) ;
68
+ expect ( result ) . to . be . true ;
69
+ } else {
70
+ expect ( xpath . isNodeLike ( signature ) ) . to . be . true ;
71
+ }
60
72
} ) ;
61
73
62
74
it ( "test reference id does not contain quotes" , function ( ) {
63
75
const xml = fs . readFileSync ( "./test/static/id_with_quotes.xml" , "utf-8" ) ;
64
76
const doc = new xmldom . DOMParser ( ) . parseFromString ( xml ) ;
65
77
const assertion = xpath . select1 ( "//*[local-name(.)='Assertion']" , doc ) ;
66
- const signature = xpath . select1 (
67
- "//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']" ,
68
- // @ts -expect-error FIXME
69
- assertion ,
70
- ) ;
71
- const sig = new SignedXml ( ) ;
72
- sig . publicCert = fs . readFileSync ( "./test/static/feide_public.pem" ) ;
73
- // @ts -expect-error FIXME
74
- sig . loadSignature ( signature ) ;
75
- expect ( function ( ) {
76
- sig . checkSignature ( xml ) ;
77
- } , "id should not contain quotes" ) . to . throw ( ) ;
78
+ if ( xpath . isNodeLike ( assertion ) ) {
79
+ const signature = xpath . select1 (
80
+ "//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']" ,
81
+ assertion ,
82
+ ) ;
83
+ if ( xpath . isNodeLike ( signature ) ) {
84
+ const sig = new SignedXml ( ) ;
85
+ sig . publicCert = fs . readFileSync ( "./test/static/feide_public.pem" ) ;
86
+ sig . loadSignature ( signature ) ;
87
+ expect ( function ( ) {
88
+ sig . checkSignature ( xml ) ;
89
+ } , "id should not contain quotes" ) . to . throw ( ) ;
90
+ } else {
91
+ expect ( xpath . isNodeLike ( signature ) ) . to . be . true ;
92
+ }
93
+ } else {
94
+ expect ( xpath . isNodeLike ( assertion ) ) . to . be . true ;
95
+ }
78
96
} ) ;
79
97
80
98
it ( "test validating SAML response WithComments" , function ( ) {
@@ -84,12 +102,15 @@ describe("SAML response tests", function () {
84
102
"/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']" ,
85
103
doc ,
86
104
) ;
87
- const sig = new SignedXml ( ) ;
88
- sig . publicCert = fs . readFileSync ( "./test/static/feide_public.pem" ) ;
89
- // @ts -expect-error FIXME
90
- sig . loadSignature ( signature ) ;
91
- const result = sig . checkSignature ( xml ) ;
92
- // This doesn't matter, just want to make sure that we don't fail due to unknown algorithm
93
- expect ( result ) . to . be . false ;
105
+ if ( xpath . isNodeLike ( signature ) ) {
106
+ const sig = new SignedXml ( ) ;
107
+ sig . publicCert = fs . readFileSync ( "./test/static/feide_public.pem" ) ;
108
+ sig . loadSignature ( signature ) ;
109
+ const result = sig . checkSignature ( xml ) ;
110
+ // This doesn't matter, just want to make sure that we don't fail due to unknown algorithm
111
+ expect ( result ) . to . be . false ;
112
+ } else {
113
+ expect ( xpath . isNodeLike ( signature ) ) . to . be . true ;
114
+ }
94
115
} ) ;
95
116
} ) ;
0 commit comments