-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(RHTAPATCH-1069): unit-tests for runAccessCheck
Add unit-tests to `runAccessCheck`. We decided to perform the tests using the same test suite we are using for the functional tests, using testenv. It is setting up a real environment for us, and we don't have to deal with ugly fakes when using the k8s authorization. Signed-off-by: Omer Turner <[email protected]>
- Loading branch information
Showing
4 changed files
with
178 additions
and
471 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |
k8sapi "k8s.io/api/core/v1" | ||
rbacv1 "k8s.io/api/rbac/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
|
||
"context" | ||
"os" | ||
|
@@ -23,6 +24,7 @@ import ( | |
"k8s.io/client-go/tools/clientcmd" | ||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
"sigs.k8s.io/controller-runtime/pkg/envtest" | ||
) | ||
|
||
|
@@ -267,3 +269,26 @@ var _ = AfterSuite(func() { | |
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Error killing the server during test teardown: %v", err)) | ||
} | ||
}) | ||
|
||
var _ = DescribeTable("TestRunAccessCheck", func(user string, namespace string, resource string, expectedResult bool) { | ||
cfg, _ := config.GetConfig() | ||
clientset, _ := kubernetes.NewForConfig(cfg) | ||
authCl := clientset.AuthorizationV1() | ||
|
||
boolresult, err := runAccessCheck(authCl, user, namespace, "appstudio.redhat.com", resource, "create") | ||
Expect(boolresult).To(Equal(expectedResult)) | ||
Expect(err).NotTo(HaveOccurred(), "Unexpected error testing RunAccessCheck") | ||
}, | ||
Entry( | ||
"A user that has access to the resource should return true (user1 have access to test-tenant-1)", | ||
"[email protected]", | ||
"test-tenant-2", | ||
"applications", | ||
true), | ||
Entry( | ||
"A user that does not have access to the resource should return false (user1 don't have access to test-tenant-2)", | ||
"[email protected]", | ||
"test-tenant-2", | ||
"applications", | ||
false), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.