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 ¶
- type FakePlatform
- func (f *FakePlatform) AcceptedFindings() int
- func (f *FakePlatform) Close()
- func (f *FakePlatform) CommandResult(id string) json.RawMessage
- func (f *FakePlatform) CommandState(id string) (string, string)
- func (f *FakePlatform) HeartbeatOutbox() []json.RawMessage
- func (f *FakePlatform) OpenCommand(id string)
- func (f *FakePlatform) QueueCommand(id string)
- func (f *FakePlatform) Reports() map[string]*StoredReport
- func (f *FakePlatform) Requests() []Request
- func (f *FakePlatform) RequestsTo(method, prefix string) []Request
- func (f *FakePlatform) SetAPIKey(key string)
- func (f *FakePlatform) SetControl(on bool)
- func (f *FakePlatform) SetFault(fl Fault)
- func (f *FakePlatform) SetPaused(on bool)
- func (f *FakePlatform) SetV2(on bool)
- func (f *FakePlatform) URL() string
- func (f *FakePlatform) V1Reports() []*ctis.Report
- type Fault
- type FaultAnswer
- type Request
- type StoredReport
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) 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) HeartbeatOutbox ¶
func (f *FakePlatform) HeartbeatOutbox() []json.RawMessage
HeartbeatOutbox returns the outbox objects heartbeats carried.
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) 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) 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.