|
6 | 6 |
|
7 | 7 | "github.com/golang-jwt/jwt/v5" |
8 | 8 | "github.com/stretchr/testify/assert" |
| 9 | + "github.com/stretchr/testify/require" |
9 | 10 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
10 | 11 | "k8s.io/client-go/kubernetes/fake" |
11 | 12 |
|
@@ -187,11 +188,46 @@ func TestGetScopes_CustomScopes(t *testing.T) { |
187 | 188 | } |
188 | 189 |
|
189 | 190 | func Test_getProjectFromRequest(t *testing.T) { |
190 | | - fp := newFakeProj() |
191 | | - projLister := test.NewFakeProjLister(fp) |
| 191 | + tests := []struct { |
| 192 | + name string |
| 193 | + resource string |
| 194 | + action string |
| 195 | + arg string |
| 196 | + }{ |
| 197 | + { |
| 198 | + name: "valid project/repo string", |
| 199 | + resource: "repositories", |
| 200 | + action: "create", |
| 201 | + arg: newFakeProj().Name + "/https://github.com/argoproj/argocd-example-apps", |
| 202 | + }, |
| 203 | + { |
| 204 | + name: "applicationsets with project/repo string", |
| 205 | + resource: "applicationsets", |
| 206 | + action: "create", |
| 207 | + arg: newFakeProj().Name + "/https://github.com/argoproj/argocd-example-apps", |
| 208 | + }, |
| 209 | + { |
| 210 | + name: "applicationsets with project/repo string", |
| 211 | + resource: "applicationsets", |
| 212 | + action: "*", |
| 213 | + arg: newFakeProj().Name + "/https://github.com/argoproj/argocd-example-apps", |
| 214 | + }, |
| 215 | + { |
| 216 | + name: "applicationsets with project/repo string", |
| 217 | + resource: "applicationsets", |
| 218 | + action: "get", |
| 219 | + arg: newFakeProj().Name + "/https://github.com/argoproj/argocd-example-apps", |
| 220 | + }, |
| 221 | + } |
192 | 222 |
|
193 | | - rbacEnforcer := NewRBACPolicyEnforcer(nil, projLister) |
194 | | - project := rbacEnforcer.getProjectFromRequest("", "repositories", "create", fp.Name+"/https://github.com/argoproj/argocd-example-apps") |
| 223 | + for _, tt := range tests { |
| 224 | + t.Run(tt.name, func(t *testing.T) { |
| 225 | + fp := newFakeProj() |
| 226 | + projLister := test.NewFakeProjLister(fp) |
| 227 | + rbacEnforcer := NewRBACPolicyEnforcer(nil, projLister) |
195 | 228 |
|
196 | | - assert.Equal(t, project.Name, fp.Name) |
| 229 | + project := rbacEnforcer.getProjectFromRequest("", tt.resource, tt.action, tt.arg) |
| 230 | + require.Equal(t, fp.Name, project.Name) |
| 231 | + }) |
| 232 | + } |
197 | 233 | } |
0 commit comments