-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathencryption_config_test.go
77 lines (61 loc) · 2.25 KB
/
encryption_config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package encryption_test
import (
"code.cloudfoundry.org/bbs/encryption"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Encryption Flags", func() {
var encryptionConfig encryption.EncryptionConfig
JustBeforeEach(func() {
encryptionConfig = encryption.EncryptionConfig{
EncryptionKeys: map[string]string{},
}
})
Describe("Validate", func() {
It("ensures there's at least one encryption key", func() {
encryptionConfig.ActiveKeyLabel = "label"
_, _, err := encryptionConfig.Parse()
Expect(err).To(HaveOccurred())
})
It("parses keys properly", func() {
encryptionConfig.ActiveKeyLabel = "label"
encryptionConfig.EncryptionKeys["label"] = "key"
key, keys, err := encryptionConfig.Parse()
Expect(err).ToNot(HaveOccurred())
km, err := encryption.NewKeyManager(key, keys)
Expect(err).ToNot(HaveOccurred())
Expect(km.EncryptionKey().Label()).To(Equal("label"))
})
It("ensures there's a selected active key", func() {
encryptionConfig.EncryptionKeys["label"] = "key"
_, _, err := encryptionConfig.Parse()
Expect(err).To(MatchError("Must select an active encryption key"))
})
It("fails if the active key is not on the list", func() {
encryptionConfig.ActiveKeyLabel = "other-label"
_, _, err := encryptionConfig.Parse()
Expect(err).To(MatchError("Must have at least one encryption key set"))
})
It("fails if creating a key fails to parse", func() {
encryptionConfig.ActiveKeyLabel = "label"
encryptionConfig.EncryptionKeys["label"] = "key"
encryptionConfig.EncryptionKeys[""] = "invalid"
_, _, err := encryptionConfig.Parse()
Expect(err).To(MatchError("A key label is required"))
})
It("returns an active key and all the keys", func() {
encryptionConfig.ActiveKeyLabel = "label"
encryptionConfig.EncryptionKeys["label"] = "key"
encryptionConfig.EncryptionKeys["old-label"] = "old-key"
activeKey, keys, err := encryptionConfig.Parse()
keyLabels := make([]string, len(keys))
for _, key := range keys {
keyLabels = append(keyLabels, key.Label())
}
Expect(err).NotTo(HaveOccurred())
Expect(activeKey.Label()).To(Equal("label"))
Expect(keyLabels).To(ContainElement("label"))
Expect(keyLabels).To(ContainElement("old-label"))
})
})
})