From 870918f4d169f63d78d143f065c8ec5ba2967259 Mon Sep 17 00:00:00 2001 From: William Calderipe Date: Wed, 20 Mar 2024 11:41:17 +0100 Subject: [PATCH] Move approvals test to the new Rego location Original commit: 33ae82ce2e54d60366d60f0991f31c210aca0917 --- .../core/type/open-policy-agent.type.ts | 2 +- .../rego/__test__/policies/approvals.rego | 23 +++++++++++++++++++ .../__test__/policies/approvals_test.rego | 19 +++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/apps/policy-engine/src/open-policy-agent/core/type/open-policy-agent.type.ts b/apps/policy-engine/src/open-policy-agent/core/type/open-policy-agent.type.ts index 3445bd112..aa5733fbe 100644 --- a/apps/policy-engine/src/open-policy-agent/core/type/open-policy-agent.type.ts +++ b/apps/policy-engine/src/open-policy-agent/core/type/open-policy-agent.type.ts @@ -23,7 +23,7 @@ export type Input = { transactionRequest?: TransactionRequest principal: CredentialEntity resource?: { uid: string } - approvals: CredentialEntity[] + approvals?: CredentialEntity[] transfers?: HistoricalTransfer[] } diff --git a/apps/policy-engine/src/resource/open-policy-agent/rego/__test__/policies/approvals.rego b/apps/policy-engine/src/resource/open-policy-agent/rego/__test__/policies/approvals.rego index 6b87eed05..9968cf402 100644 --- a/apps/policy-engine/src/resource/open-policy-agent/rego/__test__/policies/approvals.rego +++ b/apps/policy-engine/src/resource/open-policy-agent/rego/__test__/policies/approvals.rego @@ -94,3 +94,26 @@ permit[{"policyId": "approvalByUserRoles"}] = reason { "approvalsMissing": approvals.approvalsMissing, } } + +permit[{"policyId": "withoutApprovals"}] = reason { + resources = {"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"} + transferTypes = {"transferERC20"} + tokens = {"eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174"} + transferValueCondition = {"currency": "*", "operator": "lte", "value": "1000000000000000000"} + + checkResourceIntegrity + checkPrincipal + checkNonceExists + checkAction({"signTransaction"}) + checkWalletId(resources) + checkIntentType(transferTypes) + checkIntentToken(tokens) + checkIntentAmount(transferValueCondition) + + reason = { + "type": "permit", + "policyId": "withoutApprovals", + "approvalsSatisfied": [], + "approvalsMissing": [], + } +} diff --git a/apps/policy-engine/src/resource/open-policy-agent/rego/__test__/policies/approvals_test.rego b/apps/policy-engine/src/resource/open-policy-agent/rego/__test__/policies/approvals_test.rego index 081193759..30bc1c60b 100644 --- a/apps/policy-engine/src/resource/open-policy-agent/rego/__test__/policies/approvals_test.rego +++ b/apps/policy-engine/src/resource/open-policy-agent/rego/__test__/policies/approvals_test.rego @@ -61,3 +61,22 @@ test_approvalByUserRoles { "type": "permit", } } + +test_withoutApprovals { + withoutApprovalsReq = { + "action": "signTransaction", + "transactionRequest": transactionRequestReq, + "principal": {"userId": "test-alice-uid"}, "resource": resourceReq, + "intent": intentReq, + "feeds": feedsReq, + } + + res = permit[{"policyId": "withoutApprovals"}] with input as withoutApprovalsReq with data.entities as entities + + res == { + "type": "permit", + "policyId": "withoutApprovals", + "approvalsSatisfied": [], + "approvalsMissing": [], + } +}