Skip to content

Commit f733fc8

Browse files
committed
test: replace .Validate() calls with .ValidateReferences()
Issue: moov-io#23
1 parent 51ef967 commit f733fc8

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Other packages that provide similar functionality rely on C libraries, which mak
5454
### Examples
5555

5656
#### Validating signed XML
57-
If your signed xml contains the signature and certificate, then you can just pass in the xml and call `Validate()`.
57+
If your signed xml contains the signature and certificate, then you can just pass in the xml and call `ValidateReferences()`.
5858
```go
5959
validator, err := signedxml.NewValidator(`<YourXMLString></YourXMLString>`)
6060
xml, err = validator.ValidateReferences()

examples/examples.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ func testValidator() {
2727
if err != nil {
2828
fmt.Printf("Validation Error: %s", err)
2929
} else {
30-
err = validator.Validate()
30+
refs, err := validator.ValidateReferences()
3131
if err != nil {
3232
fmt.Printf("Validation Error: %s\n", err)
33+
}
34+
if len(refs) == 0 {
35+
fmt.Println("ERROR: No Validated References")
3336
} else {
3437
fmt.Println("Example Validation Succeeded")
3538
}

signedxml_test.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ func TestSign(t *testing.T) {
3333
Convey("And the signature should be valid", func() {
3434
validator, _ := NewValidator(xmlStr)
3535
validator.Certificates = append(validator.Certificates, *cert)
36-
err := validator.Validate()
36+
refs, err := validator.ValidateReferences()
3737
So(err, ShouldBeNil)
38+
So(len(refs), ShouldEqual, 1)
3839
})
3940
})
4041
})
@@ -51,8 +52,9 @@ func TestSign(t *testing.T) {
5152
Convey("And the signature should be valid", func() {
5253
validator, _ := NewValidator(xmlStr)
5354
validator.Certificates = append(validator.Certificates, *cert)
54-
err := validator.Validate()
55+
refs, err := validator.ValidateReferences()
5556
So(err, ShouldBeNil)
57+
So(len(refs), ShouldEqual, 1)
5658
})
5759
})
5860
})
@@ -71,14 +73,16 @@ func TestSign(t *testing.T) {
7173
validator, _ := NewValidator(xmlStr)
7274
validator.Certificates = append(validator.Certificates, *cert)
7375
validator.SetReferenceIDAttribute("customId")
74-
err := validator.Validate()
76+
refs, err := validator.ValidateReferences()
7577
So(err, ShouldBeNil)
78+
So(len(refs), ShouldEqual, 1)
7679
})
7780
Convey("And the signature should be valid, but validation fail if referenceIDAttribute NOT SET", func() {
7881
validator, _ := NewValidator(xmlStr)
7982
validator.Certificates = append(validator.Certificates, *cert)
80-
err := validator.Validate()
83+
refs, err := validator.ValidateReferences()
8184
So(err, ShouldNotBeNil)
85+
So(len(refs), ShouldEqual, 0)
8286
})
8387
})
8488

@@ -115,10 +119,11 @@ func TestValidate(t *testing.T) {
115119
defer xmlFile.Close()
116120
xmlBytes, _ := ioutil.ReadAll(xmlFile)
117121
validator, _ := NewValidator(string(xmlBytes))
118-
err = validator.Validate()
122+
refs, err := validator.ValidateReferences()
119123
Convey("Then no error occurs", func() {
120124
So(err, ShouldBeNil)
121125
So(validator.SigningCert().PublicKey, ShouldNotBeNil)
126+
So(len(refs), ShouldEqual, 1)
122127
})
123128
})
124129
}
@@ -131,10 +136,11 @@ func TestValidate(t *testing.T) {
131136
validator := Validator{}
132137
validator.SetXML(string(xmlBytes))
133138
validator.SetSignature(sig)
134-
err := validator.Validate()
139+
refs, err := validator.ValidateReferences()
135140
Convey("Then no error occurs", func() {
136141
So(err, ShouldBeNil)
137142
So(validator.SigningCert().PublicKey, ShouldNotBeNil)
143+
So(len(refs), ShouldEqual, 1)
138144
})
139145
})
140146

@@ -148,10 +154,11 @@ func TestValidate(t *testing.T) {
148154
validator := Validator{}
149155
validator.SetXML(string(xmlBytes))
150156
validator.Certificates = append(validator.Certificates, *cert)
151-
err := validator.Validate()
157+
refs, err := validator.ValidateReferences()
152158
Convey("Then no error occurs", func() {
153159
So(err, ShouldBeNil)
154160
So(validator.SigningCert().PublicKey, ShouldNotBeNil)
161+
So(len(refs), ShouldEqual, 1)
155162
})
156163
})
157164
})
@@ -164,7 +171,7 @@ func TestValidate(t *testing.T) {
164171
}
165172

166173
for description, test := range cases {
167-
Convey(fmt.Sprintf("When Validate is called %s", description), func() {
174+
Convey(fmt.Sprintf("When ValidateReferences is called %s", description), func() {
168175
xmlFile, err := os.Open(test)
169176
if err != nil {
170177
fmt.Println("Error opening file:", err)

0 commit comments

Comments
 (0)