conformance

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package conformance is the sensor protocol conformance suite (RFC-026 WP-S3, RFC-023 D23), starting with results ingest.

It has two halves:

  • FakePlatform, a control plane that implements the v2 results contract (RFC-026 §3) strictly and the v1 routes a sensor uses, records every request and can be told to fail in each §3.8 class. The SDK's own tests run against it: they check the SDK sends the right headers and digest, retries only what it should, splits on 413, never resends a partially accepted report and reuses report_id on retry.
  • The live suite (live_test.go), which runs the same contract against a real API: OPENCTEM_CONFORMANCE_URL and OPENCTEM_CONFORMANCE_KEY (a sensor key) select it; see the package README in the test file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakePlatform

type FakePlatform struct {
	Server *httptest.Server
	// APIKey is the sensor key it accepts.
	APIKey string
	// V2 serves the v2 routes and advertises them; false behaves like a
	// platform from before RFC-026 (404 on /api/v2).
	V2 bool
	// Limits are published on hello.
	Limits protov2.Limits
	// Tools are the sensor's declared tools (empty: any).
	Tools []string
	// Control serves the api RFC-029 control plane on v2 (heartbeat,
	// commands, suppressions, fingerprints, keys) and lists it on hello.
	// False (with V2) is a platform from api v0.8: v2 results only.
	Control bool
	// Paused answers heartbeats as for a disabled sensor (v2: 200 + pause).
	Paused bool
	// contains filtered or unexported fields
}

FakePlatform is an in-process control plane. Safe for concurrent use.

func NewFakePlatform

func NewFakePlatform(v2 bool) *FakePlatform

NewFakePlatform starts a fake platform. Close it with Close.

func (*FakePlatform) AcceptedFindings

func (f *FakePlatform) AcceptedFindings() int

AcceptedFindings counts the findings of committed v2 reports plus v1 reports.

func (*FakePlatform) Close

func (f *FakePlatform) Close()

Close stops the server.

func (*FakePlatform) CommandResult added in v0.9.0

func (f *FakePlatform) CommandResult(id string) json.RawMessage

CommandResult returns the result a completed command stored.

func (*FakePlatform) CommandState

func (f *FakePlatform) CommandState(id string) (string, string)

CommandState returns a command's state and its error message.

func (*FakePlatform) HeartbeatBuilds added in v0.10.0

func (f *FakePlatform) HeartbeatBuilds() []HeartbeatBuild

HeartbeatBuilds returns the "sdk" and "sensor" blocks of every heartbeat received, v1 and v2, in order.

func (*FakePlatform) HeartbeatOutbox

func (f *FakePlatform) HeartbeatOutbox() []json.RawMessage

HeartbeatOutbox returns the outbox objects heartbeats carried.

func (*FakePlatform) Heartbeats added in v0.10.0

func (f *FakePlatform) Heartbeats() []json.RawMessage

Heartbeats returns the heartbeat bodies received, v1 and v2, in order.

func (*FakePlatform) OpenCommand

func (f *FakePlatform) OpenCommand(id string)

OpenCommand registers a running command assigned to the sensor.

func (*FakePlatform) QueueCommand added in v0.9.0

func (f *FakePlatform) QueueCommand(id string)

QueueCommand adds a pending command a poll offers.

func (*FakePlatform) Releases added in v0.10.0

func (f *FakePlatform) Releases() []Release

Releases returns the releases received, in order.

func (*FakePlatform) Reports

func (f *FakePlatform) Reports() map[string]*StoredReport

Reports returns the accepted v2 reports by id.

func (*FakePlatform) Requests

func (f *FakePlatform) Requests() []Request

Requests returns the recorded requests.

func (*FakePlatform) RequestsTo

func (f *FakePlatform) RequestsTo(method, prefix string) []Request

RequestsTo returns the recorded requests whose path has prefix.

func (*FakePlatform) SetAPIKey

func (f *FakePlatform) SetAPIKey(key string)

SetAPIKey replaces the accepted sensor key (a key rotation).

func (*FakePlatform) SetControl added in v0.9.0

func (f *FakePlatform) SetControl(on bool)

SetControl switches the RFC-029 control plane on v2 on or off.

func (*FakePlatform) SetFault

func (f *FakePlatform) SetFault(fl Fault)

SetFault installs a fault injector (nil removes it).

func (*FakePlatform) SetPaused added in v0.9.0

func (f *FakePlatform) SetPaused(on bool)

SetPaused answers heartbeats as for a disabled sensor.

func (*FakePlatform) SetV2

func (f *FakePlatform) SetV2(on bool)

SetV2 switches the v2 routes on or off.

func (*FakePlatform) URL

func (f *FakePlatform) URL() string

URL is the base URL.

func (*FakePlatform) V1Reports

func (f *FakePlatform) V1Reports() []*ctis.Report

V1Reports returns the reports received on the v1 ingest route.

type Fault

type Fault func(r *http.Request, seq int) *FaultAnswer

Fault makes the fake answer a request with an error instead of handling it. Return nil to handle it normally.

type FaultAnswer

type FaultAnswer struct {
	Status     int
	Problem    protov2.ProblemType // "" for a plain (non-problem) answer
	RetryAfter string
	// Drop closes the connection without answering (a network error, the
	// sender cannot tell whether the request was processed). With Process
	// the request is handled first: "the response was lost".
	Drop    bool
	Process bool
}

FaultAnswer is an injected answer.

type HeartbeatBuild added in v0.10.0

type HeartbeatBuild struct {
	SDK *struct {
		Name    string `json:"name"`
		Version string `json:"version"`
	} `json:"sdk"`
	Sensor *struct {
		Name      string `json:"name"`
		Version   string `json:"version"`
		Commit    string `json:"commit"`
		BuildTime string `json:"build_time"`
	} `json:"sensor"`
}

HeartbeatBuild is what a heartbeat says about the SDK and the sensor binary ("sdk" and "sensor"); nil where the heartbeat did not carry it.

type Release added in v0.10.0

type Release struct {
	CommandID, Reason string
}

Release is one release a sensor sent (api RFC-030).

type Request

type Request struct {
	Method, Path string
	Header       http.Header
	Body         []byte // as sent (compressed when Content-Encoding is set)
	Status       int    // what the fake answered
}

Request is one request the fake received.

type StoredReport

type StoredReport struct {
	ReportID  string
	CommandID string
	Segments  map[int]segment
	Committed bool
	Status    protov2.Status
}

StoredReport is a report the fake accepted.

Jump to

Keyboard shortcuts

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