diff --git a/internal/service/policy/service_test.go b/internal/service/policy/service_test.go index ca5b4db7214c4c49889228c4804e6803fbffce15..3e442900a706f95d423500ec4be9529c810959a4 100644 --- a/internal/service/policy/service_test.go +++ b/internal/service/policy/service_test.go @@ -29,6 +29,9 @@ func TestService_Evaluate(t *testing.T) { // value of a blank variable assignment testPolicyBlankAssignment := `package testgroup.example _ = {"hello":"world"}` + // prepare test policy using static json data during evaluation + testPolicyWithStaticData := `package testgroup.example default allow = false allow { data.msg == "hello world" }` + // prepare test query that can be retrieved from rego queryCache testQuery, err := rego.New( rego.Module("example.rego", testPolicy), @@ -214,6 +217,36 @@ func TestService_Evaluate(t *testing.T) { Result: map[string]interface{}{"hello": "world"}, }, }, + { + name: "policy using static json data is evaluated successfully", + req: testReq(), + regocache: &policyfakes.FakeRegoCache{ + GetStub: func(key string) (*rego.PreparedEvalQuery, bool) { + return nil, false + }, + }, + storage: &policyfakes.FakeStorage{ + PolicyStub: func(ctx context.Context, s string, s2 string, s3 string) (*storage.Policy, error) { + return &storage.Policy{ + Name: "example", + Group: "testgroup", + Version: "1.0", + Rego: testPolicyWithStaticData, + Data: `{"msg": "hello world"}`, + Locked: false, + LastUpdate: time.Now(), + }, nil + }, + }, + cache: &policyfakes.FakeCache{ + SetStub: func(ctx context.Context, s string, s2 string, s3 string, bytes []byte) error { + return nil + }, + }, + res: &goapolicy.EvaluateResult{ + Result: map[string]interface{}{"allow": true}, + }, + }, } for _, test := range tests {