carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package fencerelease
2
3import "testing"
4
5func TestTokenScopeAndSingleUse(t *testing.T) {
6 for _, mode := range []string{"ok", "host", "incarnation", "generation", "operation", "rollback", "target", "zero", "revoked"} {
7 t.Run(mode, func(t *testing.T) {
8 token := New("host", "inc", 7, "op", "rb", "target")
9 host, inc, op, rb, target := "host", "inc", "op", "rb", "target"
10 gen := uint64(7)
11 switch mode {
12 case "host":
13 host = "other"
14 case "incarnation":
15 inc = "other"
16 case "generation":
17 gen++
18 case "operation":
19 op = "other"
20 case "rollback":
21 rb = "other"
22 case "target":
23 target = "other"
24 case "zero":
25 token = Token{}
26 case "revoked":
27 token.Revoke()
28 }
29 if token.Consume(host, inc, gen, op, rb, target) != (mode == "ok") {
30 t.Fatal("wrong token scope")
31 }
32 if mode == "ok" && token.Consume(host, inc, gen, op, rb, target) {
33 t.Fatal("reused token")
34 }
35 })
36 }
37}
38