MCPcopy Create free account
hub / github.com/astercloud/aster / TestBasicPolicyEngine_Evaluate_Deny

Function TestBasicPolicyEngine_Evaluate_Deny

pkg/security/policy_test.go:192–230  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

190}
191
192func TestBasicPolicyEngine_Evaluate_Deny(t *testing.T) {
193 engine := NewBasicPolicyEngine(nil, &mockAuditLog{})
194
195 policy := &SecurityPolicy{
196 ID: "policy1",
197 Name: "Deny Policy",
198 Enabled: true,
199 Priority: 10,
200 Scope: ScopeGlobal,
201 Target: TargetAll,
202 Action: ActionDeny,
203 Resources: []string{"secret"},
204 Deny: []string{"read"},
205 }
206 _ = engine.AddPolicy(policy)
207
208 request := &PolicyRequest{
209 RequestID: "req1",
210 UserID: "user1",
211 Action: "read",
212 Resource: "secret",
213 Timestamp: time.Now(),
214 Context: make(map[string]any),
215 Metadata: make(map[string]any),
216 }
217
218 evaluation, err := engine.Evaluate(request)
219 if err != nil {
220 t.Fatalf("Evaluate failed: %v", err)
221 }
222
223 if evaluation.Allowed {
224 t.Error("expected evaluation to deny access")
225 }
226
227 if evaluation.Action != ActionDeny {
228 t.Errorf("expected action Deny, got %v", evaluation.Action)
229 }
230}
231
232func TestBasicPolicyEngine_Evaluate_NoMatchingPolicy(t *testing.T) {
233 engine := NewBasicPolicyEngine(nil, &mockAuditLog{})

Callers

nothing calls this directly

Calls 4

AddPolicyMethod · 0.95
EvaluateMethod · 0.95
NewBasicPolicyEngineFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected