Skip to content

Commit ff12104

Browse files
Seed fuzz corpus with real-world SAML response files from testdata
1 parent a59d76c commit ff12104

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

internal/fuzz/fuzz_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import (
3333
"encoding/binary"
3434
"fmt"
3535
"math/big"
36+
"os"
37+
"path/filepath"
3638
"testing"
3739
"time"
3840

@@ -206,6 +208,22 @@ func fuzzSP(km *fuzzKeyMaterial) *spkg.ServiceProvider {
206208
}
207209
}
208210

211+
// seedResponseFiles adds the contents of files matching glob as seed corpus entries.
212+
func seedResponseFiles(f *testing.F, glob string) {
213+
f.Helper()
214+
matches, err := filepath.Glob(glob)
215+
if err != nil {
216+
f.Fatal(err)
217+
}
218+
for _, path := range matches {
219+
data, err := os.ReadFile(path)
220+
if err != nil {
221+
f.Fatal(err)
222+
}
223+
f.Add(data)
224+
}
225+
}
226+
209227
// deflateEncode DEFLATE-compresses and base64-encodes data for HTTP-Redirect binding.
210228
func deflateEncode(data []byte) string {
211229
var buf bytes.Buffer
@@ -220,6 +238,9 @@ func FuzzDecodeResponse(f *testing.F) {
220238
f.Add([]byte(`<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" Version="2.0" ID="_1"><saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">test</saml2:Issuer></saml2p:Response>`))
221239
f.Add([]byte(`<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" Version="2.0" ID="_1"><saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">test</saml2:Issuer><saml2p:Status><saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/></saml2p:Status><saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" ID="_a1" Version="2.0"><saml2:Issuer>test</saml2:Issuer><saml2:Subject><saml2:NameID>user@test.com</saml2:NameID></saml2:Subject></saml2:Assertion></saml2p:Response>`))
222240

241+
// Seed with real-world SAML responses from various IdPs
242+
seedResponseFiles(f, "../../testdata/*_response.xml")
243+
223244
f.Fuzz(func(t *testing.T, data []byte) {
224245
encodedResponse := base64.StdEncoding.EncodeToString(data)
225246

@@ -745,6 +766,9 @@ func FuzzResponseXMLMutation(f *testing.F) {
745766
f.Add([]byte(seed))
746767
}
747768

769+
// Seed with real-world SAML responses from various IdPs
770+
seedResponseFiles(f, "../../testdata/*_response.xml")
771+
748772
f.Fuzz(func(t *testing.T, data []byte) {
749773
encoded := base64.StdEncoding.EncodeToString(data)
750774
_, _ = sp.ValidateEncodedResponse(context.Background(), encoded)

0 commit comments

Comments
 (0)