============================================================================= Non-fuzz regression test (runs under plain `go test`) ============================================================================= TestEncodingJSONCorpusSanity runs every seed + a batch of grammar-generated inputs through
(t *testing.T)
| 712 | // |
| 713 | // Verifies: SYS-REQ-035 |
| 714 | func TestEncodingJSONCorpusSanity(t *testing.T) { |
| 715 | // 1. encoding/json-specific seeds. |
| 716 | for i, seed := range encodingJSONSeeds { |
| 717 | seed := seed |
| 718 | t.Run(fmt.Sprintf("seed_%02d_%s", i, truncateForName(seed)), func(t *testing.T) { |
| 719 | runEncodingJSONGates(t, seed) |
| 720 | }) |
| 721 | } |
| 722 | |
| 723 | // 2. Shared structureAwareSeeds (data only). |
| 724 | for i, s := range structureAwareSeeds { |
| 725 | s := s |
| 726 | t.Run(fmt.Sprintf("struct_seed_%02d_%s", i, truncateForName(s.data)), func(t *testing.T) { |
| 727 | runEncodingJSONGates(t, s.data) |
| 728 | }) |
| 729 | } |
| 730 | |
| 731 | // 3. Grammar-generated + mutated inputs (the path that exercises |
| 732 | // structure-aware generation most directly under `go test`). |
| 733 | r := rand.New(rand.NewSource(0xDEADBEEF)) |
| 734 | for i := 0; i < 300; i++ { |
| 735 | depth := r.Intn(4) |
| 736 | if r.Intn(10) == 0 { |
| 737 | depth = 5 + r.Intn(3) |
| 738 | } |
| 739 | data := genJSON(r, depth) |
| 740 | for n := r.Intn(4); n > 0; n-- { |
| 741 | data = applyMutation(r, data) |
| 742 | } |
| 743 | i, data := i, data |
| 744 | t.Run(fmt.Sprintf("gen_%03d", i), func(t *testing.T) { |
| 745 | runEncodingJSONGates(t, data) |
| 746 | }) |
| 747 | } |
| 748 | |
| 749 | // 4. Gate D: deterministic deep-nesting depths (CVE-2020-29652 class). |
| 750 | t.Run("deep_nesting", func(t *testing.T) { |
| 751 | runDeepNestingDepths(t, []int{100, 1000, 10000, 100000}) |
| 752 | }) |
| 753 | |
| 754 | // 5. Gate H: deterministic deep-nesting transform DoS gate (Compact / |
| 755 | // Indent / HTMLEscape on deeply-nested input — the recursive scanner |
| 756 | // path that Gate D's Unmarshal test does NOT cover). |
| 757 | if !testing.Short() { |
| 758 | t.Run("transform_dos", func(t *testing.T) { |
| 759 | runTransformDoSGate(t, 1000) |
| 760 | runTransformDoSGate(t, 10000) |
| 761 | }) |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | // truncateForName renders a byte slice for use as a subtest name, capping the |
| 766 | // length so deeply-nested seeds (100 KB) don't produce gigantic test IDs. |
nothing calls this directly
no test coverage detected