oficina / docs Public

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

Plain git — no account needed to clone.

Download

Download this file

1package docs
2
3import (
4 "bytes"
5 "context"
6 "encoding/base64"
7 "net/http/httptest"
8 "strings"
9 "testing"
10 "time"
11)
12
13func TestTeamImportFormAndRefusalRender(t *testing.T) {
14 f := newTeamRouterFixture(t)
15 b := f.browser()
16 b.localSignin(t, "alice@example.com")
17 b.linkProof(t, teamSubject('a'), "alice@example.com")
18 routerRedirect(t, b.do("POST", "/account/home/confirm", ""), connectedURL("/"))
19 // These requests only render a form; no content is written.
20 var err error
21 f.app.store.content, err = newContentCipher(base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{73}, 32)), "production")
22 if err != nil {
23 t.Fatal(err)
24 }
25 for _, tc := range []struct {
26 method string
27 want int
28 }{{"GET", 200}, {"POST", 400}} {
29 r := b.do(tc.method, "/import", "")
30 if r.Code != tc.want || !strings.Contains(r.Body.String(), "docs-import-form") {
31 t.Errorf("%s import: status %d, want %d with import form", tc.method, r.Code, tc.want)
32 }
33 }
34}
35
36func TestTeamImportFormRefusesExpiredMembershipAtEmission(t *testing.T) {
37 app, _ := sealedApp(t, Config{})
38 owner := app.TestPerson(t, "owner@example.com")
39 rt, clock, subject := testTeamRoster(t, app.store, app)
40 ctx := t.Context()
41 access := rt.resolveAccess(ctx, requestIdentity{Actor: localActor(owner, "owner@example.com"), HomeSubject: subject})
42 ctx = context.WithValue(ctx, accessContextKey{}, access)
43 r := httptest.NewRequest("GET", "https://docs.example/import", nil).WithContext(ctx)
44 p := app.handlers.importView(r, "test-token", "")
45 clock.step(60 * time.Second)
46 w := &teamDeadlineRecorder{ResponseRecorder: httptest.NewRecorder()}
47 app.handlers.renderImport(w, r, p, 0)
48 if w.Code != 503 || strings.Contains(w.Body.String(), "docs-import-form") {
49 t.Fatalf("expired member received import form: status %d", w.Code)
50 }
51}
52