Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into add-files-API-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
adcoelho committed Nov 13, 2024
2 parents 4d4fc33 + b8836c5 commit 95b00e1
Show file tree
Hide file tree
Showing 45 changed files with 806 additions and 159 deletions.
1 change: 1 addition & 0 deletions .buildkite/ftr_platform_stateful_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ enabled:
- x-pack/test/fleet_api_integration/config.agent.ts
- x-pack/test/fleet_api_integration/config.agent_policy.ts
- x-pack/test/fleet_api_integration/config.epm.ts
- x-pack/test/fleet_api_integration/config.event_ingested.ts
- x-pack/test/fleet_api_integration/config.fleet.ts
- x-pack/test/fleet_api_integration/config.package_policy.ts
- x-pack/test/fleet_api_integration/config.space_awareness.ts
Expand Down
3 changes: 3 additions & 0 deletions config/serverless.oblt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ xpack.serverless.plugin.developer.projectSwitcher.currentType: 'observability'
## Disable adding the component template `.fleet_agent_id_verification-1` to every index template for each datastream for each integration
xpack.fleet.agentIdVerificationEnabled: false

## Enable event.ingested separately because agentIdVerification is disabled
xpack.fleet.eventIngestedEnabled: true

## Enable the capability for the observability feature ID in the serverless environment to take ownership of the rules.
## The value need to be a featureId observability Or stackAlerts Or siem
xpack.alerting.rules.overwriteProducer: 'observability'
Expand Down
184 changes: 117 additions & 67 deletions x-pack/plugins/enterprise_search/common/utils/licensing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,92 +5,142 @@
* 2.0.
*/

import type { ILicense } from '@kbn/licensing-plugin/public';
import { licenseMock } from '@kbn/licensing-plugin/common/licensing.mock';

import { hasEnterpriseLicense } from './licensing';
import { License } from '@kbn/licensing-plugin/common/license';

import {
hasEnterpriseLicense,
hasGoldLicense,
hasPlatinumLicense,
isTrialLicense,
} from './licensing';

describe('licensing utils', () => {
const baseLicense: ILicense = {
isActive: true,
type: 'trial',
isAvailable: true,
signature: 'fake',
toJSON: jest.fn(),
getUnavailableReason: jest.fn().mockReturnValue(undefined),
hasAtLeast: jest.fn().mockReturnValue(false),
check: jest.fn().mockReturnValue({ state: 'valid' }),
getFeature: jest.fn().mockReturnValue({ isAvailable: false, isEnabled: false }),
};
describe('hasEnterpriseLicense', () => {
let license: ILicense;
beforeEach(() => {
jest.resetAllMocks();
license = {
...baseLicense,
};
});
it('returns true for active enterprise license', () => {
license.type = 'enterprise';
const basicLicense = licenseMock.createLicense();
const basicExpiredLicense = licenseMock.createLicense({ license: { status: 'expired' } });
const goldLicense = licenseMock.createLicense({ license: { type: 'gold' } });
const goldLicenseExpired = licenseMock.createLicense({
license: { status: 'expired', type: 'gold' },
});
const platinumLicense = licenseMock.createLicense({ license: { type: 'platinum' } });
const platinumLicenseExpired = licenseMock.createLicense({
license: { status: 'expired', type: 'platinum' },
});
const enterpriseLicense = licenseMock.createLicense({ license: { type: 'enterprise' } });
const enterpriseLicenseExpired = licenseMock.createLicense({
license: { status: 'expired', type: 'enterprise' },
});
const trialLicense = licenseMock.createLicense({ license: { type: 'trial' } });
const trialLicenseExpired = licenseMock.createLicense({
license: { status: 'expired', type: 'trial' },
});

expect(hasEnterpriseLicense(license)).toEqual(true);
const errorMessage = 'unavailable';
const errorLicense = new License({ error: errorMessage, signature: '' });
const unavailableLicense = new License({ signature: '' });

beforeEach(() => {
jest.resetAllMocks();
});

describe('hasEnterpriseLicense', () => {
it('returns true for active valid licenses', () => {
expect(hasEnterpriseLicense(enterpriseLicense)).toEqual(true);
expect(hasEnterpriseLicense(trialLicense)).toEqual(true);
});
it('returns true for active trial license', () => {
expect(hasEnterpriseLicense(license)).toEqual(true);
it('returns false for active invalid licenses', () => {
expect(hasEnterpriseLicense(basicLicense)).toEqual(false);
expect(hasEnterpriseLicense(goldLicense)).toEqual(false);
expect(hasEnterpriseLicense(platinumLicense)).toEqual(false);
});
it('returns false for active basic license', () => {
license.type = 'basic';

expect(hasEnterpriseLicense(license)).toEqual(false);
it('returns false for inactive licenses', () => {
expect(hasEnterpriseLicense(trialLicenseExpired)).toEqual(false);
expect(hasEnterpriseLicense(enterpriseLicenseExpired)).toEqual(false);
expect(hasEnterpriseLicense(basicExpiredLicense)).toEqual(false);
});
it('returns false for active gold license', () => {
license.type = 'gold';

expect(hasEnterpriseLicense(license)).toEqual(false);
it('returns false for unavailable license', () => {
expect(hasEnterpriseLicense(errorLicense)).toEqual(false);
expect(hasEnterpriseLicense(unavailableLicense)).toEqual(false);
});
it('returns false for active platinum license', () => {
license.type = 'platinum';

expect(hasEnterpriseLicense(license)).toEqual(false);
it('returns false for null license', () => {
expect(hasEnterpriseLicense(null)).toEqual(false);
});
it('returns false for inactive enterprise license', () => {
license.type = 'enterprise';
license.isActive = false;

expect(hasEnterpriseLicense(license)).toEqual(false);
it('returns false for undefined license', () => {
expect(hasEnterpriseLicense(undefined)).toEqual(false);
});
it('returns false for inactive trial license', () => {
license.isActive = false;
});

expect(hasEnterpriseLicense(license)).toEqual(false);
describe('hasPlatinumLicense', () => {
it('returns true for valid active licenses', () => {
expect(hasPlatinumLicense(platinumLicense)).toEqual(true);
expect(hasPlatinumLicense(enterpriseLicense)).toEqual(true);
expect(hasPlatinumLicense(trialLicense)).toEqual(true);
});
it('returns false for inactive basic license', () => {
license.type = 'basic';
license.isActive = false;

expect(hasEnterpriseLicense(license)).toEqual(false);
it('returns false for invalid active licenses', () => {
expect(hasPlatinumLicense(goldLicense)).toEqual(false);
expect(hasPlatinumLicense(basicLicense)).toEqual(false);
});
it('returns false for inactive gold license', () => {
license.type = 'gold';
license.isActive = false;

expect(hasEnterpriseLicense(license)).toEqual(false);
it('returns false for inactive licenses', () => {
expect(hasPlatinumLicense(platinumLicenseExpired)).toEqual(false);
expect(hasPlatinumLicense(enterpriseLicenseExpired)).toEqual(false);
expect(hasPlatinumLicense(trialLicenseExpired)).toEqual(false);
});
it('returns false for inactive platinum license', () => {
license.type = 'platinum';
license.isActive = false;

expect(hasEnterpriseLicense(license)).toEqual(false);
it('returns false for bad licenses', () => {
expect(hasPlatinumLicense(errorLicense)).toEqual(false);
expect(hasPlatinumLicense(unavailableLicense)).toEqual(false);
});
it('returns false for active license is missing type', () => {
delete license.type;

expect(hasEnterpriseLicense(license)).toEqual(false);
it('returns false for null license', () => {
expect(hasPlatinumLicense(null)).toEqual(false);
});
it('returns false for undefined license', () => {
expect(hasPlatinumLicense(undefined)).toEqual(false);
});
});
describe('hasGoldLicense', () => {
it('returns true for valid active licenses', () => {
expect(hasGoldLicense(goldLicense)).toEqual(true);
expect(hasGoldLicense(platinumLicense)).toEqual(true);
expect(hasGoldLicense(enterpriseLicense)).toEqual(true);
expect(hasGoldLicense(trialLicense)).toEqual(true);
});
it('returns false for invalid active licenses', () => {
expect(hasGoldLicense(basicLicense)).toEqual(false);
});
it('returns false for inactive licenses', () => {
expect(hasGoldLicense(goldLicenseExpired)).toEqual(false);
expect(hasGoldLicense(platinumLicenseExpired)).toEqual(false);
expect(hasGoldLicense(enterpriseLicenseExpired)).toEqual(false);
expect(hasGoldLicense(trialLicenseExpired)).toEqual(false);
});
it('returns false for bad licenses', () => {
expect(hasGoldLicense(errorLicense)).toEqual(false);
expect(hasGoldLicense(unavailableLicense)).toEqual(false);
});
it('returns false for null license', () => {
expect(hasEnterpriseLicense(null)).toEqual(false);
expect(hasGoldLicense(null)).toEqual(false);
});
it('returns false for undefined license', () => {
expect(hasEnterpriseLicense(undefined)).toEqual(false);
expect(hasGoldLicense(undefined)).toEqual(false);
});
});
describe('isTrialLicense', () => {
it('returns true for active trial license', () => {
expect(hasGoldLicense(trialLicense)).toEqual(true);
});
it('returns false for non-trial license', () => {
expect(isTrialLicense(platinumLicense)).toEqual(false);
});
it('returns false for invalid license', () => {
expect(isTrialLicense(trialLicenseExpired)).toEqual(false);
expect(isTrialLicense(errorLicense)).toEqual(false);
expect(isTrialLicense(unavailableLicense)).toEqual(false);
});
it('returns false for null license', () => {
expect(isTrialLicense(null)).toEqual(false);
});
it('returns false for undefined license', () => {
expect(isTrialLicense(undefined)).toEqual(false);
});
});
});
34 changes: 31 additions & 3 deletions x-pack/plugins/enterprise_search/common/utils/licensing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,38 @@

import type { ILicense } from '@kbn/licensing-plugin/public';

/* hasEnterpriseLicense return if the given license is an active `enterprise` or `trial` license
/* hasEnterpriseLicense return if the given license is an active `enterprise` or greater license
*/
export function hasEnterpriseLicense(license: ILicense | null | undefined): boolean {
if (license === undefined || license === null) return false;
const qualifyingLicenses = ['enterprise', 'trial'];
return license.isActive && qualifyingLicenses.includes(license?.type ?? '');
if (!license.isAvailable) return false;
if (!license.isActive) return false;
return license.hasAtLeast('enterprise');
}

/* hasPlatinumLicense return if the given license is an active `platinum` or greater license
*/
export function hasPlatinumLicense(license: ILicense | null | undefined): boolean {
if (license === undefined || license === null) return false;
if (!license.isAvailable) return false;
if (!license.isActive) return false;
return license.hasAtLeast('platinum');
}

/* hasGoldLicense return if the given license is an active `gold` or greater license
*/
export function hasGoldLicense(license: ILicense | null | undefined): boolean {
if (license === undefined || license === null) return false;
if (!license.isAvailable) return false;
if (!license.isActive) return false;
return license.hasAtLeast('gold');
}

/* isTrialLicense returns if the given license is an active `trial` license
*/
export function isTrialLicense(license: ILicense | null | undefined): boolean {
if (license === undefined || license === null) return false;
if (!license.isAvailable) return false;
if (!license.isActive) return false;
return license?.type === 'trial';
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { Observable, Subscription } from 'rxjs';

import { ILicense } from '@kbn/licensing-plugin/public';

import {
hasEnterpriseLicense,
hasGoldLicense,
hasPlatinumLicense,
isTrialLicense,
} from '../../../../common/utils/licensing';

interface LicensingValues {
license: ILicense | null;
licenseSubscription: Subscription | null;
Expand Down Expand Up @@ -50,29 +57,14 @@ export const LicensingLogic = kea<MakeLogicType<LicensingValues, LicensingAction
selectors: {
hasPlatinumLicense: [
(selectors) => [selectors.license],
(license) => {
const qualifyingLicenses = ['platinum', 'enterprise', 'trial'];
return license?.isActive && qualifyingLicenses.includes(license?.type);
},
(license) => hasPlatinumLicense(license),
],
hasEnterpriseLicense: [
(selectors) => [selectors.license],
(license) => {
const qualifyingLicenses = ['enterprise', 'trial'];
return license?.isActive && qualifyingLicenses.includes(license?.type);
},
],
hasGoldLicense: [
(selectors) => [selectors.license],
(license) => {
const qualifyingLicenses = ['gold', 'platinum', 'enterprise', 'trial'];
return license?.isActive && qualifyingLicenses.includes(license?.type);
},
],
isTrial: [
(selectors) => [selectors.license],
(license) => license?.isActive && license?.type === 'trial',
(license) => hasEnterpriseLicense(license),
],
hasGoldLicense: [(selectors) => [selectors.license], (license) => hasGoldLicense(license)],
isTrial: [(selectors) => [selectors.license], (license) => isTrialLicense(license)],
},
events: ({ props, actions, values }) => ({
afterMount: () => {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface FleetConfigType {
packages?: PreconfiguredPackage[];
outputs?: PreconfiguredOutput[];
agentIdVerificationEnabled?: boolean;
eventIngestedEnabled?: boolean;
enableExperimental?: string[];
packageVerification?: {
gpgKeyPath?: string;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/public/mock/plugin_configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const createConfigurationMock = (): FleetConfigType => {
registryUrl: '',
registryProxyUrl: '',
agentIdVerificationEnabled: true,
eventIngestedEnabled: false,
agents: {
enabled: true,
elasticsearch: {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export const config: PluginConfigDescriptor = {
proxies: PreconfiguredFleetProxiesSchema,
spaceSettings: PreconfiguredSpaceSettingsSchema,
agentIdVerificationEnabled: schema.boolean({ defaultValue: true }),
eventIngestedEnabled: schema.boolean({ defaultValue: false }),
setup: schema.maybe(
schema.object({
agentPolicySchemaUpgradeBatchSize: schema.maybe(schema.number()),
Expand Down
Loading

0 comments on commit 95b00e1

Please sign in to comment.