From 61275848007386550dc211e3ed0b13388e654a29 Mon Sep 17 00:00:00 2001 From: hsluoyz Date: Sat, 12 Nov 2022 21:46:12 +0800 Subject: [PATCH] fix: Revert "fix: escape assertion bug (#394)" (#398) This reverts commit 5a339d858a9cfb7d8899355cbd179ec962b43cfa. --- examples/abac_attr_model.conf | 11 ----------- examples/abac_attr_policy.csv | 2 -- src/util/util.ts | 6 ++---- test/enforcer.test.ts | 14 -------------- 4 files changed, 2 insertions(+), 31 deletions(-) delete mode 100644 examples/abac_attr_model.conf delete mode 100644 examples/abac_attr_policy.csv diff --git a/examples/abac_attr_model.conf b/examples/abac_attr_model.conf deleted file mode 100644 index a39d802..0000000 --- a/examples/abac_attr_model.conf +++ /dev/null @@ -1,11 +0,0 @@ -[request_definition] -r = sub_data, act - -[policy_definition] -p = sub, act - -[policy_effect] -e = some(where (p.eft == allow)) - -[matchers] -m = r.sub_data.attr.id == p.sub && r.act == p.act \ No newline at end of file diff --git a/examples/abac_attr_policy.csv b/examples/abac_attr_policy.csv deleted file mode 100644 index c861941..0000000 --- a/examples/abac_attr_policy.csv +++ /dev/null @@ -1,2 +0,0 @@ -p, alice, read -p, bob, write \ No newline at end of file diff --git a/src/util/util.ts b/src/util/util.ts index f45c23e..af680cd 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -17,10 +17,8 @@ import * as fs from 'fs'; // escapeAssertion escapes the dots in the assertion, // because the expression evaluation doesn't support such variable names. function escapeAssertion(s: string): string { - s = ' ' + s; - s = s.replace(/(?<=[\(| ])r\./g, 'r_'); - s = s.replace(/(?<=[\(| ])p\./g, 'p_'); - s = s.trim(); + s = s.replace(/r\./g, 'r_'); + s = s.replace(/p\./g, 'p_'); return s; } diff --git a/test/enforcer.test.ts b/test/enforcer.test.ts index e70ea51..e3565c1 100644 --- a/test/enforcer.test.ts +++ b/test/enforcer.test.ts @@ -697,17 +697,3 @@ test('TestEnforceExWithPriorityModel', async () => { testEnforceEx(e, 'bob', 'data2', 'read', [true, ['data2_allow_group', 'data2', 'read', 'allow']]); testEnforceEx(e, 'alice', 'data2', 'read', [false, []]); }); - -test('TestABACAtrrModel', async () => { - const e = await newEnforcer('examples/abac_attr_model.conf', 'examples/abac_attr_policy.csv'); - expect( - await e.enforce( - { - attr: { - id: 'alice', - }, - }, - 'read' - ) - ).toBe(true); -});