2022-11-12 17:44:12 +00:00
|
|
|
package token
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
fuzz "github.com/AdaLogics/go-fuzz-headers"
|
2024-05-14 08:21:38 +00:00
|
|
|
"github.com/go-jose/go-jose/v4"
|
2022-11-12 17:44:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func FuzzToken1(f *testing.F) {
|
|
|
|
f.Fuzz(func(t *testing.T, data []byte) {
|
|
|
|
ff := fuzz.NewConsumer(data)
|
|
|
|
rawToken, err := ff.GetString()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
verifyOps := VerifyOptions{}
|
|
|
|
err = ff.GenerateStruct(&verifyOps)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2024-05-14 08:21:38 +00:00
|
|
|
token, err := NewToken(rawToken, []jose.SignatureAlgorithm{jose.EdDSA, jose.RS384})
|
2022-11-12 17:44:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2023-11-18 06:50:40 +00:00
|
|
|
_, err = token.Verify(verifyOps)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2022-11-12 17:44:12 +00:00
|
|
|
_, _ = token.VerifySigningKey(verifyOps)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func FuzzToken2(f *testing.F) {
|
|
|
|
f.Fuzz(func(t *testing.T, data []byte) {
|
|
|
|
ff := fuzz.NewConsumer(data)
|
|
|
|
verifyOps := VerifyOptions{}
|
|
|
|
err := ff.GenerateStruct(&verifyOps)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
token := &Token{}
|
|
|
|
err = ff.GenerateStruct(token)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2023-11-18 06:50:40 +00:00
|
|
|
_, err = token.Verify(verifyOps)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2022-11-12 17:44:12 +00:00
|
|
|
_, _ = token.VerifySigningKey(verifyOps)
|
|
|
|
})
|
|
|
|
}
|