|
1
|
package api |
|
2
|
|
|
3
|
import ( |
|
4
|
"path/filepath" |
|
5
|
"testing" |
|
6
|
) |
|
7
|
|
|
8
|
func TestNewPolicyStoreDefaultsBridgeTTL(t *testing.T) { |
|
9
|
ps, err := NewPolicyStore(filepath.Join(t.TempDir(), "policies.json"), 5) |
|
10
|
if err != nil { |
|
11
|
t.Fatalf("NewPolicyStore() error = %v", err) |
|
12
|
} |
|
13
|
|
|
14
|
got := ps.Get().Bridge.WebUserTTLMinutes |
|
15
|
if got != 5 { |
|
16
|
t.Fatalf("default bridge ttl = %d, want 5", got) |
|
17
|
} |
|
18
|
} |
|
19
|
|
|
20
|
func TestPolicyStoreSetNormalizesBridgeTTL(t *testing.T) { |
|
21
|
ps, err := NewPolicyStore(filepath.Join(t.TempDir(), "policies.json"), 5) |
|
22
|
if err != nil { |
|
23
|
t.Fatalf("NewPolicyStore() error = %v", err) |
|
24
|
} |
|
25
|
|
|
26
|
p := ps.Get() |
|
27
|
p.Bridge.WebUserTTLMinutes = 0 |
|
28
|
if err := ps.Set(p); err != nil { |
|
29
|
t.Fatalf("Set() error = %v", err) |
|
30
|
} |
|
31
|
|
|
32
|
got := ps.Get().Bridge.WebUserTTLMinutes |
|
33
|
if got != 5 { |
|
34
|
t.Fatalf("normalized bridge ttl = %d, want 5", got) |
|
35
|
} |
|
36
|
} |
|
37
|
|