Skip to content

Commit 62cd83d

Browse files
authored
[Fleet] use agentless API from package policy editor UI (#244424)
1 parent 4169f2a commit 62cd83d

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

x-pack/platform/plugins/shared/fleet/common/experimental_features.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const _allowedExperimentalValues = {
2020
installIntegrationsKnowledge: false,
2121
enableFleetPolicyRevisionsCleanupTask: true,
2222
agentlessPoliciesAPI: true, // When enabled, agentless policies API will be enabled.
23-
useAgentlessAPIInUI: false, // When enabled, Fleet UI will use agentless policies API to create agentless policies.
23+
useAgentlessAPIInUI: true, // When enabled, Fleet UI will use agentless policies API to create agentless policies.
2424
disableAgentlessLegacyAPI: false, // When enabled, it will disable creating agentless policies via agent or package policies API.
2525
};
2626

x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/index.test.tsx

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ import { Route } from '@kbn/shared-ux-router';
99
import React from 'react';
1010
import { fireEvent, act, waitFor } from '@testing-library/react';
1111

12+
import { sendCreateAgentlessPolicy } from '../../../../../../hooks/use_request/agentless_policy';
13+
1214
import type { MockedFleetStartServices, TestRenderer } from '../../../../../../mock';
1315
import { createFleetTestRendererMock } from '../../../../../../mock';
14-
import { FLEET_ROUTING_PATHS, pagePathGetters, PLUGIN_ID } from '../../../../constants';
16+
import {
17+
FLEET_ROUTING_PATHS,
18+
pagePathGetters,
19+
PLUGIN_ID,
20+
INTEGRATIONS_PLUGIN_ID,
21+
} from '../../../../constants';
1522
import type { CreatePackagePolicyRouteState } from '../../../../types';
1623
import {
1724
sendCreatePackagePolicyForRq,
@@ -37,6 +44,8 @@ jest.mock('../components/steps/components/use_policies', () => {
3744
};
3845
});
3946

47+
jest.mock('../../../../../../hooks/use_request/agentless_policy');
48+
4049
jest.mock('../../../../hooks', () => {
4150
return {
4251
...jest.requireActual('../../../../hooks'),
@@ -718,9 +727,18 @@ describe('When on the package policy create page', () => {
718727
isCloudEnabled: true,
719728
},
720729
});
721-
(sendCreateAgentPolicy as jest.MockedFunction<any>).mockResolvedValue({
722-
data: {
723-
item: { id: 'agentless-policy-1', name: 'Agentless policy 1', namespace: 'default' },
730+
(sendCreateAgentlessPolicy as jest.MockedFunction<any>).mockResolvedValue({
731+
item: {
732+
name: 'Nginx',
733+
id: 'policy-1',
734+
inputs: [],
735+
policy_ids: ['agent-policy-1'],
736+
supports_agentless: true,
737+
package: {
738+
name: 'nginx',
739+
title: 'Nginx',
740+
version: '1.3.0',
741+
},
724742
},
725743
});
726744

@@ -741,17 +759,19 @@ describe('When on the package policy create page', () => {
741759
fireEvent.click(renderResult.getByText(/Save and continue/).closest('button')!);
742760
});
743761

744-
expect(sendCreateAgentPolicy).toHaveBeenCalledWith(
762+
expect(sendCreateAgentlessPolicy).toHaveBeenCalledWith(
745763
expect.objectContaining({
746-
monitoring_enabled: ['logs', 'metrics'],
747-
name: 'Agentless policy for nginx-1',
764+
name: 'nginx-1',
748765
}),
749-
{ withSysMonitoring: true }
766+
{ format: 'legacy' }
750767
);
751-
expect(sendCreatePackagePolicyForRq).toHaveBeenCalled();
768+
expect(sendCreatePackagePolicyForRq).not.toHaveBeenCalled();
752769

753770
await waitFor(() => {
754-
expect(renderResult.getByText('Nginx integration added')).toBeInTheDocument();
771+
expect(useStartServices().application.navigateToApp).toHaveBeenCalledWith(
772+
INTEGRATIONS_PLUGIN_ID,
773+
{ path: '/detail/nginx-1.3.0/policies?openEnrollmentFlyout=agent-policy-1' }
774+
);
755775
});
756776
});
757777

@@ -766,19 +786,18 @@ describe('When on the package policy create page', () => {
766786
fireEvent.click(renderResult.getByText(/Save and continue/).closest('button')!);
767787
});
768788

769-
expect(sendCreateAgentPolicy).toHaveBeenCalledWith(
789+
expect(sendCreateAgentlessPolicy).toHaveBeenCalledWith(
770790
expect.objectContaining({
771-
monitoring_enabled: ['logs', 'metrics'],
772-
name: 'Agentless policy for nginx-1',
773-
supports_agentless: true,
791+
name: 'nginx-1',
774792
}),
775-
{ withSysMonitoring: true }
793+
{ format: 'legacy' }
776794
);
777-
expect(sendCreatePackagePolicyForRq).toHaveBeenCalled();
795+
expect(sendCreatePackagePolicyForRq).not.toHaveBeenCalled();
778796

779-
await waitFor(() => {
780-
expect(renderResult.getByText('Nginx integration added')).toBeInTheDocument();
781-
});
797+
expect(useStartServices().application.navigateToApp).toHaveBeenCalledWith(
798+
INTEGRATIONS_PLUGIN_ID,
799+
{ path: '/detail/nginx-1.3.0/policies?openEnrollmentFlyout=agent-policy-1' }
800+
);
782801
});
783802
});
784803
});

0 commit comments

Comments
 (0)