oficina / fichas Public

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

Plain git — no account needed to clone.

Download

Download this file

1package fichas
2
3import (
4 "net/http"
5 "testing"
6
7 "github.com/keymaildev/signin"
8)
9
10// The probe's verdicts. Any 5xx is undecided, which the door treats as
11// admitted: it never shows the refusal or ends a session because
12// something failed. Only the gate's own refusal (404) is a refusal.
13// Fichas' gate reads no store of its own (the owners list is config), so
14// this is the rule a future store read inherits, pinned here.
15func TestTheProbesVerdicts(t *testing.T) {
16 for _, c := range []struct {
17 reached bool
18 status int
19 signedIn, admitted bool
20 }{
21 {true, 0, true, true},
22 {false, http.StatusInternalServerError, true, true},
23 {false, http.StatusServiceUnavailable, true, true},
24 {false, http.StatusBadGateway, true, true},
25 {false, http.StatusNotFound, true, false},
26 {false, http.StatusSeeOther, false, false},
27 {false, http.StatusForbidden, false, false},
28 } {
29 got := probeVerdict(c.reached, c.status)
30 if got.signedIn != c.signedIn || got.admitted != c.admitted {
31 t.Errorf("reached %v, status %d: %+v, want signedIn %v admitted %v", c.reached, c.status, got, c.signedIn, c.admitted)
32 }
33 }
34}
35
36// The door judges the two web sign-ins and nothing else.
37func TestTheDoorJudgesOnlyWebSignins(t *testing.T) {
38 for method, want := range map[signin.Method]bool{
39 signin.MethodMagicLink: true,
40 signin.MethodKeymail: true,
41 "home-assertion": false,
42 "home-assertion-native": false,
43 "passkey": false,
44 "": false,
45 } {
46 if got := doorJudges(method); got != want {
47 t.Errorf("doorJudges(%q) = %v, want %v", method, got, want)
48 }
49 }
50}
51
52// What a fresh sign-in may land on.
53func TestKeepableReturn(t *testing.T) {
54 for to, want := range map[string]bool{
55 "/": true,
56 "/cards/new": true,
57 "/t/abc?sort=name": true,
58 "": false,
59 "cards": false,
60 "//evil.example/": false,
61 "/\\evil.example": false,
62 "https://evil.ex/": false,
63 "/signed-out": false,
64 "/signed-out?x=1": false,
65 "/signin": false,
66 "/signin?ways=1": false,
67 "/signin/forget": false,
68 "/auth/verify": false,
69 "/signed-outward": true,
70 "/signinsheet": true,
71 "/authors": true,
72 "/%zz": false,
73 // Dot segments and backslashes, as a browser resolves them
74 // (Fable on fichas #9).
75 "/./signed-out": false,
76 "/x/../signed-out": false,
77 "/x/../signed-out?a=1": false,
78 "/x/./../signed-out/": false,
79 "/%2e/signed-out": false,
80 "/x/%2e%2e/signed-out": false,
81 "/x\\..\\signed-out": false,
82 "/./signin": false,
83 "/x/../signin/forget": false,
84 "/cards/../signin?ways=1": false,
85 "/./auth/verify": false,
86 "/x/../auth/callback": false,
87 "/x/../auth": false,
88 "/cards/./new": true,
89 "/t/x/../t_customer": true,
90 "/x/../cards/new": true,
91 "javascript:alert1": false,
92 } {
93 if got := keepableReturn(to); got != want {
94 t.Errorf("keepableReturn(%q) = %v, want %v", to, got, want)
95 }
96 }
97}
98