feat(core): Make detaching floatable entitlements on shutdown configurable (#14266)

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
Cornelius Suermann
2025-04-04 17:35:32 +02:00
committed by GitHub
parent 39e2d35a71
commit c9565fc0be
9 changed files with 55 additions and 48 deletions

View File

@@ -1,8 +1,6 @@
import { Container } from '@n8n/di';
import { ClearLicenseCommand } from '@/commands/license/clear';
import { SETTINGS_LICENSE_CERT_KEY } from '@/constants';
import { SettingsRepository } from '@/databases/repositories/settings.repository';
import { License } from '@/license';
import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials';
import { setupTestCommand } from '@test-integration/utils/test-command';
@@ -10,26 +8,30 @@ import { setupTestCommand } from '@test-integration/utils/test-command';
import { mockInstance } from '../../shared/mocking';
mockInstance(LoadNodesAndCredentials);
const license = mockInstance(License);
const command = setupTestCommand(ClearLicenseCommand);
test('license:clear invokes shutdown() to release any floating entitlements', async () => {
await command.run();
test('license:clear invokes clear() to release any floating entitlements and deletes the license cert from the DB', async () => {
const license = Container.get(License);
expect(license.init).toHaveBeenCalledTimes(1);
expect(license.shutdown).toHaveBeenCalledTimes(1);
});
const manager = {
clear: jest.fn().mockImplementation(async () => {
await license.saveCertStr('');
}),
};
test('license:clear deletes the license from the DB even if shutdown() fails', async () => {
license.shutdown.mockRejectedValueOnce(new Error('shutdown failed'));
const settingsRepository = Container.get(SettingsRepository);
settingsRepository.delete = jest.fn();
await command.run();
expect(settingsRepository.delete).toHaveBeenCalledWith({
key: SETTINGS_LICENSE_CERT_KEY,
const initSpy = jest.spyOn(license, 'init').mockImplementation(async () => {
Object.defineProperty(license, 'manager', {
value: manager,
writable: true,
});
});
const clearSpy = jest.spyOn(license, 'clear');
const saveCertStrSpy = jest.spyOn(license, 'saveCertStr');
await command.run();
expect(initSpy).toHaveBeenCalledTimes(1);
expect(clearSpy).toHaveBeenCalledTimes(1);
expect(saveCertStrSpy).toHaveBeenCalledWith('');
});