-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First pass for helper for bulk changes Signed-off-by: Mark Anderson <[email protected]> * Convert ACLRead and ACLWrite to new form Signed-off-by: Mark Anderson <[email protected]> * AgentRead and AgentWRite Signed-off-by: Mark Anderson <[email protected]> * Fix EventWrite Signed-off-by: Mark Anderson <[email protected]> * KeyRead, KeyWrite, KeyList Signed-off-by: Mark Anderson <[email protected]> * KeyRing Signed-off-by: Mark Anderson <[email protected]> * NodeRead NodeWrite Signed-off-by: Mark Anderson <[email protected]> * OperatorRead and OperatorWrite Signed-off-by: Mark Anderson <[email protected]> * PreparedQuery Signed-off-by: Mark Anderson <[email protected]> * Intention partial Signed-off-by: Mark Anderson <[email protected]> * Fix ServiceRead, Write ,etc Signed-off-by: Mark Anderson <[email protected]> * Error check ServiceRead? Signed-off-by: Mark Anderson <[email protected]> * Fix Sessionread/Write Signed-off-by: Mark Anderson <[email protected]> * Fixup snapshot ACL Signed-off-by: Mark Anderson <[email protected]> * Error fixups for txn Signed-off-by: Mark Anderson <[email protected]> * Add changelog Signed-off-by: Mark Anderson <[email protected]> * Fixup review comments Signed-off-by: Mark Anderson <[email protected]>
- Loading branch information
Showing
35 changed files
with
616 additions
and
247 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:enhancement | ||
acl: Provide fuller detail in the error messsage when an ACL denies access. | ||
``` |
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package acl | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"regexp" | ||
"testing" | ||
) | ||
|
||
func RequirePermissionDeniedError(t testing.TB, err error, _ Authorizer, _ *AuthorizerContext, resource Resource, accessLevel AccessLevel, resourceID string) { | ||
t.Helper() | ||
if err == nil { | ||
t.Fatal("An error is expected but got nil.") | ||
} | ||
if v, ok := err.(PermissionDeniedError); ok { | ||
require.Equal(t, v.Resource, resource) | ||
require.Equal(t, v.AccessLevel, accessLevel) | ||
require.Equal(t, v.ResourceID.Name, resourceID) | ||
} else { | ||
t.Fatalf("Expected a permission denied error got %T %vp", err, err) | ||
} | ||
} | ||
|
||
func RequirePermissionDeniedMessage(t testing.TB, msg string, auth Authorizer, _ *AuthorizerContext, resource Resource, accessLevel AccessLevel, resourceID string) { | ||
require.NotEmpty(t, msg, "expected non-empty error message") | ||
|
||
var resourceIDFound string | ||
if auth == nil { | ||
expr := "^Permission denied" + `: provided accessor lacks permission '(\S*):(\S*)' on (.*)\s*$` | ||
re, _ := regexp.Compile(expr) | ||
matched := re.FindStringSubmatch(msg) | ||
|
||
require.Equal(t, string(resource), matched[1], "resource") | ||
require.Equal(t, accessLevel.String(), matched[2], "access level") | ||
resourceIDFound = matched[3] | ||
} else { | ||
expr := "^Permission denied" + `: accessor '(\S*)' lacks permission '(\S*):(\S*)' on (.*)\s*$` | ||
re, _ := regexp.Compile(expr) | ||
matched := re.FindStringSubmatch(msg) | ||
|
||
require.Equal(t, auth, matched[1], "auth") | ||
require.Equal(t, string(resource), matched[2], "resource") | ||
require.Equal(t, accessLevel.String(), matched[3], "access level") | ||
resourceIDFound = matched[4] | ||
} | ||
// AuthorizerContext information should be checked here | ||
require.Contains(t, resourceIDFound, resourceID, "resource id") | ||
} |
Oops, something went wrong.