|
|
@@ -1,15 +1,28 @@
|
|
|
-const { getInstance } = require('../setup-crowi');
|
|
|
+import { aclService } from './acl';
|
|
|
+import { configManager } from './config-manager';
|
|
|
+
|
|
|
+
|
|
|
+describe('AclService', () => {
|
|
|
+ test("has consts 'isLabeledStatement'", () => {
|
|
|
+ expect(aclService.labels.SECURITY_RESTRICT_GUEST_MODE_DENY).toBe('Deny');
|
|
|
+ expect(aclService.labels.SECURITY_RESTRICT_GUEST_MODE_READONLY).toBe('Readonly');
|
|
|
+ expect(aclService.labels.SECURITY_REGISTRATION_MODE_OPEN).toBe('Open');
|
|
|
+ expect(aclService.labels.SECURITY_REGISTRATION_MODE_RESTRICTED).toBe('Restricted');
|
|
|
+ expect(aclService.labels.SECURITY_REGISTRATION_MODE_CLOSED).toBe('Closed');
|
|
|
+ });
|
|
|
+});
|
|
|
|
|
|
describe('AclService test', () => {
|
|
|
- let crowi;
|
|
|
|
|
|
const initialEnv = process.env;
|
|
|
|
|
|
- beforeEach(async() => {
|
|
|
- crowi = await getInstance();
|
|
|
- process.env = initialEnv;
|
|
|
+ beforeAll(async() => {
|
|
|
+ await configManager.loadConfigs();
|
|
|
});
|
|
|
|
|
|
+ afterEach(() => {
|
|
|
+ process.env = initialEnv;
|
|
|
+ });
|
|
|
|
|
|
describe('isAclEnabled()', () => {
|
|
|
|
|
|
@@ -17,11 +30,11 @@ describe('AclService test', () => {
|
|
|
delete process.env.FORCE_WIKI_MODE;
|
|
|
|
|
|
// reload
|
|
|
- await crowi.configManager.loadConfigs();
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
|
- const result = crowi.aclService.isAclEnabled();
|
|
|
+ const result = aclService.isAclEnabled();
|
|
|
|
|
|
- const wikiMode = crowi.configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
+ const wikiMode = configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
expect(wikiMode).toBe(undefined);
|
|
|
expect(result).toBe(true);
|
|
|
});
|
|
|
@@ -30,11 +43,11 @@ describe('AclService test', () => {
|
|
|
process.env.FORCE_WIKI_MODE = 'dummy string';
|
|
|
|
|
|
// reload
|
|
|
- await crowi.configManager.loadConfigs();
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
|
- const result = crowi.aclService.isAclEnabled();
|
|
|
+ const result = aclService.isAclEnabled();
|
|
|
|
|
|
- const wikiMode = crowi.configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
+ const wikiMode = configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
expect(wikiMode).toBe('dummy string');
|
|
|
expect(result).toBe(true);
|
|
|
});
|
|
|
@@ -43,11 +56,11 @@ describe('AclService test', () => {
|
|
|
process.env.FORCE_WIKI_MODE = 'private';
|
|
|
|
|
|
// reload
|
|
|
- await crowi.configManager.loadConfigs();
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
|
- const result = crowi.aclService.isAclEnabled();
|
|
|
+ const result = aclService.isAclEnabled();
|
|
|
|
|
|
- const wikiMode = crowi.configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
+ const wikiMode = configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
expect(wikiMode).toBe('private');
|
|
|
expect(result).toBe(true);
|
|
|
});
|
|
|
@@ -56,11 +69,11 @@ describe('AclService test', () => {
|
|
|
process.env.FORCE_WIKI_MODE = 'public';
|
|
|
|
|
|
// reload
|
|
|
- await crowi.configManager.loadConfigs();
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
|
- const result = crowi.aclService.isAclEnabled();
|
|
|
+ const result = aclService.isAclEnabled();
|
|
|
|
|
|
- const wikiMode = crowi.configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
+ const wikiMode = configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
expect(wikiMode).toBe('public');
|
|
|
expect(result).toBe(false);
|
|
|
});
|
|
|
@@ -74,11 +87,11 @@ describe('AclService test', () => {
|
|
|
delete process.env.FORCE_WIKI_MODE;
|
|
|
|
|
|
// reload
|
|
|
- await crowi.configManager.loadConfigs();
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
|
- const result = crowi.aclService.isWikiModeForced();
|
|
|
+ const result = aclService.isWikiModeForced();
|
|
|
|
|
|
- const wikiMode = crowi.configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
+ const wikiMode = configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
expect(wikiMode).toBe(undefined);
|
|
|
expect(result).toBe(false);
|
|
|
});
|
|
|
@@ -87,11 +100,11 @@ describe('AclService test', () => {
|
|
|
process.env.FORCE_WIKI_MODE = 'dummy string';
|
|
|
|
|
|
// reload
|
|
|
- await crowi.configManager.loadConfigs();
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
|
- const result = crowi.aclService.isWikiModeForced();
|
|
|
+ const result = aclService.isWikiModeForced();
|
|
|
|
|
|
- const wikiMode = crowi.configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
+ const wikiMode = configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
expect(wikiMode).toBe('dummy string');
|
|
|
expect(result).toBe(false);
|
|
|
});
|
|
|
@@ -100,11 +113,11 @@ describe('AclService test', () => {
|
|
|
process.env.FORCE_WIKI_MODE = 'private';
|
|
|
|
|
|
// reload
|
|
|
- await crowi.configManager.loadConfigs();
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
|
- const result = crowi.aclService.isWikiModeForced();
|
|
|
+ const result = aclService.isWikiModeForced();
|
|
|
|
|
|
- const wikiMode = crowi.configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
+ const wikiMode = configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
expect(wikiMode).toBe('private');
|
|
|
expect(result).toBe(true);
|
|
|
});
|
|
|
@@ -113,11 +126,11 @@ describe('AclService test', () => {
|
|
|
process.env.FORCE_WIKI_MODE = 'public';
|
|
|
|
|
|
// reload
|
|
|
- await crowi.configManager.loadConfigs();
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
|
- const result = crowi.aclService.isWikiModeForced();
|
|
|
+ const result = aclService.isWikiModeForced();
|
|
|
|
|
|
- const wikiMode = crowi.configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
+ const wikiMode = configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
expect(wikiMode).toBe('public');
|
|
|
expect(result).toBe(true);
|
|
|
});
|
|
|
@@ -130,18 +143,18 @@ describe('AclService test', () => {
|
|
|
|
|
|
beforeEach(async() => {
|
|
|
// prepare spy for ConfigManager.getConfig
|
|
|
- getConfigSpy = jest.spyOn(crowi.configManager, 'getConfig');
|
|
|
+ getConfigSpy = vi.spyOn(configManager, 'getConfig');
|
|
|
});
|
|
|
|
|
|
test('to be false when FORCE_WIKI_MODE=private', async() => {
|
|
|
process.env.FORCE_WIKI_MODE = 'private';
|
|
|
|
|
|
// reload
|
|
|
- await crowi.configManager.loadConfigs();
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
|
- const result = crowi.aclService.isGuestAllowedToRead();
|
|
|
+ const result = aclService.isGuestAllowedToRead();
|
|
|
|
|
|
- const wikiMode = crowi.configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
+ const wikiMode = configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
expect(wikiMode).toBe('private');
|
|
|
expect(getConfigSpy).not.toHaveBeenCalledWith('crowi', 'security:restrictGuestMode');
|
|
|
expect(result).toBe(false);
|
|
|
@@ -151,11 +164,11 @@ describe('AclService test', () => {
|
|
|
process.env.FORCE_WIKI_MODE = 'public';
|
|
|
|
|
|
// reload
|
|
|
- await crowi.configManager.loadConfigs();
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
|
- const result = crowi.aclService.isGuestAllowedToRead();
|
|
|
+ const result = aclService.isGuestAllowedToRead();
|
|
|
|
|
|
- const wikiMode = crowi.configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
+ const wikiMode = configManager.getConfig('crowi', 'security:wikiMode');
|
|
|
expect(wikiMode).toBe('public');
|
|
|
expect(getConfigSpy).not.toHaveBeenCalledWith('crowi', 'security:restrictGuestMode');
|
|
|
expect(result).toBe(true);
|
|
|
@@ -174,7 +187,7 @@ describe('AclService test', () => {
|
|
|
test(`when FORCE_WIKI_MODE is undefined and 'security:restrictGuestMode' is '${restrictGuestMode}`, async() => {
|
|
|
|
|
|
// reload
|
|
|
- await crowi.configManager.loadConfigs();
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
|
// setup mock implementation
|
|
|
getConfigSpy.mockImplementation((ns, key) => {
|
|
|
@@ -187,7 +200,7 @@ describe('AclService test', () => {
|
|
|
throw new Error('Unexpected behavior.');
|
|
|
});
|
|
|
|
|
|
- const result = crowi.aclService.isGuestAllowedToRead();
|
|
|
+ const result = aclService.isGuestAllowedToRead();
|
|
|
|
|
|
expect(getConfigSpy).toHaveBeenCalledTimes(2);
|
|
|
expect(getConfigSpy).toHaveBeenCalledWith('crowi', 'security:wikiMode');
|