@@ -167,25 +167,44 @@ func TestValidate(t *testing.T) {
167
167
168
168
Convey ("Given invalid signed XML" , t , func () {
169
169
cases := map [string ]string {
170
- "(Changed Content)" : "./testdata/invalid-signature-changed content.xml" ,
170
+ "(Changed Content)" : "./testdata/invalid-signature-changed- content.xml" ,
171
171
"(Non-existing Reference)" : "./testdata/invalid-signature-non-existing-reference.xml" ,
172
- "(Wrong Sig Value)" : "./testdata/invalid-signature-signature-value.xml" ,
172
+ }
173
+ for description , test := range cases {
174
+ Convey (fmt .Sprintf ("When ValidateReferences is called %s" , description ), func () {
175
+ xmlBytes , err := os .ReadFile (test )
176
+ if err != nil {
177
+ fmt .Println ("Error reading file:" , err )
178
+ }
179
+ validator , _ := NewValidator (string (xmlBytes ))
180
+
181
+ refs , err := validator .ValidateReferences ()
182
+ Convey ("Then an error occurs" , func () {
183
+ So (err , ShouldNotBeNil )
184
+ So (err .Error (), ShouldContainSubstring , "signedxml:" )
185
+ t .Logf ("%v - %d" , description , len (refs ))
186
+ So (len (refs ), ShouldEqual , 0 )
187
+ })
188
+ })
173
189
}
174
190
191
+ cases = map [string ]string {
192
+ "(Wrong Sig Value)" : "./testdata/invalid-signature-signature-value.xml" ,
193
+ }
175
194
for description , test := range cases {
176
195
Convey (fmt .Sprintf ("When ValidateReferences is called %s" , description ), func () {
177
- xmlFile , err := os .Open (test )
196
+ xmlBytes , err := os .ReadFile (test )
178
197
if err != nil {
179
- fmt .Println ("Error opening file:" , err )
198
+ fmt .Println ("Error reading file:" , err )
180
199
}
181
- defer xmlFile .Close ()
182
- xmlBytes , _ := ioutil .ReadAll (xmlFile )
183
200
validator , _ := NewValidator (string (xmlBytes ))
184
201
185
- err = validator .Validate ()
202
+ refs , err : = validator .ValidateReferences ()
186
203
Convey ("Then an error occurs" , func () {
187
204
So (err , ShouldNotBeNil )
188
205
So (err .Error (), ShouldContainSubstring , "signedxml:" )
206
+ t .Logf ("%v - %d" , description , len (refs ))
207
+ So (len (refs ), ShouldEqual , 1 )
189
208
})
190
209
})
191
210
}
0 commit comments