From 1394e8ddfdc4cc9d8859ae034a8f36fb9e3b54e7 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Thu, 30 Apr 2020 11:13:07 +0800 Subject: [PATCH] feat: avoid miss initialize() --- src/coreEnforcer.ts | 32 +++++++++----------------------- src/enforcer.ts | 6 +----- test/model.test.ts | 1 - 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/coreEnforcer.ts b/src/coreEnforcer.ts index 56e5cfc..614b088 100644 --- a/src/coreEnforcer.ts +++ b/src/coreEnforcer.ts @@ -27,30 +27,18 @@ import { getLogger, logPrint } from './log'; export class CoreEnforcer { protected modelPath: string; protected model: Model; - protected fm: FunctionMap; - private eft: Effector; - private matcherMap: Map Promise) | ((context: object) => any)>; + protected fm: FunctionMap = FunctionMap.loadFunctionMap(); + protected eft: Effector = new DefaultEffector(); + private matcherMap: Map Promise) | ((context: object) => any)> = new Map(); protected adapter: FilteredAdapter | Adapter; protected watcher: Watcher | null = null; - protected rm: RoleManager; - - private enabled: boolean; - protected autoSave: boolean; - protected autoBuildRoleLinks: boolean; - protected autoNotifyWatcher: boolean; - - public initialize(): void { - this.rm = new DefaultRoleManager(10); - this.eft = new DefaultEffector(); - this.matcherMap = new Map(); - this.watcher = null; - - this.enabled = true; - this.autoSave = true; - this.autoBuildRoleLinks = true; - this.autoNotifyWatcher = true; - } + protected rm: RoleManager = new DefaultRoleManager(10); + + protected enabled = true; + protected autoSave = true; + protected autoBuildRoleLinks = true; + protected autoNotifyWatcher = true; /** * loadModel reloads the model from the model CONF file. @@ -61,7 +49,6 @@ export class CoreEnforcer { this.model = newModel(); this.model.loadModel(this.modelPath); this.model.printModel(); - this.fm = FunctionMap.loadFunctionMap(); } /** @@ -80,7 +67,6 @@ export class CoreEnforcer { */ public setModel(m: Model): void { this.model = m; - this.fm = FunctionMap.loadFunctionMap(); } /** diff --git a/src/enforcer.ts b/src/enforcer.ts index e57c713..ea97f55 100644 --- a/src/enforcer.ts +++ b/src/enforcer.ts @@ -13,7 +13,7 @@ // limitations under the License. import { ManagementEnforcer } from './managementEnforcer'; -import { FunctionMap, Model, newModel } from './model'; +import { Model, newModel } from './model'; import { Adapter, FileAdapter, StringAdapter } from './persist'; import { getLogger } from './log'; @@ -65,12 +65,8 @@ export class Enforcer extends ManagementEnforcer { this.model = m; this.model.printModel(); - this.fm = FunctionMap.loadFunctionMap(); - - this.initialize(); if (this.adapter) { - // error intentionally ignored await this.loadPolicy(); } } diff --git a/test/model.test.ts b/test/model.test.ts index 5defe2c..cc32091 100644 --- a/test/model.test.ts +++ b/test/model.test.ts @@ -99,7 +99,6 @@ test('TestBasicModelWithoutUsers', async () => { test('TestBasicModelWithoutResources', async () => { const e = await newEnforcer('examples/basic_without_resources_model.conf', 'examples/basic_without_resources_policy.csv'); - e.initialize(); await testEnforceWithoutUsers(e, 'alice', 'read', true); await testEnforceWithoutUsers(e, 'alice', 'write', false);