Skip to content

Commit

Permalink
fix(core): Allow license:clear command to be used for licenses that f…
Browse files Browse the repository at this point in the history
…ailed renewal (#10665)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <[email protected]>
  • Loading branch information
2 people authored and riascho committed Sep 23, 2024
1 parent 939f9de commit d21f4a3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
8 changes: 6 additions & 2 deletions packages/cli/src/commands/license/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ export class ClearLicenseCommand extends BaseCommand {
async run() {
this.logger.info('Clearing license from database.');

// Invoke shutdown() to force any floating entitlements to be released
// Attempt to invoke shutdown() to force any floating entitlements to be released
const license = Container.get(License);
await license.init();
await license.shutdown();
try {
await license.shutdown();
} catch {
this.logger.info('License shutdown failed. Continuing with clearing license from database.');
}

await Container.get(SettingsRepository).delete({
key: SETTINGS_LICENSE_CERT_KEY,
Expand Down
24 changes: 21 additions & 3 deletions packages/cli/test/integration/commands/license.cmd.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { License } from '@/license';
import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials';
import { ClearLicenseCommand } from '@/commands/license/clear';
import { Container } from 'typedi';

import { setupTestCommand } from '@test-integration/utils/test-command';
import { mockInstance } from '../../shared/mocking';

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';

mockInstance(LoadNodesAndCredentials);
const license = mockInstance(License);
const command = setupTestCommand(ClearLicenseCommand);
Expand All @@ -15,3 +19,17 @@ test('license:clear invokes shutdown() to release any floating entitlements', as
expect(license.init).toHaveBeenCalledTimes(1);
expect(license.shutdown).toHaveBeenCalledTimes(1);
});

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,
});
});

0 comments on commit d21f4a3

Please sign in to comment.