Repository navigation
Expand file tree
/
Copy pathinit_cert_test.go
More file actions
93 lines (87 loc) · 2.67 KB
/
Copy pathinit_cert_test.go
File metadata and controls
93 lines (87 loc) · 2.67 KB
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
package centralsensor
import (
"testing"
"github.com/stackrox/rox/pkg/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const (
testClusterID = "12b1af66-be55-4e54-948d-ac9c311ca4b2"
otherClusterID = "d2842760-c0f5-4574-80a1-58c300c36375"
)
func TestUserIssuedInitCertClusterIDIsNilUUID(t *testing.T) {
parsed, err := uuid.FromString(RegisteredInitCertClusterID)
require.NoError(t, err, "could not parse init cert cluster ID as UUID")
assert.Equal(t, uuid.Nil, parsed, "expected init cert cluster ID to be the nil UUID")
}
func TestGetClusterID(t *testing.T) {
cases := map[string]struct {
explicitID, idFromCert string
expectedID string
expectError bool
}{
// No explicit ID, concrete ID in cert
"no-explicit-id": {
explicitID: "",
idFromCert: testClusterID,
expectedID: testClusterID,
},
// Same explicit and cert ID
"explicit-id-no-wildcard": {
explicitID: testClusterID,
idFromCert: testClusterID,
expectedID: testClusterID,
},
// Error case where an incorrect explicit ID is set for a non-wildcard cert
"incorrect-id-no-wildcard": {
explicitID: otherClusterID,
idFromCert: testClusterID,
expectError: true,
},
// Feature flag enabled: explicit ID and registered wildcard cert
"explicit-id-and-registered-wildcard-cert": {
explicitID: testClusterID,
idFromCert: RegisteredInitCertClusterID,
expectedID: testClusterID,
},
// Feature flag enabled: explicit nil ID and registered wildcard cert
"explicit-nil-id-and-registered-wildcard-cert": {
explicitID: RegisteredInitCertClusterID,
idFromCert: RegisteredInitCertClusterID,
expectError: true,
},
"no-explicit-id-and-registered-wildcard-cert": {
explicitID: "",
idFromCert: RegisteredInitCertClusterID,
expectError: true,
},
// Feature flag enabled: explicit ID and ephemeral wildcard cert
"explicit-id-and-ephemeral-wildcard-cert": {
explicitID: testClusterID,
idFromCert: EphemeralInitCertClusterID,
expectedID: testClusterID,
},
// Feature flag enabled: explicit nil ID and ephemeral wildcard cert
"explicit-nil-id-and-ephemeral-wildcard-cert": {
explicitID: RegisteredInitCertClusterID,
idFromCert: EphemeralInitCertClusterID,
expectError: true,
},
"no-explicit-id-and-ephemeral-wildcard-cert": {
explicitID: "",
idFromCert: EphemeralInitCertClusterID,
expectError: true,
},
}
for cName, c := range cases {
t.Run(cName, func(t *testing.T) {
clusterID, err := GetClusterID(c.explicitID, c.idFromCert)
if c.expectError {
assert.Error(t, err)
} else {
require.NoError(t, err)
assert.Equal(t, c.expectedID, clusterID)
}
})
}
}