MCPcopy Create free account
hub / github.com/buger/jsonparser / TestJSONFuzzCorpusSanity

Function TestJSONFuzzCorpusSanity

json_fuzz_test.go:1581–1620  ·  view source on GitHub ↗

============================================================================= Corpus-seeding helper (non-fuzz regression gate) ============================================================================= TestJSONFuzzCorpusSanity runs every seed corpus entry AND a batch of grammar-generated inputs t

(t *testing.T)

Source from the content-addressed store, hash-verified

1579//
1580// Verifies: SYS-REQ-035
1581func TestJSONFuzzCorpusSanity(t *testing.T) {
1582 // 1. Run each static seed through the gates.
1583 for i, seed := range structureAwareSeeds {
1584 seed := seed
1585 t.Run(fmt.Sprintf("seed_%02d_data_%q_path_%q", i, seed.data, seed.path), func(t *testing.T) {
1586 path := splitPathComponents(seed.path)
1587 runStructureAwareGates(t, seed.data, path)
1588 })
1589 }
1590
1591 // 2. Grammar-generated inputs: exercise the generator + mutations under
1592 // `go test` without requiring the fuzz engine. This is the path that
1593 // exercises structure-aware generation most directly.
1594 r := rand.New(rand.NewSource(0xC0FFEE))
1595 for i := 0; i < 300; i++ {
1596 depth := r.Intn(4)
1597 if r.Intn(10) == 0 {
1598 depth = 5 + r.Intn(3)
1599 }
1600 data := genJSON(r, depth)
1601
1602 // Generator note: genJSON produces mostly-valid JSON, but per the
1603 // spec it intentionally includes a small fraction of near-valid
1604 // edge cases (e.g. leading-zero numbers like "007") that test the
1605 // parser's leniency. We do NOT hard-assert json.Valid here — the
1606 // gates below are the real correctness test, and they handle
1607 // invalid input gracefully (the OUTPUT-VALIDITY gate is gated on
1608 // dataValid, so it only fires for truly valid input).
1609
1610 // Apply 0–3 mutations (the mutations intentionally break validity).
1611 for n := r.Intn(4); n > 0; n-- {
1612 data = applyMutation(r, data)
1613 }
1614
1615 path := genKeyPath(r)
1616 t.Run(fmt.Sprintf("gen_%03d", i), func(t *testing.T) {
1617 runStructureAwareGates(t, data, path)
1618 })
1619 }
1620}
1621
1622// =============================================================================
1623// DoS / scale regression gate (closes Dimension 5)

Callers

nothing calls this directly

Calls 5

splitPathComponentsFunction · 0.85
runStructureAwareGatesFunction · 0.85
genJSONFunction · 0.85
applyMutationFunction · 0.85
genKeyPathFunction · 0.85

Tested by

no test coverage detected