mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
* Fix preconfiguration error when renaming a preconfigured policy
* Add test + only compare on ID if it's defined on the preconfigured policy
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 94fbacc6bd
)
# Conflicts:
# x-pack/plugins/fleet/server/services/preconfiguration.test.ts
This commit is contained in:
parent
64bbe49898
commit
09d2cd1ce5
2 changed files with 53 additions and 1 deletions
|
@ -209,6 +209,7 @@ const spyAgentPolicyServicBumpAllAgentPoliciesForOutput = jest.spyOn(
|
|||
|
||||
describe('policy preconfiguration', () => {
|
||||
beforeEach(() => {
|
||||
mockedPackagePolicyService.getByIDs.mockReset();
|
||||
mockedPackagePolicyService.create.mockReset();
|
||||
mockInstalledPackages.clear();
|
||||
mockInstallPackageErrors.clear();
|
||||
|
@ -391,6 +392,55 @@ describe('policy preconfiguration', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('should not try to recreate preconfigure package policy that has been renamed', async () => {
|
||||
const soClient = getPutPreconfiguredPackagesMock();
|
||||
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
|
||||
|
||||
mockedPackagePolicyService.getByIDs.mockResolvedValue([
|
||||
{ name: 'Renamed package policy', id: 'test_package1' } as PackagePolicy,
|
||||
]);
|
||||
|
||||
mockConfiguredPolicies.set('test-id', {
|
||||
name: 'Test policy',
|
||||
description: 'Test policy description',
|
||||
unenroll_timeout: 120,
|
||||
namespace: 'default',
|
||||
id: 'test-id',
|
||||
package_policies: [
|
||||
{
|
||||
name: 'test_package1',
|
||||
id: 'test_package1',
|
||||
},
|
||||
],
|
||||
is_managed: true,
|
||||
} as PreconfiguredAgentPolicy);
|
||||
|
||||
await ensurePreconfiguredPackagesAndPolicies(
|
||||
soClient,
|
||||
esClient,
|
||||
[
|
||||
{
|
||||
name: 'Test policy',
|
||||
namespace: 'default',
|
||||
id: 'test-id',
|
||||
is_managed: true,
|
||||
package_policies: [
|
||||
{
|
||||
package: { name: 'test_package' },
|
||||
name: 'test_package1',
|
||||
id: 'test_package1',
|
||||
},
|
||||
],
|
||||
},
|
||||
] as PreconfiguredAgentPolicy[],
|
||||
[{ name: 'test_package', version: '3.0.0' }],
|
||||
mockDefaultOutput,
|
||||
DEFAULT_SPACE_ID
|
||||
);
|
||||
|
||||
expect(mockedPackagePolicyService.create).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('should throw an error when trying to install duplicate packages', async () => {
|
||||
const soClient = getPutPreconfiguredPackagesMock();
|
||||
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
|
||||
|
|
|
@ -334,7 +334,9 @@ export async function ensurePreconfiguredPackagesAndPolicies(
|
|||
|
||||
const packagePoliciesToAdd = installedPackagePolicies.filter((installablePackagePolicy) => {
|
||||
return !(agentPolicyWithPackagePolicies?.package_policies as PackagePolicy[]).some(
|
||||
(packagePolicy) => packagePolicy.name === installablePackagePolicy.name
|
||||
(packagePolicy) =>
|
||||
(packagePolicy.id !== undefined && packagePolicy.id === installablePackagePolicy.id) ||
|
||||
packagePolicy.name === installablePackagePolicy.name
|
||||
);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue