Skip to content

Commit ec2ea17

Browse files
committed
feat: replace Validate() with ValidateReferences()
1 parent 3f4aac3 commit ec2ea17

4 files changed

+27
-17
lines changed

signedxml_test.go

+26-7
Original file line numberDiff line numberDiff line change
@@ -167,25 +167,44 @@ func TestValidate(t *testing.T) {
167167

168168
Convey("Given invalid signed XML", t, func() {
169169
cases := map[string]string{
170-
"(Changed Content)": "./testdata/invalid-signature-changed content.xml",
170+
"(Changed Content)": "./testdata/invalid-signature-changed-content.xml",
171171
"(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+
})
173189
}
174190

191+
cases = map[string]string{
192+
"(Wrong Sig Value)": "./testdata/invalid-signature-signature-value.xml",
193+
}
175194
for description, test := range cases {
176195
Convey(fmt.Sprintf("When ValidateReferences is called %s", description), func() {
177-
xmlFile, err := os.Open(test)
196+
xmlBytes, err := os.ReadFile(test)
178197
if err != nil {
179-
fmt.Println("Error opening file:", err)
198+
fmt.Println("Error reading file:", err)
180199
}
181-
defer xmlFile.Close()
182-
xmlBytes, _ := ioutil.ReadAll(xmlFile)
183200
validator, _ := NewValidator(string(xmlBytes))
184201

185-
err = validator.Validate()
202+
refs, err := validator.ValidateReferences()
186203
Convey("Then an error occurs", func() {
187204
So(err, ShouldNotBeNil)
188205
So(err.Error(), ShouldContainSubstring, "signedxml:")
206+
t.Logf("%v - %d", description, len(refs))
207+
So(len(refs), ShouldEqual, 1)
189208
})
190209
})
191210
}

testdata/invalid-signature-signature-value.xml

+1-1
Large diffs are not rendered by default.

validator.go

-9
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,6 @@ func (v *Validator) SigningCert() x509.Certificate {
4848
return v.signingCert
4949
}
5050

51-
// Validate validates the Reference digest values, and the signature value
52-
// over the SignedInfo.
53-
//
54-
// Deprecated: Use ValidateReferences instead
55-
func (v *Validator) Validate() error {
56-
_, err := v.ValidateReferences()
57-
return err
58-
}
59-
6051
// ValidateReferences validates the Reference digest values, and the signature value
6152
// over the SignedInfo.
6253
//

0 commit comments

Comments
 (0)