🤖 handofftest
amadan.net/rastrillo/rastrillo/handoff/handofftest
Use handofftest as a fake root app in your tests. This saves you from signing tokens by hand.
func New(t testing.TB) *Root
type Root struct {
Origin string
Key *crypto.Keypair
KeyID string
Now func() time.Time
}
func (r *Root) Setup() instance.Setup
func (r *Root) Assert(t testing.TB, enter *http.Response, subject string) url.Values
func (r *Root) AssertAt(t testing.TB, enter *http.Response, subject string,
authTime time.Time) url.Values
func (r *Root) Roster(t testing.TB, audience string, sequence int64,
state roster.State, members ...roster.Member) string
func (r *Root) RosterOrigin(t testing.TB, audience string, sequence int64,
state roster.State, origin string, members ...roster.Member) string
func (r *Root) RosterPlan(t testing.TB, audience string, sequence int64,
state roster.State, plan string, lapsedAt, until time.Time,
members ...roster.Member) string
func (r *Root) GrantToken(t testing.TB, claims granttoken.Claims) string
func (r *Root) Call(t testing.TB, method, target string, body []byte) *http.Request
New makes a root at https://root.test with a fresh key, k1. Pass Setup to handoff and roster to configure an instance for this root. Use it in place of instance.FromEnv.
Assert responds to the redirect from the instance's Enter handler as the root would for a signed-in subject. Pass Assert the response from Enter. Then POST its form to handoff.EnterPath with the nonce cookie set by Enter. AssertAt is Assert for a person who signed in at the root at authTime. The assertion's auth_time is authTime. AssertAt ignores max_age, as a root that does not honour it would, so you can test how your app handles an old sign-in. authTime must not be after the root's Now. Assert is AssertAt with Now. Roster signs a snapshot for one instance, ready to POST to roster.Path. RosterOrigin signs one that also carries the account's custom origin, such as https://blog.example.org. The audience is still the instance's platform host. RosterPlan signs a snapshot with the account's plan, when it last stopped holding a paid plan, and when the plan stops granting. Pass a zero lapsedAt when the account never lapsed or holds a paid plan again, and a zero until when the plan has no deadline.
GrantToken signs a granttoken as this root. It fills Version, Issuer, KeyID and IssuedAt, and sets ExpiresAt to an hour from now when you leave it zero. You choose the rest.
Call signs a rootcall request to target, an https:// URL on the instance's platform host. It returns the request as the instance's server reads it. Pass it to the handler behind Guard.Wrap. Each request can be served once.
Assert, the Roster methods and Call sign tokens with a 60-second lifetime. Set Now to the clock used by the instance under test, or its clock may reject those tokens.
Read this page as markdown — exact, unstyled, and cheap for an agent to fetch.