oficina / home Public

Clone
git clone https://amadan.net/oficina/home

Plain git — no account needed to clone.

Download

Download this file

1package home
2
3import (
4 "net/url"
5 "strings"
6 "testing"
7
8 "amadan.net/oficina/home/handoff"
9)
10
11// The directory mounts two consumers on one Store: the ordinary start asks
12// the credential origin for an assertion with no age bound, and the fresh
13// start (team-provisioning-amendment.md §4) asks for max_age=300.
14func TestDirectoryOrdinaryAndFreshStartPaths(t *testing.T) {
15 p := newExchangePair(t)
16 for _, c := range []struct {
17 path string
18 maxAge bool
19 }{{handoff.StartPath, false}, {freshStartPath, true}} {
20 r := exchangeRequest(p.directory, "GET", directoryOrigin+c.path+"?return_to=%2Foperator%2Fconfirm", "", nil)
21 if r.Code != 303 {
22 t.Fatal(c.path, r.Code)
23 }
24 u, err := url.Parse(r.Header().Get("Location"))
25 if err != nil || u.Scheme+"://"+u.Host != Origin || u.Path != "/authorize" {
26 t.Fatal(c.path, "redirected elsewhere", r.Header().Get("Location"))
27 }
28 q := u.Query()
29 if q.Get("consumer") != "directory" || !handoff.ValidNonce(q.Get("nonce")) {
30 t.Fatal(c.path, "authorize query", u.RawQuery)
31 }
32 if got := q["max_age"]; c.maxAge != (len(got) == 1 && got[0] == "300") || (!c.maxAge && len(got) != 0) {
33 t.Fatal(c.path, "max_age", got)
34 }
35 namedCookie(t, r, "__Host-oficina-assertion-pending")
36 }
37 // The fresh start answers only its own path; a typo is an ordinary 404.
38 if r := exchangeRequest(p.directory, "GET", directoryOrigin+"/auth/fresh/start/", "", nil); r.Code != 404 {
39 t.Fatal("near-miss fresh path served", r.Code)
40 }
41 if !strings.HasPrefix(freshStartPath, "/auth/") || p.directory.fresh.StartPath() != freshStartPath {
42 t.Fatal("fresh consumer mounted at an unexpected path")
43 }
44}
45