diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5955590..4ad5aeb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,7 +52,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [^18, ^20] + node: [^20] steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/platform_test.yml b/.github/workflows/platform_test.yml index 9f4d21f..c184851 100644 --- a/.github/workflows/platform_test.yml +++ b/.github/workflows/platform_test.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [^18, ^20] + node-version: [^20] steps: - uses: actions/checkout@v3 @@ -37,7 +37,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [^18, ^20] + node-version: [^20] steps: - uses: actions/checkout@v3 @@ -60,7 +60,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [^18, ^20] + node-version: [^20] steps: - uses: actions/checkout@v3 diff --git a/src/internalEnforcer.ts b/src/internalEnforcer.ts index 6787601..ac74f0a 100644 --- a/src/internalEnforcer.ts +++ b/src/internalEnforcer.ts @@ -33,7 +33,7 @@ export class InternalEnforcer extends CoreEnforcer { try { await this.adapter.addPolicy(sec, ptype, rule); } catch (e) { - if (e.message !== 'not implemented') { + if (!(e instanceof Error) || e.message !== 'not implemented') { throw e; } } @@ -70,7 +70,7 @@ export class InternalEnforcer extends CoreEnforcer { try { await (this.adapter as BatchAdapter).addPolicies(sec, ptype, rules); } catch (e) { - if (e.message !== 'not implemented') { + if (!(e instanceof Error) || e.message !== 'not implemented') { throw e; } } @@ -108,7 +108,7 @@ export class InternalEnforcer extends CoreEnforcer { try { await (this.adapter as UpdatableAdapter).updatePolicy(sec, ptype, oldRule, newRule); } catch (e) { - if (e.message !== 'not implemented') { + if (!(e instanceof Error) || e.message !== 'not implemented') { throw e; } } @@ -144,7 +144,7 @@ export class InternalEnforcer extends CoreEnforcer { try { await this.adapter.removePolicy(sec, ptype, rule); } catch (e) { - if (e.message !== 'not implemented') { + if (!(e instanceof Error) || e.message !== 'not implemented') { throw e; } } @@ -179,7 +179,7 @@ export class InternalEnforcer extends CoreEnforcer { try { await (this.adapter as BatchAdapter).removePolicies(sec, ptype, rules); } catch (e) { - if (e.message !== 'not implemented') { + if (!(e instanceof Error) || e.message !== 'not implemented') { throw e; } } @@ -212,7 +212,7 @@ export class InternalEnforcer extends CoreEnforcer { try { await this.adapter.removeFilteredPolicy(sec, ptype, fieldIndex, ...fieldValues); } catch (e) { - if (e.message !== 'not implemented') { + if (!(e instanceof Error) || e.message !== 'not implemented') { throw e; } } diff --git a/src/util/util.ts b/src/util/util.ts index d2105cf..d911074 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -213,9 +213,9 @@ function policyStringToArray(policy: string): string[][] { function customIn(a: number | string, b: number | string): number { if ((b as any) instanceof Array) { - return (((b as any) as Array).includes(a) as unknown) as number; + return (b as any as Array).includes(a) as unknown as number; } - return ((a in (b as any)) as unknown) as number; + return (a in (b as any)) as unknown as number; } function bracketCompatible(exp: string): string { diff --git a/test/enforcer.test.ts b/test/enforcer.test.ts index 1abb1fe..36e97ab 100644 --- a/test/enforcer.test.ts +++ b/test/enforcer.test.ts @@ -573,9 +573,9 @@ test('test ABAC multiple eval()', async () => { ); const e = await newEnforcer(m, policy); - await testEnforce(e, 56, (98 as unknown) as string, 'read', true); - await testEnforce(e, 23, (67 as unknown) as string, 'read', false); - await testEnforce(e, 78, (34 as unknown) as string, 'read', false); + await testEnforce(e, 56, 98 as unknown as string, 'read', true); + await testEnforce(e, 23, 67 as unknown as string, 'read', false); + await testEnforce(e, 78, 34 as unknown as string, 'read', false); }); test('TestEnforceSync', async () => { @@ -645,9 +645,9 @@ test('test ABAC multiple eval()', async () => { ); const e = await newEnforcer(m, policy); - await testEnforce(e, 56, (98 as unknown) as string, 'read', true); - await testEnforce(e, 23, (67 as unknown) as string, 'read', false); - await testEnforce(e, 78, (34 as unknown) as string, 'read', false); + await testEnforce(e, 56, 98 as unknown as string, 'read', true); + await testEnforce(e, 23, 67 as unknown as string, 'read', false); + await testEnforce(e, 78, 34 as unknown as string, 'read', false); }); test('TestBatchEnforce', async () => { diff --git a/test/model/model.test.ts b/test/model/model.test.ts index 7c8f028..19e2204 100644 --- a/test/model/model.test.ts +++ b/test/model/model.test.ts @@ -56,8 +56,9 @@ test('TestLoadModelFromConfig', (done) => { } if (e instanceof Error) { + const errorMessage = e.message; requiredSections.forEach((n) => { - if (!e.message.includes(n)) { + if (!errorMessage.includes(n)) { throw new Error(`section name: ${sectionNameMap[n]} should be in message`); } });