corpusgen

package
v0.17.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package corpusgen produces deterministic edge-case seed values from neutral schema/auth constraints. It is a generation-time tool used by cmd/apic and the helpers/* emitters to bake intelligent f.Add(...) seeds into generated fuzz tests. Determinism is mandatory: no rand, no time — generated output must be byte-identical across runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fp

func Fp(v float64) *float64

func Intp

func Intp(v int) *int

Intp / Fp are pointer constructors for ergonomic Constraint building from non-pointer config fields (cmd/apic builds Constraint values directly).

func RenderLiteral

func RenderLiteral(v any) string

RenderLiteral renders a seed value as a deterministic Go source expression suitable for baking into generated test code. Maps render with sorted keys.

Types

type Constraint

type Constraint struct {
	Type         string // "string","integer","number","boolean","array","object","file"
	MinLen       *int
	MaxLen       *int
	Min          *float64
	Max          *float64
	ExclusiveMin bool
	ExclusiveMax bool
	Pattern      string
	Enum         []any
	Required     bool
	Nullable     bool
	Items        *Constraint
	Properties   map[string]Constraint
	PropRequired []string
	MinItems     *int
	MaxItems     *int
}

Constraint is a neutral description of one field's validation rules, decoupled from any specific schema model so adapters can map both the config SchemaProp and kin-openapi schemas onto it.

func FromOpenAPISchema

func FromOpenAPISchema(s *openapi3.Schema) Constraint

FromOpenAPISchema maps a kin-openapi schema to a neutral Constraint. Used by the helpers/* emitters which read api/cfgs/openapi.yaml. Returns the zero Constraint for a nil schema.

Note: this function maps SCALAR facets only (type/length/numeric/enum/pattern). It does not populate Items/Properties/PropRequired/MinItems/MaxItems because the current helpers/* consumers fuzz scalar request fields. Extend when object/array helper fuzzing is added.

type Seed

type Seed struct {
	Value any
	Tag   string
}

Seed is one edge-case value plus a short tag describing why it matters.

func AuthSeeds

func AuthSeeds(expr string) []Seed

AuthSeeds returns adversarial Authorization-header values for an auth mode or composite expression. The values are full header strings (e.g. "Bearer <token>"). "public"/"none" yield no seeds. The forged JWTs are static, well-known test fixtures (alg:none, etc.); add an allowlist entry in .gitleaks.toml if a scanner flags them.

func ObjectSeeds

func ObjectSeeds(c Constraint) []Seed

ObjectSeeds returns whole-object seeds: a valid in-bounds object, one variant per single-required-missing, and an extra-unknown-property object.

func ValuesFor

func ValuesFor(c Constraint) []Seed

ValuesFor returns deterministic edge-case seeds for a single constraint.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL