mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 18:41:14 +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));
|
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', () => {
|
describe('reinit', () => {
|
||||||
@@ -262,7 +276,7 @@ describe('License', () => {
|
|||||||
|
|
||||||
await license.reinit();
|
await license.reinit();
|
||||||
|
|
||||||
expect(initSpy).toHaveBeenCalledWith(true);
|
expect(initSpy).toHaveBeenCalledWith({ forceRecreate: true });
|
||||||
|
|
||||||
expect(LicenseManager.prototype.reset).toHaveBeenCalled();
|
expect(LicenseManager.prototype.reset).toHaveBeenCalled();
|
||||||
expect(LicenseManager.prototype.initialize).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
|
// Attempt to invoke shutdown() to force any floating entitlements to be released
|
||||||
const license = Container.get(License);
|
const license = Container.get(License);
|
||||||
await license.init();
|
await license.init({ isCli: true });
|
||||||
try {
|
try {
|
||||||
await license.shutdown();
|
await license.shutdown();
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export class LicenseInfoCommand extends BaseCommand {
|
|||||||
|
|
||||||
async run() {
|
async run() {
|
||||||
const license = Container.get(License);
|
const license = Container.get(License);
|
||||||
await license.init();
|
await license.init({ isCli: true });
|
||||||
|
|
||||||
this.logger.info('Printing license information:\n' + license.getInfo());
|
this.logger.info('Printing license information:\n' + license.getInfo());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ export class License {
|
|||||||
this.logger = this.logger.scoped('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) {
|
if (this.manager && !forceRecreate) {
|
||||||
this.logger.warn('License manager already initialized or shutting down');
|
this.logger.warn('License manager already initialized or shutting down');
|
||||||
return;
|
return;
|
||||||
@@ -73,10 +76,13 @@ export class License {
|
|||||||
|
|
||||||
const { isLeader } = this.instanceSettings;
|
const { isLeader } = this.instanceSettings;
|
||||||
const { autoRenewalEnabled } = this.globalConfig.license;
|
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 {
|
try {
|
||||||
this.manager = new LicenseManager({
|
this.manager = new LicenseManager({
|
||||||
@@ -390,7 +396,7 @@ export class License {
|
|||||||
|
|
||||||
async reinit() {
|
async reinit() {
|
||||||
this.manager?.reset();
|
this.manager?.reset();
|
||||||
await this.init(true);
|
await this.init({ forceRecreate: true });
|
||||||
this.logger.debug('License reinitialized');
|
this.logger.debug('License reinitialized');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user