-
Notifications
You must be signed in to change notification settings - Fork 16
/
utils_test.go
45 lines (40 loc) · 915 Bytes
/
utils_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
package main
import (
"io/ioutil"
"os"
"testing"
)
func TestDetectSopsFile(t *testing.T) {
tmp, err := ioutil.TempFile("", "utils_test.*.yaml")
if err != nil {
t.Errorf("Error creating temp file")
}
defer os.Remove(tmp.Name())
// Test negative case
tmp.WriteString(`---
secret: hello
`)
fileData, err := ReadAndUnmarshalYaml(tmp.Name())
res := DetectSopsKey(fileData)
if res != false || err != nil {
t.Errorf("DetectSopsYaml(tmp) = %t, %v; want false, <nil>", res, err)
}
// Test positive case
tmp.Seek(0, 0)
tmp.WriteString(`---
secret: ENC[AES256_GCM,...]
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
lastmodified: '2020-11-03T01:45:48Z'
pgp: []
version: 3.6.1
`)
fileData, err = ReadAndUnmarshalYaml(tmp.Name())
res = DetectSopsKey(fileData)
if res != true || err != nil {
t.Errorf("DetectSopsYaml(tmp) = %t, %v; want true, <nil>", res, err)
}
}