mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(core): Fix license CLI commands showing incorrect renewal setting (#12759)
This commit is contained in:
@@ -251,6 +251,20 @@ describe('License', () => {
|
||||
|
||||
expect(LicenseManager).toHaveBeenCalledWith(expect.objectContaining(expectedRenewalSettings));
|
||||
});
|
||||
|
||||
it('when CLI command with N8N_LICENSE_AUTO_RENEW_ENABLED=true, should enable renewal', async () => {
|
||||
const globalConfig = mock<GlobalConfig>({
|
||||
license: { ...licenseConfig, autoRenewalEnabled: true },
|
||||
});
|
||||
|
||||
await new License(mockLogger(), mock(), mock(), mock(), globalConfig).init({
|
||||
isCli: true,
|
||||
});
|
||||
|
||||
expect(LicenseManager).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ autoRenewEnabled: true, renewOnInit: true }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('reinit', () => {
|
||||
@@ -262,7 +276,7 @@ describe('License', () => {
|
||||
|
||||
await license.reinit();
|
||||
|
||||
expect(initSpy).toHaveBeenCalledWith(true);
|
||||
expect(initSpy).toHaveBeenCalledWith({ forceRecreate: true });
|
||||
|
||||
expect(LicenseManager.prototype.reset).toHaveBeenCalled();
|
||||
expect(LicenseManager.prototype.initialize).toHaveBeenCalled();
|
||||
|
||||
@@ -16,7 +16,7 @@ export class ClearLicenseCommand extends BaseCommand {
|
||||
|
||||
// Attempt to invoke shutdown() to force any floating entitlements to be released
|
||||
const license = Container.get(License);
|
||||
await license.init();
|
||||
await license.init({ isCli: true });
|
||||
try {
|
||||
await license.shutdown();
|
||||
} catch {
|
||||
|
||||
@@ -11,7 +11,7 @@ export class LicenseInfoCommand extends BaseCommand {
|
||||
|
||||
async run() {
|
||||
const license = Container.get(License);
|
||||
await license.init();
|
||||
await license.init({ isCli: true });
|
||||
|
||||
this.logger.info('Printing license information:\n' + license.getInfo());
|
||||
}
|
||||
|
||||
@@ -43,7 +43,10 @@ export class License {
|
||||
this.logger = this.logger.scoped('license');
|
||||
}
|
||||
|
||||
async init(forceRecreate = false) {
|
||||
async init({
|
||||
forceRecreate = false,
|
||||
isCli = false,
|
||||
}: { forceRecreate?: boolean; isCli?: boolean } = {}) {
|
||||
if (this.manager && !forceRecreate) {
|
||||
this.logger.warn('License manager already initialized or shutting down');
|
||||
return;
|
||||
@@ -73,10 +76,13 @@ export class License {
|
||||
|
||||
const { isLeader } = this.instanceSettings;
|
||||
const { autoRenewalEnabled } = this.globalConfig.license;
|
||||
const eligibleToRenew = isCli || isLeader;
|
||||
|
||||
const shouldRenew = isLeader && autoRenewalEnabled;
|
||||
const shouldRenew = eligibleToRenew && autoRenewalEnabled;
|
||||
|
||||
if (isLeader && !autoRenewalEnabled) this.logger.warn(LICENSE_RENEWAL_DISABLED_WARNING);
|
||||
if (eligibleToRenew && !autoRenewalEnabled) {
|
||||
this.logger.warn(LICENSE_RENEWAL_DISABLED_WARNING);
|
||||
}
|
||||
|
||||
try {
|
||||
this.manager = new LicenseManager({
|
||||
@@ -390,7 +396,7 @@ export class License {
|
||||
|
||||
async reinit() {
|
||||
this.manager?.reset();
|
||||
await this.init(true);
|
||||
await this.init({ forceRecreate: true });
|
||||
this.logger.debug('License reinitialized');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user