| new file mode 100644 |
| index 0000000..665a792 |
| --- /dev/null |
| +++ b/internal/home/operator_ceremony_test.go |
| @@ -0,0 +1,438 @@ |
| +package home |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "encoding/base64" |
| + "net/http" |
| + "net/http/httptest" |
| + "net/url" |
| + "os" |
| + "regexp" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/home/internal/home/directorydata" |
| + "amadan.net/oficina/home/internal/home/sealtest" |
| + "amadan.net/oficina/home/internal/operator" |
| + "amadan.net/rastrillo/rastrillo/assertion" |
| + "amadan.net/rastrillo/rastrillo/migrate" |
| + "amadan.net/rastrillo/rastrillo/sessions" |
| + json "github.com/go-json-experiment/json" |
| + "github.com/keymaildev/signin" |
| +) |
| + |
| +func backdate(t *testing.T, a *App, column string, at time.Time) { |
| + t.Helper() |
| + if _, err := a.db.Writer().Exec("UPDATE sessions SET "+column+"=?", at.UTC().Format(time.RFC3339)); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +func (f *operatorFixture) submit(t *testing.T, role, kind string, apps []string) { |
| + t.Helper() |
| + if rec := f.post(role, operatorPlanPath, f.plan(t, role, kind, apps, nil), nil); rec.Code != 200 { |
| + t.Fatal(role, "plan", rec.Code, rec.Body.String()) |
| + } |
| +} |
| + |
| +func TestOperatorDirectoryConfirmCeremony(t *testing.T) { |
| + f := newOperatorFixture(t) |
| + f.submit(t, "directory", "create-team", []string{"docs", "sheets"}) |
| + // Signed out: the fresh-only start, back to this page. |
| + anon := exchangeRequest(f.directory, "GET", directoryOrigin+operatorConfirm, "", nil) |
| + if anon.Code != 303 || anon.Header().Get("Location") != freshStartPath+"?return_to=%2Foperator%2Fconfirm" { |
| + t.Fatal("anonymous confirm", anon.Code, anon.Header().Get("Location")) |
| + } |
| + cred := f.paulCredential(t) |
| + session := f.paulDirectory(t, cred) |
| + page := exchangeRequest(f.directory, "GET", directoryOrigin+operatorConfirm, "", nil, session) |
| + body := page.Body.String() |
| + if page.Code != 200 || !strings.Contains(body, operatorName) || !strings.Contains(body, operatorLabel+".docs.oficina.works") || !strings.Contains(body, operatorLabel+".sheets.oficina.works") || !strings.Contains(body, "5a5a5a5a") { |
| + t.Fatal("directory page does not show Home's copy", page.Code) |
| + } |
| + // A plan id other than the pending one is refused at confirm. |
| + wrong := exchangeRequest(f.directory, "POST", directoryOrigin+operatorConfirm, directoryOrigin, url.Values{"plan": {fixtureToken(91)}}, session) |
| + if wrong.Code != 403 || f.openCount(t, f.directory) != 0 { |
| + t.Fatal("other plan id opened", wrong.Code) |
| + } |
| + // Stale and future auth_time: back through the fresh exchange. |
| + for _, at := range []time.Time{time.Now().Add(-301 * time.Second), time.Now().Add(time.Hour)} { |
| + backdate(t, f.directory, "auth_time", at) |
| + r := exchangeRequest(f.directory, "GET", directoryOrigin+operatorConfirm, "", nil, session) |
| + if r.Code != 303 || !strings.HasPrefix(r.Header().Get("Location"), freshStartPath) { |
| + t.Fatal("stale/future directory session admitted", r.Code) |
| + } |
| + post := exchangeRequest(f.directory, "POST", directoryOrigin+operatorConfirm, directoryOrigin, url.Values{"plan": {fixtureToken(90)}}, session) |
| + if post.Code != 303 || f.openCount(t, f.directory) != 0 { |
| + t.Fatal("stale POST opened", post.Code) |
| + } |
| + } |
| + session = f.paulDirectory(t, f.paulCredential(t)) |
| + if rec := f.confirm(t, "directory", session, ""); rec.Code != 200 || f.openCount(t, f.directory) != 1 { |
| + t.Fatal("confirm", rec.Code) |
| + } |
| + // After plan expiry nothing opens. |
| + f.expireWindows(t) |
| + f.submit(t, "directory", "add-apps", []string{"docs"}) |
| + f.directory.op.now = func() time.Time { return time.Now().Add(601 * time.Second) } |
| + post := exchangeRequest(f.directory, "POST", directoryOrigin+operatorConfirm, directoryOrigin, url.Values{"plan": {fixtureToken(90)}}, session) |
| + if post.Code != 403 || f.openCount(t, f.directory) != 0 || f.countRows(t, f.directory, "operator_plans") != 0 { |
| + t.Fatal("expired plan opened or lingered", post.Code) |
| + } |
| +} |
| + |
| +func (f *operatorFixture) openCount(t *testing.T, a *App) int { |
| + t.Helper() |
| + var n int |
| + if err := a.db.Writer().QueryRow("SELECT count(*) FROM operator_plans WHERE state='open'").Scan(&n); err != nil { |
| + t.Fatal(err) |
| + } |
| + return n |
| +} |
| + |
| +func TestOperatorConfirmRefusesAnotherSubjectWith404(t *testing.T) { |
| + f := newOperatorFixture(t) |
| + f.submit(t, "directory", "add-apps", []string{"docs"}) |
| + f.submit(t, "credential", "add-apps", []string{"docs"}) |
| + stranger := signInFully(t, f.credential, "stranger@example.invalid") |
| + if r := exchangeRequest(f.credential.App, "GET", Origin+operatorConfirm, "", nil, stranger); r.Code != 404 { |
| + t.Fatal("credential confirm for a non-operator", r.Code) |
| + } |
| + if r := exchangeRequest(f.credential.App, "POST", Origin+operatorConfirm, Origin, url.Values{"plan": {fixtureToken(90)}}, stranger); r.Code != 404 { |
| + t.Fatal("credential confirm POST for a non-operator", r.Code) |
| + } |
| + session := f.paulDirectory(t, stranger) |
| + if r := exchangeRequest(f.directory, "GET", directoryOrigin+operatorConfirm, "", nil, session); r.Code != 404 { |
| + t.Fatal("directory confirm for a non-operator", r.Code) |
| + } |
| + if f.openCount(t, f.directory)+f.openCount(t, f.credential.App) != 0 { |
| + t.Fatal("window opened") |
| + } |
| +} |
| + |
| +func TestOperatorCredentialConfirmCeremony(t *testing.T) { |
| + f := newOperatorFixture(t) |
| + signInFully(t, f.credential, sealtest.CanaryAddress) |
| + f.submit(t, "credential", "create-team", []string{"docs"}) |
| + paul := f.paulCredential(t) |
| + page := exchangeRequest(f.credential.App, "GET", Origin+operatorConfirm, "", nil, paul) |
| + if page.Code != 200 || !strings.Contains(page.Body.String(), "Type the owner’s email to confirm") || !strings.Contains(page.Body.String(), "5a5a5a5a") || !strings.Contains(page.Body.String(), "Docs") { |
| + t.Fatal("credential page", page.Code) |
| + } |
| + // A mistyped owner opens nothing. |
| + m := planIDField.FindStringSubmatch(page.Body.String()) |
| + for _, typed := range []string{"", "someone-else@example.invalid", "canary-8f3a@example.invalid.x"} { |
| + r := exchangeRequest(f.credential.App, "POST", Origin+operatorConfirm, Origin, url.Values{"plan": {m[1]}, "owner": {typed}}, paul) |
| + if r.Code != 403 || f.openCount(t, f.credential.App) != 0 || (typed != "" && strings.Contains(r.Body.String(), typed)) { |
| + t.Fatal("mistyped owner", typed, r.Code) |
| + } |
| + } |
| + // Case and surrounding space are the blind index's own normalisation. |
| + if r := exchangeRequest(f.credential.App, "POST", Origin+operatorConfirm, Origin, url.Values{"plan": {m[1]}, "owner": {" " + strings.ToUpper(sealtest.CanaryAddress) + " "}}, paul); r.Code != 200 || f.openCount(t, f.credential.App) != 1 { |
| + t.Fatal("typed owner refused", r.Code) |
| + } |
| +} |
| + |
| +func TestOperatorCredentialConfirmStaleSessionGetsAFreshIntentAndNoLoop(t *testing.T) { |
| + f := newOperatorFixture(t) |
| + f.submit(t, "credential", "add-apps", []string{"docs"}) |
| + paul := f.paulCredential(t) |
| + backdate(t, f.credential.App, "created_at", time.Now().Add(-time.Hour)) |
| + stale := exchangeRequest(f.credential.App, "GET", Origin+operatorConfirm, "", nil, paul) |
| + if stale.Code != 303 || stale.Header().Get("Location") != "/signin?return_to=%2Foperator%2Fconfirm" { |
| + t.Fatal("stale session", stale.Code, stale.Header().Get("Location")) |
| + } |
| + intent := namedCookie(t, stale, assertionIntentCookie) |
| + read, ok := f.credential.readAssertionIntent(&http.Request{Header: http.Header{"Cookie": {intent.String()}}}, time.Now()) |
| + if !ok || read.Consumer != operatorConfirmConsumer || read.MaxAge != 300 || read.Subject != f.paul { |
| + t.Fatal("fresh intent shape", read) |
| + } |
| + // The reserved consumer can never reach an assertion. |
| + if r := exchangeRequest(f.credential.App, "GET", Origin+"/authorize/resume", "", nil, intent, f.paulCredential(t)); r.Code == 200 || strings.Contains(r.Body.String(), `name="assertion"`) { |
| + t.Fatal("reserved consumer minted an assertion", r.Code) |
| + } |
| + // A Keymail identity is sent to the email link, not a no-gesture loop. |
| + form := exchangeRequest(f.credential.App, "GET", Origin+stale.Header().Get("Location"), "", nil, intent, paul) |
| + navigation := namedCookie(t, form, returnCookie) |
| + f.credential.flow.Classifier = &signin.Classifier{HTTP: &http.Client{Timeout: classifierTimeout}} |
| + newKeymailStub(t, f.credential, f.paulAddress) |
| + begin := exchangeRequest(f.credential.App, "POST", Origin+"/signin", Origin, url.Values{"address": {f.paulAddress}}, intent, paul, navigation) |
| + if begin.Code != 303 || begin.Header().Get("Location") != "/signin/sent" { |
| + t.Fatal("forced sign-in did not take the email link", begin.Code, begin.Header().Get("Location")) |
| + } |
| + verified := exchangeRequest(f.credential.App, "POST", Origin+linkPath, Origin, url.Values{"token": {capturedLink(t, f.credential)}}, intent, paul, navigation) |
| + if verified.Code != 303 || verified.Header().Get("Location") != operatorConfirm { |
| + t.Fatal("sign-in lost the confirm page", verified.Code, verified.Header().Get("Location")) |
| + } |
| + fresh := sessionCookie(verified) |
| + back := exchangeRequest(f.credential.App, "GET", Origin+operatorConfirm, "", nil, intent, fresh) |
| + if back.Code != 200 { |
| + t.Fatal("returned fresh session refused", back.Code) |
| + } |
| + if c := back.Result().Cookies(); len(c) != 1 || c[0].Name != assertionIntentCookie || c[0].MaxAge >= 0 { |
| + t.Fatal("intent not consumed", c) |
| + } |
| + m := planIDField.FindStringSubmatch(back.Body.String()) |
| + opened := exchangeRequest(f.credential.App, "POST", Origin+operatorConfirm, Origin, url.Values{"plan": {m[1]}}, intent, fresh) |
| + if opened.Code != 200 || f.openCount(t, f.credential.App) != 1 { |
| + t.Fatal("confirm", opened.Code) |
| + } |
| + if c := opened.Result().Cookies(); len(c) != 1 || c[0].Name != assertionIntentCookie || c[0].MaxAge >= 0 { |
| + t.Fatal("intent cookie not cleared after confirm", c) |
| + } |
| +} |
| + |
| +func TestOperatorCredentialConfirmRefusesKeymailWithoutGestureAndRecovery(t *testing.T) { |
| + f := newOperatorFixture(t) |
| + f.submit(t, "credential", "add-apps", []string{"docs"}) |
| + for _, method := range []string{string(signin.MethodKeymail), "magiclink+recovery", "keymail+recovery"} { |
| + token, err := f.credential.sessions.Mint(sessionWith(f.paul, method)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + cookie := &http.Cookie{Name: f.credential.sessions.CookieName(), Value: token} |
| + if r := exchangeRequest(f.credential.App, "GET", Origin+operatorConfirm, "", nil, cookie); r.Code != 303 || !strings.HasPrefix(r.Header().Get("Location"), "/signin") { |
| + t.Fatal(method, "admitted", r.Code) |
| + } |
| + if r := exchangeRequest(f.credential.App, "POST", Origin+operatorConfirm, Origin, url.Values{"plan": {fixtureToken(90)}}, cookie); r.Code != 303 || f.openCount(t, f.credential.App) != 0 { |
| + t.Fatal(method, "opened", r.Code) |
| + } |
| + } |
| +} |
| + |
| +func TestOperatorFreshIntentWithInvalidNonceIsIgnored(t *testing.T) { |
| + f := newOperatorFixture(t) |
| + b, _ := json.Marshal(assertionIntent{Consumer: operatorConfirmConsumer, Nonce: "not-a-nonce", Expires: time.Now().Unix() + 600, MaxAge: 300, Subject: f.paul}) |
| + sealed, _ := f.credential.secrets.Sealer.Seal("assertion.intent", b) |
| + bad := &http.Cookie{Name: assertionIntentCookie, Value: base64.RawURLEncoding.EncodeToString(sealed)} |
| + if _, ok := f.credential.readAssertionIntent(&http.Request{Header: http.Header{"Cookie": {bad.String()}}}, time.Now()); ok { |
| + t.Fatal("invalid nonce read as an intent") |
| + } |
| + // A plain sign-in, then the page: no loop. |
| + f.submit(t, "credential", "add-apps", []string{"docs"}) |
| + signIn(t, f.credential, f.paulAddress) |
| + verified := redeem(t, f.credential, capturedLink(t, f.credential)) |
| + if r := exchangeRequest(f.credential.App, "GET", Origin+operatorConfirm, "", nil, bad, sessionCookie(verified)); r.Code != 200 { |
| + t.Fatal("fresh session with a junk intent refused", r.Code) |
| + } |
| +} |
| + |
| +// Gate 5: the credential origin renders no account-authored string. The |
| +// plan's label and team name live only on the directory; the owner's |
| +// address is never echoed, typed or not. |
| +func TestOperatorCredentialConfirmRendersNoAccountAuthoredString(t *testing.T) { |
| + f := newOperatorFixture(t) |
| + signInFully(t, f.credential, sealtest.CanaryAddress) |
| + f.provisionTeam(t) |
| + f.expireWindows(t) |
| + f.submit(t, "directory", "create-team", []string{"docs"}) |
| + f.submit(t, "credential", "create-team", []string{"docs", "sheets"}) |
| + paul := f.paulCredential(t) |
| + page := exchangeRequest(f.credential.App, "GET", Origin+operatorConfirm, "", nil, paul) |
| + m := planIDField.FindStringSubmatch(page.Body.String()) |
| + wrong := exchangeRequest(f.credential.App, "POST", Origin+operatorConfirm, Origin, url.Values{"plan": {m[1]}, "owner": {"typed-canary@example.invalid"}}, paul) |
| + right := exchangeRequest(f.credential.App, "POST", Origin+operatorConfirm, Origin, url.Values{"plan": {m[1]}, "owner": {sealtest.CanaryAddress}}, paul) |
| + for _, r := range []string{page.Body.String(), wrong.Body.String(), right.Body.String()} { |
| + for _, canary := range []string{operatorLabel, operatorName, sealtest.CanaryAddress, "typed-canary", "blue.docs"} { |
| + if strings.Contains(strings.ToLower(r), strings.ToLower(canary)) { |
| + t.Fatalf("credential confirm rendered %q", canary) |
| + } |
| + } |
| + } |
| +} |
| + |
| +func sessionWith(subject, method string) sessions.Session { |
| + return sessions.Session{Subject: subject, Method: method, At: time.Now()} |
| +} |
| + |
| +func TestOperatorEndToEndProvisioningAndRegistry(t *testing.T) { |
| + f := newOperatorFixture(t) |
| + signInFully(t, f.credential, sealtest.CanaryAddress) |
| + f.provisionTeam(t) |
| + // The registered consumer is in the union at once: /authorize admits it. |
| + nonce, _ := assertion.RandomID() |
| + consumer := operatorLabel + "-docs" |
| + authorize := exchangeRequest(f.credential.App, "GET", Origin+"/authorize?consumer="+consumer+"&nonce="+nonce, "", nil) |
| + if authorize.Code != 303 { |
| + t.Fatal("registered consumer refused at /authorize", authorize.Code) |
| + } |
| + intent := namedCookie(t, authorize, assertionIntentCookie) |
| + session := signInFully(t, f.credential, sealtest.CanaryAddress) |
| + handoff := exchangeRequest(f.credential.App, "GET", Origin+"/authorize/resume", "", nil, intent, session) |
| + target := "https://" + operatorLabel + ".docs.oficina.works" |
| + csp := handoff.Header().Get("Content-Security-Policy") |
| + if handoff.Code != 200 || !strings.Contains(csp, "form-action 'self' "+target+" "+directoryOrigin+";") && !strings.HasSuffix(csp, "form-action 'self' "+target+" "+directoryOrigin) { |
| + t.Fatal("handoff CSP does not name exactly its consumer", handoff.Code, csp) |
| + } |
| + if strings.Contains(csp, "blue.docs") || strings.Contains(csp, "preview.example") { |
| + t.Fatal("handoff CSP names other consumers") |
| + } |
| + // The fence: a record for a pre-existing (not stream-seeded) team is |
| + // unobtainable. |
| + if _, err := f.directory.db.Writer().Exec("INSERT INTO teams(sqid,label,sealed_name,created_at) VALUES('gb','acme',zeroblob(40),1)"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := f.directory.db.Writer().Exec("INSERT INTO memberships(team_id,person_ref,role) VALUES(2,?,'owner')", f.paul); err != nil { |
| + t.Fatal(err) |
| + } |
| + f.expireWindows(t) |
| + f.submit(t, "directory", "add-apps", []string{"sheets"}) |
| + if rec := f.confirm(t, "directory", f.paulDirectory(t, f.paulCredential(t)), ""); rec.Code != 200 { |
| + t.Fatal(rec.Code) |
| + } |
| + if rec, _ := f.run(t, "directory", "directory.provision-consumer", func(b operator.InputBase) any { |
| + return operator.ProvisionInput{InputBase: b, Generation: generationToken(), TeamSQID: "gb", App: "sheets", Consumer: "acme-sheets", Audience: "https://acme.sheets.oficina.works"} |
| + }); rec.Code != 403 { |
| + t.Fatal("record for a pre-existing team", rec.Code) |
| + } |
| + // Retire: refused at /authorize and at sign-out afterwards. |
| + f.expireWindows(t) |
| + f.submit(t, "credential", "retire-apps", []string{"docs"}) |
| + paul := f.paulCredential(t) |
| + if rec := f.confirm(t, "credential", paul, ""); rec.Code != 200 { |
| + t.Fatal(rec.Code) |
| + } |
| + if rec, _ := f.run(t, "credential", "credential.retire-consumer", func(b operator.InputBase) any { |
| + return operator.RetireInput{InputBase: b, Consumer: consumer} |
| + }); rec.Code != 200 { |
| + t.Fatal("retire", rec.Code, rec.Body.String()) |
| + } |
| + if r := exchangeRequest(f.credential.App, "GET", Origin+"/authorize?consumer="+consumer+"&nonce="+nonce, "", nil); r.Code != 400 { |
| + t.Fatal("retired consumer admitted at /authorize", r.Code) |
| + } |
| + signout := exchangeRequest(f.credential.App, "POST", Origin+signoutPath, target, url.Values{}, session) |
| + if signout.Code != 403 { |
| + t.Fatal("retired consumer admitted at sign-out", signout.Code) |
| + } |
| +} |
| + |
| +func TestOperatorSignoutConfirmCSPNamesOneConsumer(t *testing.T) { |
| + f := newOperatorFixture(t) |
| + r := exchangeRequest(f.credential.App, "POST", Origin+signoutPath, "https://preview.example.test", url.Values{}) |
| + csp := r.Header().Get("Content-Security-Policy") |
| + if r.Code != 200 || csp != f.credential.securityPolicy("https://preview.example.test") || strings.Contains(csp, "blue.docs") { |
| + t.Fatal("signoutConfirm CSP", r.Code, csp) |
| + } |
| +} |
| + |
| +// Additive migrations: sessions, keys and team ciphertexts written before |
| +// them survive, and the previous binary's schema still applies after them. |
| +func TestOperatorHTTPMigrationsAreAdditive(t *testing.T) { |
| + p := newExchangePair(t) |
| + session := signInFully(t, p.credential, sealtest.CanaryAddress) |
| + if _, err := migrate.Apply(context.Background(), p.credential.db, (Runtime{role: "credential"}).ServingSchema()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := migrate.Apply(context.Background(), p.credential.db, migrate.Merge(BootSchema, operator.CredentialSchema)); err != nil { |
| + t.Fatal("old credential schema refused the new database", err) |
| + } |
| + if r := exchangeRequest(p.credential.App, "GET", Origin+"/passkey/enrol", "", nil, session); r.Code != 200 { |
| + t.Fatal("session lost across the migration", r.Code) |
| + } |
| + if _, err := p.directory.db.Writer().Exec("INSERT INTO teams(sqid,label,sealed_name,created_at) VALUES('Uk','alpha',?,1)", mustSealName(t, p.directory, 1, "Alpha")); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := migrate.Apply(context.Background(), p.directory.db, (Runtime{role: "directory"}).ServingSchema()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := migrate.Apply(context.Background(), p.directory.db, migrate.Merge(directorySchema, directorydata.OperatorSchema, operator.DirectorySchema)); err != nil { |
| + t.Fatal("old directory schema refused the new database", err) |
| + } |
| + var sealed []byte |
| + if err := p.directory.db.Writer().QueryRow("SELECT sealed_name FROM teams").Scan(&sealed); err != nil { |
| + t.Fatal(err) |
| + } |
| + if name, err := p.directory.secrets.Sealer.Open("directory.team-name/1", sealed); err != nil || string(name) != "Alpha" { |
| + t.Fatal("team ciphertext lost", err) |
| + } |
| +} |
| + |
| +func mustSealName(t *testing.T, a *App, id int64, name string) []byte { |
| + t.Helper() |
| + b, err := a.secrets.Sealer.Seal("directory.team-name/1", []byte(name)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return b |
| +} |
| + |
| +// Gate 1 and gate 9 over the whole sequence: plan, both confirms, every |
| +// verb, hostile refusals. No canary address, team name, label, plan bytes, |
| +// bearer or prefilter in either database (file, WAL, SHM) or any log line. |
| +func TestOperatorPrivacyGatesOverTheWholeSequence(t *testing.T) { |
| + f := newOperatorFixture(t) |
| + signInFully(t, f.credential, sealtest.CanaryAddress) |
| + records := f.provisionTeam(t) |
| + plan := f.plan(t, "credential", "create-team", []string{"docs"}, nil) |
| + // Hostile refusals carrying the canaries in their bodies. |
| + f.post("credential", operatorPlanPath, plan, func(r *http.Request) { r.Header.Set("Authorization", "Bearer "+fixtureToken(9)) }) |
| + f.post("credential", operatorPlanPath, plan, func(r *http.Request) { r.Header.Set("Origin", "https://"+operatorLabel+".docs.oficina.works") }) |
| + f.post("directory", operatorPath, []byte(`{"label":"`+operatorLabel+`","name":"`+operatorName+`","owner":"`+sealtest.CanaryAddress+`"}`), nil) |
| + f.post("credential", operatorPath, []byte(`{"owner":"`+sealtest.CanaryAddress+`"}`), nil) |
| + f.post("credential", operatorPlanPath, plan, nil) |
| + f.post("credential", operatorPlanPath, plan, nil) |
| + for _, path := range []string{f.credential.dbPath, f.directoryPath} { |
| + sealtest.AssertNoPlaintext(t, path) |
| + for _, suffix := range []string{"", "-wal", "-shm"} { |
| + b, _ := os.ReadFile(path + suffix) |
| + for _, secret := range [][]byte{plan[10:60], records["docs"][10:60], []byte(f.prefilter)} { |
| + if bytes.Contains(b, secret) { |
| + t.Fatal("private operator bytes at rest in", path+suffix) |
| + } |
| + } |
| + } |
| + } |
| + logs := f.logs.String() |
| + if !strings.Contains(logs, "operator http") { |
| + t.Fatal("captured no operator log lines; the gate would pass by not looking") |
| + } |
| + for _, canary := range []string{sealtest.CanaryAddress, operatorName, operatorLabel, f.prefilter, fixtureToken(90), string(plan[10:40])} { |
| + if strings.Contains(strings.ToLower(logs), strings.ToLower(canary)) { |
| + t.Fatalf("log line carries %q", canary) |
| + } |
| + } |
| + for _, line := range strings.Split(strings.TrimSpace(logs), "\n") { |
| + if strings.Contains(line, "operator") && !regexp.MustCompile(`msg="operator (http|confirm)"`).MatchString(line) { |
| + continue |
| + } |
| + if m := regexp.MustCompile(` op=(\S*)`).FindStringSubmatch(line); m != nil && len(m[1]) > 8 { |
| + t.Fatal("operation id logged past its prefix", line) |
| + } |
| + } |
| +} |
| + |
| +// Gate 10: every new route answers no-store, on both origins, whatever the |
| +// outcome. |
| +func TestOperatorRoutesAreNoStore(t *testing.T) { |
| + f := newOperatorFixture(t) |
| + f.submit(t, "directory", "add-apps", []string{"docs"}) |
| + f.submit(t, "credential", "add-apps", []string{"docs"}) |
| + paul := f.paulCredential(t) |
| + dir := f.paulDirectory(t, paul) |
| + stranger := signInFully(t, f.credential, "stranger@example.invalid") |
| + var recs []*httptest.ResponseRecorder |
| + for _, role := range []string{"credential", "directory"} { |
| + recs = append(recs, |
| + f.post(role, operatorPath, []byte("{}"), nil), |
| + f.post(role, operatorPlanPath, []byte("{}"), nil), |
| + f.post(role, operatorPlanPath, []byte("{}"), func(r *http.Request) { r.Header.Del("Authorization") }), |
| + f.post(role, operatorPath, []byte("{}"), func(r *http.Request) { r.Method = "GET" }), |
| + ) |
| + } |
| + recs = append(recs, |
| + exchangeRequest(f.credential.App, "GET", Origin+operatorConfirm, "", nil), |
| + exchangeRequest(f.credential.App, "GET", Origin+operatorConfirm, "", nil, paul), |
| + exchangeRequest(f.credential.App, "GET", Origin+operatorConfirm, "", nil, stranger), |
| + exchangeRequest(f.credential.App, "POST", Origin+operatorConfirm, Origin, url.Values{"plan": {"x"}}, paul), |
| + exchangeRequest(f.directory, "GET", directoryOrigin+operatorConfirm, "", nil), |
| + exchangeRequest(f.directory, "GET", directoryOrigin+operatorConfirm, "", nil, dir), |
| + exchangeRequest(f.directory, "POST", directoryOrigin+operatorConfirm, directoryOrigin, url.Values{"plan": {"x"}}, dir), |
| + ) |
| + for i, r := range recs { |
| + if r.Header().Get("Cache-Control") != "no-store" { |
| + t.Errorf("response %d (%d) is cacheable", i, r.Code) |
| + } |
| + } |
| +} |