Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions federation/federation_fuzz_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package federation

import (
"bytes"
"context"
"encoding/json"
"net/url"
Expand Down Expand Up @@ -326,11 +327,20 @@ func countNew(overrides, params map[string]json.RawMessage) int {

func jsonValuesEqual(t *testing.T, a, b json.RawMessage) bool {
t.Helper()
var av, bv any
if json.Unmarshal(a, &av) != nil || json.Unmarshal(b, &bv) != nil {
return false
}
return reflect.DeepEqual(av, bv)
av, aok := decodeExactJSON(a)
bv, bok := decodeExactJSON(b)
return aok && bok && reflect.DeepEqual(av, bv)
}

// decodeExactJSON is raw decoded with its numbers kept as their text
// (json.Number), so a number outside float64's range, which encoding/json
// can't decode into a float64, still compares equal to the same number:
// applySuperiorMetadata carries a value through as written.
func decodeExactJSON(raw json.RawMessage) (any, bool) {
dec := json.NewDecoder(bytes.NewReader(raw))
dec.UseNumber()
var v any
return v, dec.Decode(&v) == nil
}

// FuzzValidEntityID checks ValidEntityID against OpenID Federation 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go test fuzz v1
string("{\"\":{\"\":{\"\":200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000}}}")
string("{\"\":{}}")
Loading