Documentation
¶
Overview ¶
Package sighttest drives admin panels in tests: a header-based authenticator, a fixed subject table for switching roles, an HTTP client that handles CSRF, and a Live client for index and form events over the SSE+POST transport admin panels serve.
Index ¶
- Constants
- func Auth() auth.Authenticator
- func StateStoreSuite(t *testing.T, newStore func(t *testing.T) sight.StateStore)
- func Subjects(m map[string]rbac.Subject) func(ctx context.Context, userID string) (rbac.Subject, error)
- type Client
- func (c *Client) As(user string) *Client
- func (c *Client) CSRFToken(path string) string
- func (c *Client) Get(path string) *Response
- func (c *Client) Live(path string) *Live
- func (c *Client) Post(path string, form url.Values) *Response
- func (c *Client) PostRaw(path string, form url.Values) *Response
- func (c *Client) URL() string
- type Frame
- type LeakOption
- type LeakReport
- type Live
- func (l *Live) AwaitEvent(name string, d time.Duration) (payload json.RawMessage, ok bool)
- func (l *Live) Click(handler string) Frame
- func (l *Live) HandlerRef(event string, n int) string
- func (l *Live) Push(name string, payload any) Frame
- func (l *Live) Put(path, contentType string, body []byte) *Response
- func (l *Live) Submit(handler string, form map[string]string) Frame
- type Response
Constants ¶
const UserHeader = "X-Admintest-User"
UserHeader carries the user ID that Auth authenticates.
Variables ¶
This section is empty.
Functions ¶
func Auth ¶
func Auth() auth.Authenticator
Auth returns an authenticator that trusts UserHeader. Use it in tests only.
func StateStoreSuite ¶
StateStoreSuite checks a StateStore against the contract admin relies on. newStore returns an empty store for each subtest.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an HTTP client for one test server with a cookie jar.
func (*Client) CSRFToken ¶
CSRFToken returns the token from the CSRF cookie the panel set for path, or "".
func (*Client) Live ¶
Live opens the Live page at path and joins its session. It fails the test unless the page answers 200 with a Live root.
func (*Client) Post ¶
Post submits form to path with the CSRF token, fetching a page first when the jar has no CSRF cookie yet.
type Frame ¶
type Frame struct {
Raw string
Err map[string]string
Redirect string
Events map[string]json.RawMessage
}
Frame is the server's answer to one event.
type LeakOption ¶
type LeakOption func(*leakConfig)
LeakOption configures LeakScan.
func MaxPages ¶
func MaxPages(n int) LeakOption
MaxPages caps the pages crawled per user. Default 400.
func Probe ¶
func Probe(paths ...string) LeakOption
Probe adds paths every user is sent to directly, such as another tenant's records or exports. A 403 or 404 is fine; a sentinel in the answer is not.
func Searches ¶
func Searches(terms ...string) LeakOption
Searches adds terms typed into every index search and the Cmd+K palette. LeakScan always searches the first half of each sentinel, so a match shows the full value only if the row holding it was found.
type LeakReport ¶
type LeakReport struct {
Pages, LiveViews, Searches, Exports, Relations, Probes int
}
LeakReport counts what one scan exercised, so a test can check the scan reached the screens it means to cover.
func LeakScan ¶
func LeakScan(t testing.TB, c *Client, prefix string, users []string, sentinels []string, opts ...LeakOption) LeakReport
LeakScan proves that what users must not see never reaches them. It signs in as each user and crawls every page of the panel under prefix reachable from its home: it follows links (record pages and CSV exports included), joins every Live view over the SSE+POST transport, lists 100 rows per index page and follows those rows too, opens every relation tab, searches every index and the Cmd+K palette, and sends the probe paths. It fails t when any sentinel appears in a page, a Live frame, a CSV, a JSON answer, or a toast, in plain, HTML-escaped, or JSON-escaped form.
type Live ¶
type Live struct {
// HTML is the dead render.
HTML string
// Frames holds every frame received, in order.
Frames []string
// contains filtered or unexported fields
}
Live is a Live page joined the way the browser runtime joins an admin panel: an SSE stream for the server's frames and a POST, carrying the page's CSRF token, for each event.
func (*Live) AwaitEvent ¶
AwaitEvent returns the payload of the next pushed event called name that the test has not awaited yet, such as the toast of a queued run that finished on a worker, waiting up to d for it. ok is false on timeout.
func (*Live) HandlerRef ¶
HandlerRef returns the n-th (from 0) data-f-<event> handler reference in the page's first render, such as HandlerRef("submit", 0). It fails the test when there is none.
func (*Live) Push ¶
Push sends a named event to the view's HandleEvent and returns the server's answer: its diff or error frame, a following redirect, and the events the view pushed.