|
@@ -1,15 +1,13 @@
|
|
|
import ldap, { Client } from 'ldapjs';
|
|
import ldap, { Client } from 'ldapjs';
|
|
|
|
|
|
|
|
-import LdapUserGroupSyncService from '../../../src/features/external-user-group/server/service/ldap-user-group-sync';
|
|
|
|
|
|
|
+import { ldapUserGroupSyncService, instanciate } from '../../../src/features/external-user-group/server/service/ldap-user-group-sync';
|
|
|
import { configManager } from '../../../src/server/service/config-manager';
|
|
import { configManager } from '../../../src/server/service/config-manager';
|
|
|
import LdapService from '../../../src/server/service/ldap';
|
|
import LdapService from '../../../src/server/service/ldap';
|
|
|
import PassportService from '../../../src/server/service/passport';
|
|
import PassportService from '../../../src/server/service/passport';
|
|
|
import { getInstance } from '../setup-crowi';
|
|
import { getInstance } from '../setup-crowi';
|
|
|
|
|
|
|
|
-
|
|
|
|
|
describe('LdapUserGroupSyncService.generateExternalUserGroupTrees', () => {
|
|
describe('LdapUserGroupSyncService.generateExternalUserGroupTrees', () => {
|
|
|
let crowi;
|
|
let crowi;
|
|
|
- let ldapGroupSyncService: LdapUserGroupSyncService;
|
|
|
|
|
|
|
|
|
|
const configParams = {
|
|
const configParams = {
|
|
|
'security:passport-ldap:attrMapName': 'name',
|
|
'security:passport-ldap:attrMapName': 'name',
|
|
@@ -37,7 +35,7 @@ describe('LdapUserGroupSyncService.generateExternalUserGroupTrees', () => {
|
|
|
mockLdapCreateClient.mockImplementation(() => { return {} as Client });
|
|
mockLdapCreateClient.mockImplementation(() => { return {} as Client });
|
|
|
|
|
|
|
|
const passportService = new PassportService(crowi);
|
|
const passportService = new PassportService(crowi);
|
|
|
- ldapGroupSyncService = new LdapUserGroupSyncService(passportService);
|
|
|
|
|
|
|
+ instanciate(passportService, null);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
describe('When there is no circular reference in group tree', () => {
|
|
describe('When there is no circular reference in group tree', () => {
|
|
@@ -150,12 +148,12 @@ describe('LdapUserGroupSyncService.generateExternalUserGroupTrees', () => {
|
|
|
return Promise.reject(new Error('not found'));
|
|
return Promise.reject(new Error('not found'));
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- const rootNodes = await ldapGroupSyncService.generateExternalUserGroupTrees();
|
|
|
|
|
|
|
+ const rootNodes = await ldapUserGroupSyncService?.generateExternalUserGroupTrees();
|
|
|
|
|
|
|
|
- expect(rootNodes.length).toBe(2);
|
|
|
|
|
|
|
+ expect(rootNodes?.length).toBe(2);
|
|
|
|
|
|
|
|
// check grandParentGroup
|
|
// check grandParentGroup
|
|
|
- const grandParentNode = rootNodes.find(node => node.id === 'cn=grandParentGroup,ou=groups,dc=example,dc=org');
|
|
|
|
|
|
|
+ const grandParentNode = rootNodes?.find(node => node.id === 'cn=grandParentGroup,ou=groups,dc=example,dc=org');
|
|
|
const expectedChildNode = {
|
|
const expectedChildNode = {
|
|
|
id: 'cn=childGroup,ou=groups,dc=example,dc=org',
|
|
id: 'cn=childGroup,ou=groups,dc=example,dc=org',
|
|
|
userInfos: [{
|
|
userInfos: [{
|
|
@@ -195,7 +193,7 @@ describe('LdapUserGroupSyncService.generateExternalUserGroupTrees', () => {
|
|
|
expect(grandParentNode).toStrictEqual(expectedGrandParentNode);
|
|
expect(grandParentNode).toStrictEqual(expectedGrandParentNode);
|
|
|
|
|
|
|
|
// check rootGroup
|
|
// check rootGroup
|
|
|
- const rootNode = rootNodes.find(node => node.id === 'cn=rootGroup,ou=groups,dc=example,dc=org');
|
|
|
|
|
|
|
+ const rootNode = rootNodes?.find(node => node.id === 'cn=rootGroup,ou=groups,dc=example,dc=org');
|
|
|
const expectedRootNode = {
|
|
const expectedRootNode = {
|
|
|
id: 'cn=rootGroup,ou=groups,dc=example,dc=org',
|
|
id: 'cn=rootGroup,ou=groups,dc=example,dc=org',
|
|
|
userInfos: [{
|
|
userInfos: [{
|
|
@@ -258,7 +256,7 @@ describe('LdapUserGroupSyncService.generateExternalUserGroupTrees', () => {
|
|
|
return Promise.reject(new Error('not found'));
|
|
return Promise.reject(new Error('not found'));
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- await expect(ldapGroupSyncService.generateExternalUserGroupTrees()).rejects.toThrow('external_user_group.ldap.circular_reference');
|
|
|
|
|
|
|
+ await expect(ldapUserGroupSyncService?.generateExternalUserGroupTrees()).rejects.toThrow('external_user_group.ldap.circular_reference');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|