|
|
@@ -1,6 +1,10 @@
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
+import type { GrantedGroup } from '@growi/core';
|
|
|
import mongoose from 'mongoose';
|
|
|
|
|
|
+import { ExternalGroupProviderType } from '../../../src/features/external-user-group/interfaces/external-user-group';
|
|
|
+import ExternalUserGroup from '../../../src/features/external-user-group/server/models/external-user-group';
|
|
|
+import ExternalUserGroupRelation from '../../../src/features/external-user-group/server/models/external-user-group-relation';
|
|
|
import Tag from '../../../src/server/models/tag';
|
|
|
import UserGroup from '../../../src/server/models/user-group';
|
|
|
import UserGroupRelation from '../../../src/server/models/user-group-relation';
|
|
|
@@ -17,6 +21,10 @@ describe('PageService page operations with non-public pages', () => {
|
|
|
let groupIdA;
|
|
|
let groupIdB;
|
|
|
let groupIdC;
|
|
|
+ let externalGroupIdIsolate;
|
|
|
+ let externalGroupIdA;
|
|
|
+ let externalGroupIdB;
|
|
|
+ let externalGroupIdC;
|
|
|
let crowi;
|
|
|
let Page;
|
|
|
let Revision;
|
|
|
@@ -92,6 +100,13 @@ describe('PageService page operations with non-public pages', () => {
|
|
|
return createdPage;
|
|
|
};
|
|
|
|
|
|
+ const normalizeGrantedGroups = (grantedGroups: GrantedGroup[]) => {
|
|
|
+ return JSON.parse(JSON.stringify(grantedGroups)).map((group) => {
|
|
|
+ delete group._id;
|
|
|
+ return group;
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
beforeAll(async() => {
|
|
|
crowi = await getInstance();
|
|
|
await crowi.configManager.updateConfigsInTheSameNamespace('crowi', { 'app:isV5Compatible': true });
|
|
|
@@ -188,6 +203,82 @@ describe('PageService page operations with non-public pages', () => {
|
|
|
},
|
|
|
]);
|
|
|
|
|
|
+ externalGroupIdIsolate = new mongoose.Types.ObjectId();
|
|
|
+ externalGroupIdA = new mongoose.Types.ObjectId();
|
|
|
+ externalGroupIdB = new mongoose.Types.ObjectId();
|
|
|
+ externalGroupIdC = new mongoose.Types.ObjectId();
|
|
|
+ await ExternalUserGroup.insertMany([
|
|
|
+ {
|
|
|
+ _id: externalGroupIdIsolate,
|
|
|
+ name: 'np_externalGroupIsolate',
|
|
|
+ externalId: 'np_externalGroupIsolate',
|
|
|
+ provider: ExternalGroupProviderType.ldap,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ _id: externalGroupIdA,
|
|
|
+ name: 'np_externalGroupA',
|
|
|
+ externalId: 'np_externalGroupA',
|
|
|
+ provider: ExternalGroupProviderType.ldap,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ _id: externalGroupIdB,
|
|
|
+ name: 'np_externalGroupB',
|
|
|
+ externalId: 'np_externalGroupB',
|
|
|
+ parent: externalGroupIdA,
|
|
|
+ provider: ExternalGroupProviderType.ldap,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ _id: externalGroupIdC,
|
|
|
+ name: 'np_externalGroupC',
|
|
|
+ externalId: 'np_externalGroupC',
|
|
|
+ parent: externalGroupIdB,
|
|
|
+ provider: ExternalGroupProviderType.ldap,
|
|
|
+ },
|
|
|
+ ]);
|
|
|
+
|
|
|
+ await ExternalUserGroupRelation.insertMany([
|
|
|
+ {
|
|
|
+ relatedGroup: externalGroupIdIsolate,
|
|
|
+ relatedUser: npUserId1,
|
|
|
+ createdAt: new Date(),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ relatedGroup: externalGroupIdIsolate,
|
|
|
+ relatedUser: npUserId2,
|
|
|
+ createdAt: new Date(),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ relatedGroup: externalGroupIdA,
|
|
|
+ relatedUser: npUserId1,
|
|
|
+ createdAt: new Date(),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ relatedGroup: externalGroupIdA,
|
|
|
+ relatedUser: npUserId2,
|
|
|
+ createdAt: new Date(),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ relatedGroup: externalGroupIdA,
|
|
|
+ relatedUser: npUserId3,
|
|
|
+ createdAt: new Date(),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ relatedGroup: externalGroupIdB,
|
|
|
+ relatedUser: npUserId2,
|
|
|
+ createdAt: new Date(),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ relatedGroup: externalGroupIdB,
|
|
|
+ relatedUser: npUserId3,
|
|
|
+ createdAt: new Date(),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ relatedGroup: externalGroupIdC,
|
|
|
+ relatedUser: npUserId3,
|
|
|
+ createdAt: new Date(),
|
|
|
+ },
|
|
|
+ ]);
|
|
|
+
|
|
|
xssSpy = jest.spyOn(crowi.xss, 'process').mockImplementation(path => path);
|
|
|
|
|
|
dummyUser1 = await User.findOne({ username: 'v5DummyUser1' });
|
|
|
@@ -913,8 +1004,8 @@ describe('PageService page operations with non-public pages', () => {
|
|
|
expect(page3Renamed).toBeTruthy();
|
|
|
expect(page2Renamed.parent).toStrictEqual(_pageD._id);
|
|
|
expect(page3Renamed.parent).toStrictEqual(page2Renamed._id);
|
|
|
- expect(page2Renamed.grantedGroup).toStrictEqual(_page2.grantedGroup);
|
|
|
- expect(page3Renamed.grantedGroup).toStrictEqual(_page3.grantedGroup);
|
|
|
+ expect(normalizeGrantedGroups(page2Renamed.grantedGroups)).toStrictEqual(normalizeGrantedGroups(_page2.grantedGroups));
|
|
|
+ expect(normalizeGrantedGroups(page3Renamed.grantedGroups)).toStrictEqual(normalizeGrantedGroups(_page3.grantedGroups));
|
|
|
expect(xssSpy).toHaveBeenCalled();
|
|
|
});
|
|
|
test('Should throw with NOT grant normalized pages', async() => {
|
|
|
@@ -1052,16 +1143,8 @@ describe('PageService page operations with non-public pages', () => {
|
|
|
expect(duplicatedPage2).toBeTruthy();
|
|
|
expect(duplicatedRevision1).toBeTruthy();
|
|
|
expect(duplicatedRevision2).toBeTruthy();
|
|
|
- const grantedGroups1 = JSON.parse(JSON.stringify(duplicatedPage1.grantedGroups)).map((group) => {
|
|
|
- delete group._id;
|
|
|
- return group;
|
|
|
- });
|
|
|
- const grantedGroups2 = JSON.parse(JSON.stringify(duplicatedPage2.grantedGroups)).map((group) => {
|
|
|
- delete group._id;
|
|
|
- return group;
|
|
|
- });
|
|
|
- expect(grantedGroups1).toStrictEqual([{ item: groupIdA._id.toString(), type: 'UserGroup' }]);
|
|
|
- expect(grantedGroups2).toStrictEqual([{ item: groupIdB._id.toString(), type: 'UserGroup' }]);
|
|
|
+ expect(normalizeGrantedGroups(duplicatedPage1.grantedGroups)).toStrictEqual([{ item: groupIdA._id.toString(), type: 'UserGroup' }]);
|
|
|
+ expect(normalizeGrantedGroups(duplicatedPage2.grantedGroups)).toStrictEqual([{ item: groupIdB._id.toString(), type: 'UserGroup' }]);
|
|
|
expect(duplicatedPage1.parent).toStrictEqual(_page1.parent);
|
|
|
expect(duplicatedPage2.parent).toStrictEqual(duplicatedPage1._id);
|
|
|
expect(duplicatedRevision1.body).toBe(_revision1.body);
|
|
|
@@ -1366,11 +1449,7 @@ describe('PageService page operations with non-public pages', () => {
|
|
|
expect(revertedPage.parent).toStrictEqual(rootPage._id);
|
|
|
expect(revertedPage.status).toBe(Page.STATUS_PUBLISHED);
|
|
|
expect(revertedPage.grant).toBe(Page.GRANT_USER_GROUP);
|
|
|
- const grantedGroups = JSON.parse(JSON.stringify(revertedPage.grantedGroups)).map((group) => {
|
|
|
- delete group._id;
|
|
|
- return group;
|
|
|
- });
|
|
|
- expect(grantedGroups).toStrictEqual([{ item: groupIdA.toString(), type: 'UserGroup' }]);
|
|
|
+ expect(normalizeGrantedGroups(revertedPage.grantedGroups)).toStrictEqual([{ item: groupIdA.toString(), type: 'UserGroup' }]);
|
|
|
expect(pageTagRelation.isPageTrashed).toBe(false);
|
|
|
});
|
|
|
test(`revert multiple pages: only target page should be reverted.
|
|
|
@@ -1452,16 +1531,8 @@ describe('PageService page operations with non-public pages', () => {
|
|
|
expect(revertedPage1.status).toBe(Page.STATUS_PUBLISHED);
|
|
|
expect(revertedPage2.status).toBe(Page.STATUS_PUBLISHED);
|
|
|
expect(newlyCreatedPage.status).toBe(Page.STATUS_PUBLISHED);
|
|
|
- const grantedGroups1 = JSON.parse(JSON.stringify(revertedPage1.grantedGroups)).map((group) => {
|
|
|
- delete group._id;
|
|
|
- return group;
|
|
|
- });
|
|
|
- const grantedGroups2 = JSON.parse(JSON.stringify(revertedPage2.grantedGroups)).map((group) => {
|
|
|
- delete group._id;
|
|
|
- return group;
|
|
|
- });
|
|
|
- expect(grantedGroups1).toStrictEqual([{ item: groupIdA.toString(), type: 'UserGroup' }]);
|
|
|
- expect(grantedGroups2).toStrictEqual([{ item: groupIdB.toString(), type: 'UserGroup' }]);
|
|
|
+ expect(normalizeGrantedGroups(revertedPage1.grantedGroups)).toStrictEqual([{ item: groupIdA.toString(), type: 'UserGroup' }]);
|
|
|
+ expect(normalizeGrantedGroups(revertedPage2.grantedGroups)).toStrictEqual([{ item: groupIdB.toString(), type: 'UserGroup' }]);
|
|
|
expect(newlyCreatedPage.grant).toBe(Page.GRANT_PUBLIC);
|
|
|
|
|
|
});
|