Debian Codegraph @

persist/null_test.go

raw symbols SCIP
1 package persist
2
3 import (
4 "testing"
5
6 "github.com/cloudflare/redoctober/config"
7 "github.com/cloudflare/redoctober/passvault"
8 )
9
10 func TestNewNull(t *testing.T) {
11 cfg := &config.Delegations{
12 Persist: false,
13 Mechanism: FileMechanism,
14 Location: "testdata/store.bin",
15 Policy: "policy",
16 }
17
18 store, err := New(cfg)
19 if err != nil {
20 t.Fatalf("persist: failed to create a new store: %s", err)
21 }
22
23 if _, ok := store.(*Null); !ok {
24 t.Fatalf("persist: expected a Null store, but have %T", store)
25 }
26
27 if store.Blob() != nil {
28 t.Fatalf("persist: Null store should return an empty blob")
29 }
30
31 if store.Policy() != cfg.Policy {
32 t.Fatalf("persist: expected a consistent policy")
33 }
34
35 if err := store.Store([]byte("test data")); err != nil {
36 t.Fatalf("persist: Null.Store failed with %s", err)
37 }
38
39 if err := store.Load(); err != nil {
40 t.Fatalf("persist: Null.Load failed with %s", err)
41 }
42
43 status := store.Status()
44 if status.State != Disabled {
45 t.Fatalf("persist: Null store should never persist")
46 }
47
48 if len(status.Summary) != 0 {
49 t.Fatal("persist: Null summary should have zero entries")
50 }
51
52 err = store.Delegate(passvault.PasswordRecord{}, "name", "password", []string{}, []string{}, 1, "", "1h")
53 if err == nil {
54 t.Fatal("persist: expected delegation to fail")
55 }
56
57 if cache := store.Cache(); len(cache.UserKeys) != 0 {
58 t.Fatal("persist: Null Cache() should return an empty cache")
59 }
60
61 if store.Purge() != nil {
62 t.Fatal("persist: Null Purge() shouldn't return an error")
63 }
64 }