Skip to content

Commit

Permalink
feat: Release floating entitlements on license:clear command (no-chan…
Browse files Browse the repository at this point in the history
…gelog) (#9603)

Co-authored-by: Iván Ovejero <[email protected]>
  • Loading branch information
2 people authored and RicardoE105 committed Jun 9, 2024
1 parent 39ddaac commit 8f93b0b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/cli/src/commands/license/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Container } from 'typedi';
import { SETTINGS_LICENSE_CERT_KEY } from '@/constants';
import { BaseCommand } from '../BaseCommand';
import { SettingsRepository } from '@db/repositories/settings.repository';
import { License } from '@/License';

export class ClearLicenseCommand extends BaseCommand {
static description = 'Clear license';
Expand All @@ -10,6 +11,12 @@ export class ClearLicenseCommand extends BaseCommand {

async run() {
this.logger.info('Clearing license from database.');

// Invoke shutdown() to force any floating entitlements to be released
const license = Container.get(License);
await license.init();
await license.shutdown();

await Container.get(SettingsRepository).delete({
key: SETTINGS_LICENSE_CERT_KEY,
});
Expand Down
28 changes: 28 additions & 0 deletions packages/cli/test/integration/commands/license.cmd.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { InternalHooks } from '@/InternalHooks';
import { License } from '@/License';
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
import { ClearLicenseCommand } from '@/commands/license/clear';
import { Config } from '@oclif/core';
import { mockInstance } from '../../shared/mocking';

const oclifConfig = new Config({ root: __dirname });

beforeAll(async () => {
mockInstance(InternalHooks);
mockInstance(LoadNodesAndCredentials);
await oclifConfig.load();
});

test('license:clear invokes shutdown() to release any floating entitlements', async () => {
const cmd = new ClearLicenseCommand([], oclifConfig);
await cmd.init();

const license = mockInstance(License);

await cmd.run();

expect(license.init).toHaveBeenCalledTimes(1);
expect(license.shutdown).toHaveBeenCalledTimes(1);

jest.restoreAllMocks();
});

0 comments on commit 8f93b0b

Please sign in to comment.