Documentation
¶
Overview ¶
Package transcript records real HTTP exchanges against a live lab and replays them offline.
The audit must not depend on a live backend: labs cost quota, rate-limit, and drift. The usual answer is a hand-written httptest handler, and this repo is full of them. They have one failure mode -- the fake and the real backend disagree and nobody notices, so the eval grades an imitation. A recorded transcript is the same fake with its provenance attached: it came off the real thing, and re-recording is how you find out it changed.
Two properties earn the package its place:
- Exchanges key on the AUTH CLASS as well as the path. Anonymous and authenticated requests to one URL are different observations, and on Neon they are the difference between a refusal and every row in a table.
- An unrecorded request is reported, never quietly answered. A missing recording that returns 404 looks exactly like a real negative result.
Credentials are never stored. Recording keeps the class ("anon"/"authed"), which is all replay needs and all a committed file should ever hold.
Index ¶
- Constants
- type Exchange
- type Request
- type Transcript
- func (t *Transcript) Add(method, path, auth string, status int, contentType, body string)
- func (t *Transcript) AddWithRequest(method, path, auth, requestBody string, status int, contentType, body string)
- func (t *Transcript) Save(path string) error
- func (t *Transcript) Server(onUnrecorded func(string)) *httptest.Server
Constants ¶
const ( Anon = "anon" Authed = "authed" )
Auth classes. These are the only two observations that matter to a posture scan: what a stranger sees, and what any account sees.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Exchange ¶
type Exchange struct {
Method string `json:"method"`
Path string `json:"path"` // path plus raw query
Auth string `json:"auth"` // Anon or Authed -- never a credential
Status int `json:"status"`
ContentType string `json:"content_type,omitempty"`
Body string `json:"body"`
// RequestBody is what was SENT, and it exists so a recording can be checked
// against the code that replays it.
//
// Replay does not key on it -- a probe should not have to send byte-identical
// JSON to be answered -- but without it nothing can ask whether the
// recording still answers the question the scanner asks. It did not, once:
// the Neon write probe stopped naming a column, five tables changed from
// 400 PGRST204 to 403/42501, and the committed transcript went on serving
// the old answers while every offline eval passed.
//
// Empty for requests that carry no body, which is most of them.
RequestBody string `json:"request_body,omitempty"`
}
An Exchange is one recorded request/response pair.
type Transcript ¶
type Transcript struct {
Exchanges []Exchange `json:"exchanges"`
}
A Transcript is an ordered set of exchanges. Order is normalised on save so re-recording an unchanged backend produces an unchanged file.
func Record ¶
Record performs each request against base and captures the responses.
token is used only to populate the Authorization header for Authed requests. It is never written to the transcript.
func (*Transcript) Add ¶
func (t *Transcript) Add(method, path, auth string, status int, contentType, body string)
Add appends an exchange.
func (*Transcript) AddWithRequest ¶
func (t *Transcript) AddWithRequest(method, path, auth, requestBody string, status int, contentType, body string)
AddWithRequest records an exchange and what was sent to provoke it.
func (*Transcript) Save ¶
func (t *Transcript) Save(path string) error
Save writes the transcript with exchanges in a stable order.
func (*Transcript) Server ¶
func (t *Transcript) Server(onUnrecorded func(string)) *httptest.Server
Server replays the transcript. onUnrecorded is called with a description of any request the transcript does not cover; it is not optional, because silently answering an unknown request is the failure this package exists to prevent.