Documentation
¶
Overview ¶
Package apitest is a fake Tailscale API for tests. It serves the OAuth token endpoint, requires the bearer token it issued, records every request, and answers registered routes. It contains no credential-shaped strings.
Index ¶
- Constants
- type Fake
- func (f *Fake) AcceptIDToken(tok string)
- func (f *Fake) Client(t testing.TB) *api.Client
- func (f *Fake) ExchangeRequests() int
- func (f *Fake) FailExchanges(statuses ...int)
- func (f *Fake) Fallback(h http.HandlerFunc)
- func (f *Fake) Handle(method, path string, h http.HandlerFunc)
- func (f *Fake) JSON(method, path string, status int, body string)
- func (f *Fake) Raw(method, path string, status int, body string, headers map[string]string)
- func (f *Fake) Requests() []Request
- func (f *Fake) TokenRequests() int
- func (f *Fake) URL() string
- type Request
Constants ¶
const ( ClientID = "test-client-id" ClientSecret = "test-client-secret" AccessToken = "test-access-token" Tailnet = "T1234CNTRL" // FedClientID is the federated identity the token-exchange route accepts. FedClientID = "test-fed-client-id" )
Fixed test identities. They are deliberately not shaped like real keys.
const ValidatePath = "/api/v2/tailnet/" + Tailnet + "/acl/validate"
ValidatePath is the only path tailkeeper may send a request other than GET to: policy validation, which never changes the policy.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fake ¶
type Fake struct {
Server *httptest.Server
// Scope is returned in the token response's "scope" field.
Scope string
// ExpiresIn is the token lifetime in seconds the OAuth token route grants; 0
// grants an hour.
ExpiresIn int
// NumberTokens makes the OAuth token route issue AccessToken-1, AccessToken-2,
// ... in turn; API routes then accept only the newest.
NumberTokens bool
// contains filtered or unexported fields
}
Fake is a running fake API server.
func (*Fake) AcceptIDToken ¶
AcceptIDToken makes the token-exchange route accept tok for FedClientID.
func (*Fake) Client ¶
Client returns an api.Client for the fake's tailnet using the fake OAuth client, with retries sleeping zero time.
func (*Fake) ExchangeRequests ¶
ExchangeRequests returns how many times the token-exchange endpoint was called.
func (*Fake) FailExchanges ¶
FailExchanges makes the next exchanges return these statuses, in order.
func (*Fake) Fallback ¶
func (f *Fake) Fallback(h http.HandlerFunc)
Fallback registers a handler for every path that has no route of its own. The request is recorded and its bearer token checked first, as for any other.
func (*Fake) Handle ¶
func (f *Fake) Handle(method, path string, h http.HandlerFunc)
Handle registers a handler for method and escaped path.
func (*Fake) Raw ¶
Raw registers a fixed response with any body (also empty) and extra headers, such as an ETag or a content type other than JSON.
func (*Fake) Requests ¶
Requests returns the API requests recorded so far (token requests excluded).
func (*Fake) TokenRequests ¶
TokenRequests returns how many times the token endpoint was called.