forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authorizer_test.go
39 lines (36 loc) · 1.22 KB
/
authorizer_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
package auth
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
authorizationv1 "k8s.io/api/authorization/v1"
"k8s.io/apimachinery/pkg/runtime"
kubefake "k8s.io/client-go/kubernetes/fake"
k8stesting "k8s.io/client-go/testing"
)
func TestAuthorizer_CanI(t *testing.T) {
kubeClient := &kubefake.Clientset{}
allowed := true
kubeClient.AddReactor("create", "selfsubjectaccessreviews", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
return true, &authorizationv1.SelfSubjectAccessReview{
Status: authorizationv1.SubjectAccessReviewStatus{Allowed: allowed},
}, nil
})
ctx := context.WithValue(context.Background(), KubeKey, kubeClient)
t.Run("CanI", func(t *testing.T) {
allowed, err := CanI(ctx, "", "", "", "")
if assert.NoError(t, err) {
assert.True(t, allowed)
}
})
kubeClient.AddReactor("create", "selfsubjectrulesreviews", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
return true, &authorizationv1.SelfSubjectRulesReview{
Status: authorizationv1.SubjectRulesReviewStatus{
ResourceRules: []authorizationv1.ResourceRule{{
Verbs: []string{"*"},
ResourceNames: []string{"my-name"},
}},
},
}, nil
})
}