-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages_test.go
88 lines (77 loc) · 1.8 KB
/
messages_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
package gosettings
import (
"testing"
)
func Test_BoolToYesNo(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
b *bool
s string
}{
"nil": {},
"false": {
b: ptrTo(false),
s: "no",
},
"true": {
b: ptrTo(true),
s: "yes",
},
}
for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
s := BoolToYesNo(testCase.b)
if s != testCase.s {
t.Errorf("expected %s, got %s", testCase.s, s)
}
})
}
}
func Test_ObfuscateKey(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
key string
obfuscatedKey string
}{
"empty": {
obfuscatedKey: "[not set]",
},
"124_bits_security": {
// 16^31 gives 124 bits security hidden
key: "0123456789abcdef0123456789abcde",
obfuscatedKey: "[set]",
},
"128_bits_security": {
// 16^32 gives 128 bits security hidden
key: "0123456789abcdef0123456789abcdef",
obfuscatedKey: "[set]",
},
"132_bits_security": {
// 16^33 gives 128 bits security hidden + 1 shown character
key: "0123456789abcdef0123456789abcdef0",
obfuscatedKey: "[set]",
},
"136_bits_security": {
// 16^34 gives 128 bits security hidden + 2 shown characters
key: "0123456789abcdef0123456789abcdef01",
obfuscatedKey: "0...1",
},
"296_bits_security": {
// 52^52 combinations ~= 2^296
key: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
obfuscatedKey: "abc...789",
},
}
for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
obfuscatedKey := ObfuscateKey(testCase.key)
if obfuscatedKey != testCase.obfuscatedKey {
t.Errorf("expected %s, got %s", testCase.obfuscatedKey, obfuscatedKey)
}
})
}
}