@@ -135,12 +135,14 @@ func (e *Evaluator) statementMatches(stmt *Statement, req AuthorizationRequest)
|
||||
// Check resource match (if resources are specified)
|
||||
if len(stmt.Resources) > 0 {
|
||||
resourceMatched := false
|
||||
|
||||
for _, pattern := range stmt.Resources {
|
||||
if pattern.MatchesResource(req.Resource) {
|
||||
resourceMatched = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !resourceMatched {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -390,12 +390,15 @@ func TestEvaluator_Evaluate_MatchedStatementAndPolicy(t *testing.T) {
|
||||
if result.MatchedStatement == nil {
|
||||
t.Fatal("Expected matched statement")
|
||||
}
|
||||
|
||||
if result.MatchedStatement.SID != "allow-get" {
|
||||
t.Errorf("Expected SID 'allow-get', got %q", result.MatchedStatement.SID)
|
||||
}
|
||||
|
||||
if result.MatchedPolicy == nil {
|
||||
t.Fatal("Expected matched policy")
|
||||
}
|
||||
|
||||
if result.MatchedPolicy.ID != "test-policy" {
|
||||
t.Errorf("Expected policy ID 'test-policy', got %q", result.MatchedPolicy.ID)
|
||||
}
|
||||
@@ -414,6 +417,7 @@ func TestEvaluator_Evaluate_MatchedStatementAndPolicy(t *testing.T) {
|
||||
if result.MatchedStatement == nil {
|
||||
t.Fatal("Expected matched statement")
|
||||
}
|
||||
|
||||
if result.MatchedStatement.SID != "deny-delete" {
|
||||
t.Errorf("Expected SID 'deny-delete', got %q", result.MatchedStatement.SID)
|
||||
}
|
||||
@@ -432,6 +436,7 @@ func TestEvaluator_Evaluate_MatchedStatementAndPolicy(t *testing.T) {
|
||||
if result.MatchedStatement != nil {
|
||||
t.Error("Expected no matched statement")
|
||||
}
|
||||
|
||||
if result.MatchedPolicy != nil {
|
||||
t.Error("Expected no matched policy")
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ func (m *ActionMatcher) Matches(pattern, target string) bool {
|
||||
if patternParts[1] == "*" {
|
||||
return patternParts[0] == targetParts[0] || patternParts[0] == "*"
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
case 3:
|
||||
@@ -74,6 +75,7 @@ func (m *ActionMatcher) matchPart(pattern, target string) bool {
|
||||
if pattern == "*" {
|
||||
return true
|
||||
}
|
||||
|
||||
return pattern == target
|
||||
}
|
||||
|
||||
@@ -84,5 +86,6 @@ func (m *ActionMatcher) MatchesAny(patterns []string, target string) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -127,6 +127,7 @@ func (c Condition) Evaluate(ctx ConditionContext) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
case ConditionNotEquals:
|
||||
@@ -136,6 +137,7 @@ func (c Condition) Evaluate(ctx ConditionContext) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
case ConditionIn:
|
||||
@@ -153,6 +155,7 @@ func (c Condition) Evaluate(ctx ConditionContext) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -160,6 +163,7 @@ func (c Condition) Evaluate(ctx ConditionContext) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
case ConditionNotIn:
|
||||
@@ -175,6 +179,7 @@ func (c Condition) Evaluate(ctx ConditionContext) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -182,6 +187,7 @@ func (c Condition) Evaluate(ctx ConditionContext) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
default:
|
||||
@@ -196,12 +202,14 @@ func resolveKey(key string, ctx ConditionContext) (string, bool) {
|
||||
if len(key) > 10 && key[:10] == "principal." {
|
||||
attrKey := key[10:]
|
||||
val, ok := ctx.Principal[attrKey]
|
||||
|
||||
return val, ok
|
||||
}
|
||||
|
||||
if len(key) > 9 && key[:9] == "resource." {
|
||||
attrKey := key[9:]
|
||||
val, ok := ctx.Resource[attrKey]
|
||||
|
||||
return val, ok
|
||||
}
|
||||
|
||||
|
||||
@@ -284,9 +284,11 @@ func TestConditionHelpers(t *testing.T) {
|
||||
if c.Operator != ConditionEquals {
|
||||
t.Errorf("Expected ConditionEquals, got %v", c.Operator)
|
||||
}
|
||||
|
||||
if c.Key != "principal.id" {
|
||||
t.Errorf("Expected principal.id, got %v", c.Key)
|
||||
}
|
||||
|
||||
if len(c.Values) != 2 {
|
||||
t.Errorf("Expected 2 values, got %d", len(c.Values))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user