coverage~bigbes/sr-ht-spec64cae3afweb/tokens.go

Coverage
100.0% 4/4 statements
Δ
+0.0
Blob
e8b9f5a
Uncovered nothing — every instrumented line ran
1 package web
2
3 import (
4 "net/http"
5 )
6
7 // tokensPath is the page at tokens.sr.ht this service points a human at. SPEC
8 // ch. 7 pins it: the daemon serves one page, `/tokens`, behind the unified-login
9 // cookie, and "services со временем просто ссылаются сюда" — which is what this
10 // handler is.
11 const tokensPath = "/tokens"
12
13 // handleTokens sends a human to tokens.sr.ht.
14 //
15 // This route used to be spec's own agent-credential page: mint (shown once),
16 // list, revoke, all against the agent_token table. That table is gone and
17 // issuance is centralised, so what is left of the route is the one thing it can
18 // still honestly do — point at the place that issues the credential — and it is
19 // a redirect rather than a page of prose because an operator who typed /tokens
20 // wants the form, not an explanation of where the form moved to.
21 //
22 // No principal check. The old page was owner-only because it listed and minted
23 // credentials; a redirect exposes nothing but a public origin already in the
24 // nav, and tokens.sr.ht authenticates its own page against the same
25 // unified-login cookie this service reads. Sending an anonymous browser through
26 // meta's login first would only add a round trip to the same destination.
27 //
28 // A 303 rather than a 301: the destination of this route is an instance
29 // configuration value, and a permanent redirect is cached by browsers for far
30 // longer than a config key stays true.
31 3 func (s *Server) handleTokens(w http.ResponseWriter, r *http.Request) {
32 3 if s.tokensOrigin == "" {
33 1 // An instance with no [tokens.sr.ht] origin has no page to send anybody
34 1 // to, and inventing one would land the operator on a dead host. It is
35 1 // also not a state this daemon can serve agents in — service.New refuses
36 1 // to build the agent plane without that origin — so the page says what is
37 1 // actually wrong.
38 1 s.renderError(w, r, http.StatusServiceUnavailable,
39 1 "agent credentials are issued by tokens.sr.ht, and this instance's config.ini "+
40 1 "has no [tokens.sr.ht] origin")
41 1 return
42 1 }
43 2 http.Redirect(w, r, s.tokensOrigin+tokensPath, http.StatusSeeOther)
44 }