@@ -14,50 +14,89 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- package plugin_test
17
+ package plugin
18
18
19
19
import (
20
20
"testing"
21
-
22
- "github.com/kcp-dev/kcp/cli/pkg/bind/plugin"
23
21
)
24
22
25
23
func TestBindOptionsValidate (t * testing.T ) {
26
24
testCases := []struct {
27
25
description string
28
- bindOptions plugin. BindOptions
26
+ bindOptions BindOptions
29
27
wantValid bool
30
28
}{
31
29
{
32
30
description : "Fully-qualified APIExport reference with dashes" ,
33
- bindOptions : plugin. BindOptions {APIExportRef : "test-root:test-workspace:test-apiexport-123" },
31
+ bindOptions : BindOptions {APIExportRef : "test-root:test-workspace:test-apiexport-123" },
34
32
wantValid : true ,
35
33
},
36
34
{
37
35
description : "Fully-qualified APIExport reference with dots in the name" ,
38
- bindOptions : plugin. BindOptions {APIExportRef : "test-root:test-workspace:test.apiexport.123" },
36
+ bindOptions : BindOptions {APIExportRef : "test-root:test-workspace:test.apiexport.123" },
39
37
wantValid : true ,
40
38
},
41
39
{
42
40
description : "Fully-qualified APIExport reference with special characters in the name" ,
43
- bindOptions : plugin. BindOptions {APIExportRef : "test-root:test-workspace:test@apiexport=123" },
41
+ bindOptions : BindOptions {APIExportRef : "test-root:test-workspace:test@apiexport=123" },
44
42
wantValid : true ,
45
43
},
46
44
{
47
45
description : "Fully-qualified APIExport reference with upper-case characters in the name" ,
48
- bindOptions : plugin. BindOptions {APIExportRef : "test-root:test-workspace:testAPIExport123" },
46
+ bindOptions : BindOptions {APIExportRef : "test-root:test-workspace:testAPIExport123" },
49
47
wantValid : true ,
50
48
},
51
49
{
52
50
description : "Fully-qualified APIExport reference with special characters in the path" ,
53
- bindOptions : plugin. BindOptions {APIExportRef : "test-root:t@st-workspace:test-apiexport" },
51
+ bindOptions : BindOptions {APIExportRef : "test-root:t@st-workspace:test-apiexport" },
54
52
wantValid : false ,
55
53
},
56
54
{
57
55
description : "Fully-qualified APIExport reference with upper-case characters in the path" ,
58
- bindOptions : plugin. BindOptions {APIExportRef : "test-root:TestWorkspace:test-apiexport" },
56
+ bindOptions : BindOptions {APIExportRef : "test-root:TestWorkspace:test-apiexport" },
59
57
wantValid : false ,
60
58
},
59
+ {
60
+ description : "Valid accepted permission claims" ,
61
+ bindOptions : BindOptions {
62
+ APIExportRef : "test-root:test-workspace:test-apiexport" ,
63
+ AcceptedPermissionClaims : []string {"group.resource" },
64
+ },
65
+ wantValid : true ,
66
+ },
67
+ {
68
+ description : "Valid rejected permission claims" ,
69
+ bindOptions : BindOptions {
70
+ APIExportRef : "test-root:test-workspace:test-apiexport" ,
71
+ RejectedPermissionClaims : []string {"resource.group" },
72
+ },
73
+ wantValid : true ,
74
+ },
75
+ {
76
+ description : "Conflicting accepted and rejected permission claims" ,
77
+ bindOptions : BindOptions {
78
+ APIExportRef : "test-root:test-workspace:test-apiexport" ,
79
+ AcceptedPermissionClaims : []string {"resource.group" },
80
+ RejectedPermissionClaims : []string {"resource.group" },
81
+ },
82
+ wantValid : false ,
83
+ },
84
+ {
85
+ description : "Invalid accepted permission claim format" ,
86
+ bindOptions : BindOptions {
87
+ APIExportRef : "test-root:test-workspace:test-apiexport" ,
88
+ AcceptedPermissionClaims : []string {"invalidclaim" },
89
+ },
90
+ wantValid : false ,
91
+ },
92
+ {
93
+ description : "Invalid rejected permission claim format" ,
94
+ bindOptions : BindOptions {
95
+ APIExportRef : "test-root:test-workspace:test-apiexport" ,
96
+ RejectedPermissionClaims : []string {"invalidclaim" },
97
+ },
98
+ wantValid : false ,
99
+ },
61
100
}
62
101
63
102
for _ , c := range testCases {
@@ -74,3 +113,58 @@ func TestBindOptionsValidate(t *testing.T) {
74
113
})
75
114
}
76
115
}
116
+
117
+ func TestParsePermissionClaim (t * testing.T ) {
118
+ testCases := []struct {
119
+ description string
120
+ claim string
121
+ accepted bool
122
+ wantError bool
123
+ }{
124
+ {
125
+ description : "Valid accepted permission claim" ,
126
+ claim : "resource.group" ,
127
+ accepted : true ,
128
+ wantError : false ,
129
+ },
130
+ {
131
+ description : "Valid rejected permission claim" ,
132
+ claim : "resource.group" ,
133
+ accepted : false ,
134
+ wantError : false ,
135
+ },
136
+ {
137
+ description : "Invalid permission claim format" ,
138
+ claim : "invalidclaim" ,
139
+ accepted : true ,
140
+ wantError : true ,
141
+ },
142
+ {
143
+ description : "Empty permission claim" ,
144
+ claim : "" ,
145
+ accepted : true ,
146
+ wantError : true ,
147
+ },
148
+ {
149
+ description : "Core group permission claim" ,
150
+ claim : "resource.core" ,
151
+ accepted : true ,
152
+ wantError : false ,
153
+ },
154
+ }
155
+
156
+ for _ , c := range testCases {
157
+ t .Run (c .description , func (t * testing.T ) {
158
+ b := & BindOptions {}
159
+ err := b .parsePermissionClaim (c .claim , c .accepted )
160
+
161
+ if (err != nil ) && ! c .wantError {
162
+ t .Errorf ("wanted %q to be parsed without error, but got error: %v" , c .claim , err )
163
+ }
164
+
165
+ if (err == nil ) && c .wantError {
166
+ t .Errorf ("wanted %q to be parsed with error, but got no error" , c .claim )
167
+ }
168
+ })
169
+ }
170
+ }
0 commit comments