snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
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
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
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { expect } from 'chai';
|
||||
import proxyquire from 'proxyquire';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import { applyAirGappedRestrictionsValidation } from '../../../../../server/lib/cloud/license/airGappedRestrictionsWrapper';
|
||||
|
||||
let restrictionFlag = true;
|
||||
|
||||
const airgappedModule = {
|
||||
get restricted() {
|
||||
return restrictionFlag;
|
||||
},
|
||||
};
|
||||
|
||||
proxyquire.noCallThru().load('../../../../server/patches/airGappedRestrictionsWrapper.ts', {
|
||||
'@rocket.chat/license': {
|
||||
AirGappedRestriction: airgappedModule,
|
||||
},
|
||||
'../../../server/lib/cloud/license/airGappedRestrictionsWrapper': {
|
||||
applyAirGappedRestrictionsValidation,
|
||||
},
|
||||
});
|
||||
|
||||
describe('#airGappedRestrictionsWrapper()', () => {
|
||||
it('should throw an error when the workspace is restricted', async () => {
|
||||
await expect(applyAirGappedRestrictionsValidation(sinon.stub())).to.be.rejectedWith('restricted-workspace');
|
||||
});
|
||||
it('should NOT throw an error when the workspace is not restricted', async () => {
|
||||
restrictionFlag = false;
|
||||
const spy = sinon.stub();
|
||||
await expect(applyAirGappedRestrictionsValidation(spy)).to.eventually.equal(undefined);
|
||||
expect(spy.calledOnce).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
import { Emitter } from '@rocket.chat/emitter';
|
||||
import { registerModel } from '@rocket.chat/models';
|
||||
import { expect } from 'chai';
|
||||
import proxyquire from 'proxyquire';
|
||||
import sinon from 'sinon';
|
||||
|
||||
let promises: Array<Promise<any>> = [];
|
||||
|
||||
class AirgappedRestriction extends Emitter<{ remainingDays: { days: number } }> {
|
||||
computeRestriction = sinon.spy();
|
||||
|
||||
isWarningPeriod = sinon.stub();
|
||||
|
||||
override on(type: any, cb: any): any {
|
||||
const newCb = (...args: any) => {
|
||||
promises.push(cb(...args));
|
||||
};
|
||||
return super.on(type, newCb);
|
||||
}
|
||||
}
|
||||
|
||||
const airgappedRestrictionObj = new AirgappedRestriction();
|
||||
|
||||
const mocks = {
|
||||
sendMessagesToAdmins: ({ msgs }: any) => {
|
||||
msgs({ adminUser: { language: 'pt-br' } });
|
||||
},
|
||||
settingsUpdate: sinon.spy(),
|
||||
notifySetting: sinon.spy(),
|
||||
i18n: sinon.spy(),
|
||||
findLastToken: sinon.stub(),
|
||||
};
|
||||
|
||||
const licenseMock = {
|
||||
validateCb: async () => undefined,
|
||||
removeCb: async () => undefined,
|
||||
onValidateLicense: async (cb: any) => {
|
||||
licenseMock.validateCb = cb;
|
||||
},
|
||||
onRemoveLicense: async (cb: any) => {
|
||||
licenseMock.removeCb = cb;
|
||||
},
|
||||
};
|
||||
|
||||
registerModel('IServerEventsModel', {
|
||||
insertOne: () => undefined,
|
||||
createAuditServerEvent: () => undefined,
|
||||
} as any);
|
||||
|
||||
proxyquire.noCallThru().load('../../../../server/lib/license/airGappedRestrictions.ts', {
|
||||
'@rocket.chat/license': {
|
||||
AirGappedRestriction: airgappedRestrictionObj,
|
||||
License: licenseMock,
|
||||
},
|
||||
'@rocket.chat/models': {
|
||||
Settings: {
|
||||
updateValueById: mocks.settingsUpdate,
|
||||
},
|
||||
Statistics: {
|
||||
findLastStatsToken: mocks.findLastToken,
|
||||
},
|
||||
},
|
||||
'../../../../server/lib/notifyListener': {
|
||||
notifyOnSettingChangedById: mocks.notifySetting,
|
||||
},
|
||||
'../../../../server/lib/i18n': {
|
||||
i18n: {
|
||||
t: mocks.i18n,
|
||||
},
|
||||
},
|
||||
'../../../../server/lib/sendMessagesToAdmins': {
|
||||
sendMessagesToAdmins: mocks.sendMessagesToAdmins,
|
||||
},
|
||||
});
|
||||
|
||||
describe('airgappedRestrictions', () => {
|
||||
afterEach(() => {
|
||||
Object.values(mocks).forEach((mock) => {
|
||||
if ('resetHistory' in mock) {
|
||||
mock.resetHistory();
|
||||
}
|
||||
if ('reset' in mock) {
|
||||
mock.reset();
|
||||
}
|
||||
});
|
||||
airgappedRestrictionObj.computeRestriction.resetHistory();
|
||||
airgappedRestrictionObj.isWarningPeriod.reset();
|
||||
promises = [];
|
||||
});
|
||||
it('should update setting when restriction is removed', async () => {
|
||||
airgappedRestrictionObj.emit('remainingDays', { days: -1 });
|
||||
|
||||
await Promise.all(promises);
|
||||
expect(mocks.settingsUpdate.calledWith('Cloud_Workspace_AirGapped_Restrictions_Remaining_Days', -1)).to.be.true;
|
||||
expect(mocks.notifySetting.calledWith('Cloud_Workspace_AirGapped_Restrictions_Remaining_Days')).to.be.true;
|
||||
expect(airgappedRestrictionObj.isWarningPeriod.called).to.be.false;
|
||||
});
|
||||
|
||||
it('should update setting when restriction is applied', async () => {
|
||||
airgappedRestrictionObj.emit('remainingDays', { days: 0 });
|
||||
|
||||
await Promise.all(promises);
|
||||
expect(mocks.settingsUpdate.calledWith('Cloud_Workspace_AirGapped_Restrictions_Remaining_Days', 0)).to.be.true;
|
||||
expect(mocks.notifySetting.calledWith('Cloud_Workspace_AirGapped_Restrictions_Remaining_Days')).to.be.true;
|
||||
expect(airgappedRestrictionObj.isWarningPeriod.called).to.be.false;
|
||||
});
|
||||
|
||||
it('should update setting and send rocket.cat message when in warning period', async () => {
|
||||
airgappedRestrictionObj.emit('remainingDays', { days: 1 });
|
||||
airgappedRestrictionObj.isWarningPeriod.returns(true);
|
||||
|
||||
await Promise.all(promises);
|
||||
expect(mocks.settingsUpdate.calledWith('Cloud_Workspace_AirGapped_Restrictions_Remaining_Days', 1)).to.be.true;
|
||||
expect(mocks.notifySetting.calledWith('Cloud_Workspace_AirGapped_Restrictions_Remaining_Days')).to.be.true;
|
||||
expect(airgappedRestrictionObj.isWarningPeriod.called).to.be.true;
|
||||
expect(mocks.i18n.calledWith('AirGapped_Restriction_Warning', { lng: 'pt-br' }));
|
||||
});
|
||||
|
||||
it('should recompute restriction if license is applied', async () => {
|
||||
mocks.findLastToken.returns('token');
|
||||
await licenseMock.validateCb();
|
||||
expect(mocks.findLastToken.calledOnce).to.be.true;
|
||||
expect(airgappedRestrictionObj.computeRestriction.calledWith('token')).to.be.true;
|
||||
});
|
||||
|
||||
it('should recompute restriction if license is removed', async () => {
|
||||
mocks.findLastToken.returns('token');
|
||||
await licenseMock.removeCb();
|
||||
expect(mocks.findLastToken.calledOnce).to.be.true;
|
||||
expect(airgappedRestrictionObj.computeRestriction.calledWith('token')).to.be.true;
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user