-
Notifications
You must be signed in to change notification settings - Fork 2
/
secret_test.go
109 lines (100 loc) · 2.1 KB
/
secret_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package multikey
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestEncodePEM(t *testing.T) {
// TODO
}
func TestDecodePEM(t *testing.T) {
// TODO
}
func TestEncodeSimple(t *testing.T) {
// TODO
}
func TestDecodeSimpleSecret(t *testing.T) {
tests := []struct {
testName string
toParse string
expectShards []*encryptedShard
expectErr bool
expectedErr string
}{
{
testName: "positive test",
toParse: "SOMEKEYID(SOMEVALUE)",
expectShards: []*encryptedShard{
{
KeyID: "SOMEKEYID",
Value: "SOMEVALUE",
},
},
expectErr: false,
},
{
testName: "negative test - bad format 1",
toParse: "SOMEKEYIDSOMEVALUE)",
expectErr: true,
expectedErr: errMsgInvalidSimpleFmt,
},
{
testName: "negative test - bad format 2",
toParse: "",
expectErr: true,
expectedErr: errMsgInvalidSimpleFmt,
},
{
testName: "negative test - bad format 3",
toParse: "SOMEKEY(",
expectErr: true,
expectedErr: errMsgInvalidSimpleFmt,
},
}
for _, test := range tests {
sec, err := decodeSimpleSecret(test.toParse)
if test.expectErr {
assert.Nil(t, sec, test.testName)
assert.EqualError(t, err, test.expectedErr, test.testName)
} else {
assert.EqualValues(t, sec.shards, test.expectShards, test.testName)
}
}
}
func TestEncodeDecodePEM(t *testing.T) {
tests := []struct {
testName string
testSecret *secret
expectErr bool
expectedError string
}{
{
testName: "positive test",
testSecret: &secret{
shards: []*encryptedShard{
{
KeyID: "some key id",
Value: "asdfghjkl",
},
{
KeyID: "some key id",
Value: "asdfghjkl",
},
},
},
expectErr: false,
},
}
for _, test := range tests {
enc, err := test.testSecret.encodePEM()
if test.expectErr {
assert.EqualError(t, err, test.expectedError, test.testName)
continue
}
dec, err := decodePEM(enc)
if test.expectErr {
assert.EqualError(t, err, test.expectedError, test.testName)
continue
}
assert.EqualValues(t, dec, test.testSecret, test.testName)
}
}