Skip to content

test: fuzz the formats, the reading of the fields and the tags - #78

Merged
Insei merged 3 commits into
mainfrom
test/fuzz
Oct 19, 2026
Merged

Insei merged 3 commits into
mainfrom
test/fuzz

Conversation

@Insei

@Insei Insei commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

On top of #79 (merged).

Fuzz targets:

  • rules/str: FuzzPatterns (UUID, E.164, hex color, alphanumeric, alpha, digits, numeric, hexadecimal, hostname against their regexps — the patterns of JSON Schema of the rules, so the schema describes the same strings), FuzzEncodings (base64, base64url, MAC against encoding/base64, net.ParseMAC), FuzzChecksums (Luhn against a reference implementation, credit cards), FuzzURL (a valid URL is parsed by url.Parse with a scheme and a host).
  • shared: FuzzFieldAccess — Getter, InStruct and the elements of slices of pointers read by the offsets of fmap are the fields themselves, with nil nested structs, nil pointers and nil elements.
  • internal/tags: FuzzTags — any tag on fields of 12 types either configures the rules or panics with valigo: tag ... in Configure, and the rules validate zero and filled values without panics.

Found and fixed (fix(str)): URL accepted invalid userinfo (A://"@0) and IPv6 zones (https://[::0%00]), url.Parse rejects both. The found inputs stay in testdata/fuzz as regression tests. Local runs: 60–180 s per target, nothing else found.

CI: the fuzz job runs scripts/fuzz.sh, every target for 30 s.

@Insei
Insei force-pushed the feat/tags-complete branch from 96e1b78 to efe9edf Compare October 19, 2026 09:50
@Insei
Insei changed the base branch from feat/tags-complete to main October 19, 2026 09:52
Insei added 3 commits October 19, 2026 12:53
The userinfo was checked only for whitespace, A://"@0 was valid; it is
the userinfo of RFC 3986 now. A zone of an IPv6 host, [::0%00], was
accepted by netip; url.Parse needs it escaped, the zones aren't allowed.
Both were found by fuzzing against url.Parse.
The formats of strings are checked against the parsers of the standard
library and the patterns of their JSON Schema, the reading of the fields
by the offsets of fmap against the fields themselves, and any tag either
configures the rules or panics with its error, the rules never panic.
The inputs found by fuzzing are kept in testdata.
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark diff: 1d6cc8e → 2f4c39c (10 runs)

goos: linux
goarch: amd64
pkg: github.com/insei/valigo
cpu: AMD EPYC 7763 64-Core Processor                
           │  base.txt   │              head.txt              │
           │   sec/op    │   sec/op     vs base               │
Validate-4   159.0n ± 1%   148.2n ± 2%  -6.73% (p=0.000 n=10)

           │  base.txt  │            head.txt            │
           │    B/op    │    B/op     vs base            │
Validate-4   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

           │  base.txt  │            head.txt            │
           │ allocs/op  │ allocs/op   vs base            │
Validate-4   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (1d6cc8e) to head (f945897).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #78   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           38        38           
  Lines         1775      1784    +9     
=========================================
+ Hits          1775      1784    +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Insei
Insei merged commit cc67d6a into main Oct 19, 2026
7 checks passed
@Insei
Insei deleted the test/fuzz branch October 19, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants