Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [^18, ^20]
node: [^20]
steps:
- uses: actions/checkout@v3

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/platform_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [^18, ^20]
node-version: [^20]
steps:
- uses: actions/checkout@v3

Expand All @@ -37,7 +37,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [^18, ^20]
node-version: [^20]
steps:
- uses: actions/checkout@v3

Expand All @@ -60,7 +60,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [^18, ^20]
node-version: [^20]
steps:
- uses: actions/checkout@v3

Expand Down
12 changes: 6 additions & 6 deletions src/internalEnforcer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>).includes(a) as unknown) as number;
return (b as any as Array<any>).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 {
Expand Down
12 changes: 6 additions & 6 deletions test/enforcer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
3 changes: 2 additions & 1 deletion test/model/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
});
Expand Down