-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid storing result in cache on checkaccess error (#340)
* dont store error in cache Signed-off-by: Anumita <[email protected]> * added tests Signed-off-by: Anumita <[email protected]>
- Loading branch information
Showing
3 changed files
with
26 additions
and
4 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 |
---|---|---|
|
@@ -95,8 +95,8 @@ func serverSetup(loginResp, checkaccessResp string, loginStatus, checkaccessStat | |
return srv, nil | ||
} | ||
|
||
func getServerAndClient(t *testing.T, loginResp, checkaccessResp string) (*httptest.Server, *Authorizer, authz.Store) { | ||
srv, err := serverSetup(loginResp, checkaccessResp, http.StatusOK, http.StatusOK) | ||
func getServerAndClient(t *testing.T, loginResp, checkaccessResp string, checkaccessStatus int) (*httptest.Server, *Authorizer, authz.Store) { | ||
srv, err := serverSetup(loginResp, checkaccessResp, http.StatusOK, checkaccessStatus) | ||
if err != nil { | ||
t.Fatalf("Error when creating server, reason: %v", err) | ||
} | ||
|
@@ -126,7 +126,7 @@ func TestCheck(t *testing.T) { | |
"actionId":"Microsoft.Kubernetes/connectedClusters/pods/delete", | ||
"isDataAction":true,"roleAssignment":null,"denyAssignment":null,"timeToLiveInMs":300000}]` | ||
|
||
srv, client, store := getServerAndClient(t, loginResp, validBody) | ||
srv, client, store := getServerAndClient(t, loginResp, validBody, http.StatusOK) | ||
defer srv.Close() | ||
defer store.Close() | ||
|
||
|
@@ -144,4 +144,24 @@ func TestCheck(t *testing.T) { | |
assert.Equal(t, resp.Allowed, true) | ||
assert.Equal(t, resp.Denied, false) | ||
}) | ||
|
||
t.Run("unsuccessful request", func(t *testing.T) { | ||
validBody := `""` | ||
srv, client, store := getServerAndClient(t, loginResp, validBody, http.StatusInternalServerError) | ||
defer srv.Close() | ||
defer store.Close() | ||
|
||
request := &authzv1.SubjectAccessReviewSpec{ | ||
User: "[email protected]", | ||
ResourceAttributes: &authzv1.ResourceAttributes{ | ||
Namespace: "dev", Group: "", Resource: "pods", | ||
Subresource: "status", Version: "v1", Name: "test", Verb: "delete", | ||
}, Extra: map[string]authzv1.ExtraValue{"oid": {"00000000-0000-0000-0000-000000000000"}}, | ||
} | ||
|
||
resp, err := client.Check(request, store) | ||
assert.Nilf(t, resp, "response should be nil") | ||
assert.NotNilf(t, err, "should get error") | ||
assert.Contains(t, err.Error(), "Error occured during authorization check") | ||
}) | ||
} |
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