Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
119 lines
4.5 KiB
TypeScript
119 lines
4.5 KiB
TypeScript
import { expect } from 'chai';
|
|
import { before, describe, it, after } from 'mocha';
|
|
|
|
import { getCredentials, api, request, credentials, methodCall } from '../../data/api-data';
|
|
import { restorePermissionToRoles } from '../../data/permissions.helper';
|
|
import { IS_EE } from '../../e2e/config/constants';
|
|
|
|
(IS_EE ? describe : describe.skip)('[Guest Permissions]', () => {
|
|
const guestPermissions = ['view-d-room', 'view-joined-room', 'view-p-room', 'start-discussion', 'mobile-upload-file'];
|
|
|
|
before((done) => getCredentials(done));
|
|
|
|
after(() => Promise.all(guestPermissions.map((permissionName) => restorePermissionToRoles(permissionName))));
|
|
|
|
function succeedRemoveGuestPermission(permissionName: string) {
|
|
it(`should allow removing the whitelisted permission ${permissionName} from the guest role`, async () => {
|
|
const res = await request
|
|
.post(methodCall('authorization:removeRoleFromPermission'))
|
|
.set(credentials)
|
|
.send({
|
|
message: JSON.stringify({
|
|
method: 'authorization:removeRoleFromPermission',
|
|
params: [permissionName, 'guest'],
|
|
id: 'id',
|
|
msg: 'method',
|
|
}),
|
|
})
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(200);
|
|
|
|
expect(res.body).to.have.property('success', true);
|
|
expect(res.body).to.have.property('message');
|
|
const message = JSON.parse(res.body.message);
|
|
expect(message).to.not.have.property('error');
|
|
|
|
const permissionsListRes = await request
|
|
.get(api('permissions.listAll'))
|
|
.set(credentials)
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(200);
|
|
expect(permissionsListRes.body).to.have.property('success', true);
|
|
expect(permissionsListRes.body).to.have.property('update').and.to.be.an('array');
|
|
expect(permissionsListRes.body).to.have.property('remove').and.to.be.an('array');
|
|
|
|
const updatedPermission = permissionsListRes.body.update.find((permission: any) => permission._id === permissionName);
|
|
expect(updatedPermission).to.have.property('_id', permissionName);
|
|
expect(updatedPermission).to.have.property('roles').and.to.be.an('array').that.does.not.include('guest');
|
|
});
|
|
}
|
|
|
|
function succeedAddGuestPermission(permissionName: string) {
|
|
it(`should allow granting the whitelisted permission ${permissionName} to the guest role`, async () => {
|
|
const res = await request
|
|
.post(methodCall('authorization:addPermissionToRole'))
|
|
.set(credentials)
|
|
.send({
|
|
message: JSON.stringify({
|
|
method: 'authorization:addPermissionToRole',
|
|
params: [permissionName, 'guest'],
|
|
id: 'id',
|
|
msg: 'method',
|
|
}),
|
|
})
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(200);
|
|
|
|
expect(res.body).to.have.property('success', true);
|
|
expect(res.body).to.have.property('message');
|
|
const message = JSON.parse(res.body.message);
|
|
expect(message).to.not.have.property('error');
|
|
|
|
const permissionsListRes = await request
|
|
.get(api('permissions.listAll'))
|
|
.set(credentials)
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(200);
|
|
expect(permissionsListRes.body).to.have.property('success', true);
|
|
expect(permissionsListRes.body).to.have.property('update').and.to.be.an('array');
|
|
expect(permissionsListRes.body).to.have.property('remove').and.to.be.an('array');
|
|
|
|
const updatedPermission = permissionsListRes.body.update.find((permission: any) => permission._id === permissionName);
|
|
expect(updatedPermission).to.have.property('_id', permissionName);
|
|
expect(updatedPermission).to.have.property('roles').and.to.be.an('array').that.includes('guest');
|
|
});
|
|
}
|
|
|
|
describe('Default guest roles', () => {
|
|
guestPermissions.forEach((permissionName) => {
|
|
succeedRemoveGuestPermission(permissionName);
|
|
});
|
|
|
|
guestPermissions.forEach((permissionName) => {
|
|
succeedAddGuestPermission(permissionName);
|
|
});
|
|
|
|
it('should not allow adding a non whitelisted permission to the guest role', async () => {
|
|
const res = await request
|
|
.post(methodCall('authorization:addPermissionToRole'))
|
|
.set(credentials)
|
|
.send({
|
|
message: JSON.stringify({
|
|
method: 'authorization:addPermissionToRole',
|
|
params: ['create-c', 'guest'],
|
|
id: 'id',
|
|
msg: 'method',
|
|
}),
|
|
})
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400);
|
|
|
|
expect(res.body).to.have.property('success', false);
|
|
expect(res.body).to.have.property('message');
|
|
const message = JSON.parse(res.body.message);
|
|
expect(message).to.have.property('error');
|
|
expect(message.error).to.have.property('reason', 'Permission is restricted');
|
|
});
|
|
});
|
|
});
|