conformance

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package conformance runs the CTIS conformance vectors (conformance/v2) against this implementation. The same vectors let any other implementation check itself: they are plain JSON, see conformance/README.md, and conformance/PROTOCOL.md describes the line protocol (Serve) through which scripts/conformance_harness.py drives any implementation.

Index

Constants

View Source
const (
	CategoryProtocol    = "protocol"    // the request is malformed
	CategoryUnsupported = "unsupported" // the implementation does not provide the op
	CategoryCanonical   = "canonical"   // the value has no canonical form
	CategoryFingerprint = "fingerprint" // the input forms no fingerprint
	CategoryWebURL      = "web_url"     // the URL is refused
	CategoryVersion     = validatedoc.CategoryVersion
	CategoryDecode      = validatedoc.CategoryDecode
	CategoryValidate    = validatedoc.CategoryValidate
	CategoryMapping     = "mapping" // a mapping file is refused
	CategoryInput       = "input"   // the input of a mapping is refused as a whole
)

Error categories of an operation. The document categories (version, decode, validate) are those of the documents manifest.

View Source
const MaxRequestBytes = 64 << 20

MaxRequestBytes bounds one request line of the protocol.

Variables

View Source
var (
	RequiredOps = []string{
		"canonical", "asset_key", "vulnerability_id", "preferred_id", "location_key",
		"fingerprint", "secret_digest", "correlation_key", "web_url", "decode", "validate",
	}
	OptionalOps = []string{"mapping_apply", "interop_path_match", "interop_select", "interop_collect"}
)

RequiredOps are the operations every CTIS implementation provides (the core); OptionalOps belong to the declarative mapping language and the interoperability engine, which a binding may leave out.

View Source
var CanonicalFunctions = []string{
	"CanonicalAssetValue", "CanonicalDomain", "CanonicalIP", "CanonicalCIDR", "CanonicalService",
	"CanonicalOrigin", "CanonicalURL", "CanonicalRepository", "CanonicalPurl", "CanonicalCPE",
	"CanonicalImage", "CanonicalARN", "CanonicalAzureResourceID", "CanonicalGCPResourceName",
	"CanonicalCertificateFingerprint",
}

CanonicalFunctions are the function names of the "canonical" operation.

Functions

func Canonical

func Canonical(fn string, in json.RawMessage) (any, error)

Canonical applies a canonical-form function named by a vector file to the vector's input and returns the result (a string, or an object for CanonicalPurl).

func Cases added in v2.0.2

func Cases(dir string) ([]Case, []LoadError)

Cases reads every vector family under dir (a conformance/v2 directory).

func Info added in v2.0.2

func Info(implementation, version string) map[string]any

Info is the output of the "info" operation.

func Serve added in v2.0.2

func Serve(r io.Reader, w io.Writer, implementation, version string) error

Serve answers protocol requests (conformance/PROTOCOL.md): one JSON object per line on r, one answer per line on w, in order. It returns when r ends, or with the error of a failed read or write. implementation and version name this implementation in the answer to "info".

Types

type Case added in v2.0.2

type Case struct {
	Suite   string
	Name    string
	Op      string
	Input   json.RawMessage
	Want    json.RawMessage // the expected output when WantErr is nil
	WantErr *WantError
}

Case is one vector as a protocol request and the answer it expects. scripts/conformance_harness.py builds the same cases from the same files.

func (*Case) Check added in v2.0.2

func (c *Case) Check(got any, e *OpError, messages bool) error

Check compares an answer with the case's expectation. With messages set, an expected error message substring must occur in the answer's message (the Go reference words its messages as the vectors say; another implementation matches on the category only).

type LoadError added in v2.0.2

type LoadError struct {
	Suite, Name, Err string
}

LoadError is a vector file that could not be read; it counts as a failed vector.

type OpError added in v2.0.2

type OpError struct {
	Category string `json:"category"`
	Message  string `json:"message"`
}

OpError is the error answer of an operation.

func Do added in v2.0.2

func Do(op string, in json.RawMessage) (any, *OpError)

Do runs one operation on its input and returns the output, or the error answer. The "info" operation is answered by the caller (Serve).

func (*OpError) Error added in v2.0.2

func (e *OpError) Error() string

type Result

type Result struct {
	Suite string // for example "canonical/domain.json" or "documents"
	Name  string
	Err   string // empty when the vector passed
}

Result is the outcome of one vector.

func Failures

func Failures(rs []Result) []Result

Failures returns the results that did not pass.

func Run

func Run(dir string) ([]Result, error)

Run executes every vector under dir (a conformance/v2 directory) and returns one Result per vector. It returns an error only when dir cannot be read at all.

type WantError added in v2.0.2

type WantError struct {
	Category string `json:"category"`
	Message  string `json:"message,omitempty"`
}

WantError is an expected error answer: the category (empty: any) and a substring of the message (informative, see Check).

Jump to

Keyboard shortcuts

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