-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_test.go
121 lines (115 loc) · 2.77 KB
/
generate_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
110
111
112
113
114
115
116
117
118
119
120
121
package main
import "testing"
func TestHasSSHRemoteBaseURL(t *testing.T) {
type args struct {
cwd string
}
tests := []struct {
name string
args args
want bool
wantErr bool
}{
{"with remote base", args{"./testData/app-with-remote-base"}, true, false},
{"without remote base", args{"./testData/app-with-secrets"}, false, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
files, err := findKustomizeFiles(tt.args.cwd)
if err != nil {
t.Fatal(err)
}
got, err := hasSSHRemoteBaseURL(files)
if (err != nil) != tt.wantErr {
t.Errorf("hasSSHRemoteBaseURL() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("hasSSHRemoteBaseURL() = %v, want %v", got, tt.want)
}
})
}
}
func TestCiphertextSecrets(t *testing.T) {
t.Run("Error on STRONGBOX header in Secret data", func(t *testing.T) {
yamlData := `
apiVersion: v1
kind: ServiceAccount
metadata:
name: test
---
apiVersion: v1
kind: Secret
metadata:
name: my-secret
data:
key1: |
c2VjcmV0ZGF0YQ==
key2: |
IyBTVFJPTkdCT1ggRU5DUllQVEVEIFJFU09VUkNFIDsgU2VlIGh0dHBzOi8vZ2l0aHViLmNvbS91
dy1sYWJzL3N0cm9uZ2JveApiZlY0ZWZnVjNwTVVJUmRwV0VzbDFCdnJTNUo0QXZHcnd1eWNpZ0Y4
eXZtUWVGUGNMNktFZGxRbjROOEtzVDhWNHJiUm45TVlIWXFUCmtoQ1d2bEMxWjh2QXJGcVhRdkhz
UGF4M2lRPT0K
`
err := checkSecrets([]byte(yamlData))
if err == nil {
t.Error("Expected error due to STRONGBOX header, but got nil")
}
})
t.Run("Success with no STRONGBOX header in Secret data", func(t *testing.T) {
yamlData := `
apiVersion: v1
kind: ConfigMap
metadata:
name: test
data:
key: value
key1: value1
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: test
---
apiVersion: v1
kind: Secret
metadata:
name: my-secret
data:
key1: |
c2VjcmV0ZGF0YQ==
`
err := checkSecrets([]byte(yamlData))
if err != nil {
t.Errorf("Expected success, but got error: %v", err)
}
})
t.Run("Error on AGE header in Secret data", func(t *testing.T) {
yamlData := `
apiVersion: v1
kind: ServiceAccount
metadata:
name: test
---
apiVersion: v1
kind: Secret
metadata:
name: my-secret
data:
key1: |
c2VjcmV0ZGF0YQ==
key2: |
LS0tLS1CRUdJTiBBR0UgRU5DUllQVEVEIEZJTEUtLS0tLQpZV2RsTFdWdVkzSjVjSFJwYjI0dWIz
Sm5MM1l4Q2kwK0lGZ3lOVFV4T1NCMVNHbHdXRkJMT0VwbVpHOWlUM1JTClMzQk5aREZPYm5Ndllr
c3pkMVpwTUVsTldXSXpXRVEyWmtRMENqUnJPRTVuUVV3dlVrNWpZWFZTV1RaalNUVXoKUzBOdWRu
RXpWWE5WVFhBeVpFcHZaMjl2V0ZwSVN6Z0tMUzB0SUROWVIweFpkM2ROVG5admF6QkRjM2RJWm1G
SQpZMDQ1Ukc1WVlsWnJUMmREWVdZek1GRTVhVk5RYVRRS05DYmE3QzU1S01FWFp2MjU4bFU2WjFD
M1c4UUF0WklGClJxZXFQSXZKYTljRTU0YUFDQT09Ci0tLS0tRU5EIEFHRSBFTkNSWVBURUQgRklM
RS0tLS0tCg==
`
err := checkSecrets([]byte(yamlData))
if err == nil {
t.Error("Expected error due to AGE header, but got nil")
}
})
}