[Security Solution][Endpoint] Fix unhandled promise rejections in skipped tests (#115354)

* Fix errors and comment code in middleware (pending to fix this)

* Fix endpoint list middleware test

* Fix policy TA layout test

* Fix test returning missing promise
This commit is contained in:
David Sánchez 2021-10-18 17:35:28 +02:00 committed by GitHub
parent 6792bdfc6d
commit cf4a687906
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 41 deletions

View file

@ -20,7 +20,6 @@ jest.mock('../../../common/components/user_privileges/use_endpoint_privileges');
let onSearchMock: jest.Mock;
const mockUseEndpointPrivileges = useEndpointPrivileges as jest.Mock;
// unhandled promise rejection: https://github.com/elastic/kibana/issues/112699
describe('Search exceptions', () => {
let appTestContext: AppContextTestRender;
let renderResult: ReturnType<AppContextTestRender['render']>;

View file

@ -122,30 +122,27 @@ export const endpointActivityLogHttpMock =
const responseData = fleetActionGenerator.generateResponse({
agent_id: endpointMetadata.agent.id,
});
return {
body: {
page: 1,
pageSize: 50,
startDate: 'now-1d',
endDate: 'now',
data: [
{
type: 'response',
item: {
id: '',
data: responseData,
},
page: 1,
pageSize: 50,
startDate: 'now-1d',
endDate: 'now',
data: [
{
type: 'response',
item: {
id: '',
data: responseData,
},
{
type: 'action',
item: {
id: '',
data: actionData,
},
},
{
type: 'action',
item: {
id: '',
data: actionData,
},
],
},
},
],
};
},
},

View file

@ -61,8 +61,7 @@ jest.mock('../../../../common/lib/kibana');
type EndpointListStore = Store<Immutable<EndpointState>, Immutable<AppAction>>;
// unhandled promise rejection: https://github.com/elastic/kibana/issues/112699
describe.skip('endpoint list middleware', () => {
describe('endpoint list middleware', () => {
const getKibanaServicesMock = KibanaServices.get as jest.Mock;
let fakeCoreStart: jest.Mocked<CoreStart>;
let depsStart: DepsStartMock;
@ -390,7 +389,6 @@ describe.skip('endpoint list middleware', () => {
it('should call get Activity Log API with correct paging options', async () => {
dispatchUserChangedUrl();
const updatePagingDispatched = waitForAction('endpointDetailsActivityLogUpdatePaging');
dispatchGetActivityLogPaging({ page: 3 });

View file

@ -19,20 +19,14 @@ import { createLoadedResourceState, isLoadedResourceState } from '../../../../..
import { getPolicyDetailsArtifactsListPath } from '../../../../../common/routing';
import { EndpointDocGenerator } from '../../../../../../../common/endpoint/generate_data';
import { policyListApiPathHandlers } from '../../../store/test_mock_utils';
import { licenseService } from '../../../../../../common/hooks/use_license';
import {
EndpointPrivileges,
useEndpointPrivileges,
} from '../../../../../../common/components/user_privileges/use_endpoint_privileges';
jest.mock('../../../../trusted_apps/service');
jest.mock('../../../../../../common/hooks/use_license', () => {
const licenseServiceInstance = {
isPlatinumPlus: jest.fn(),
};
return {
licenseService: licenseServiceInstance,
useLicense: () => {
return licenseServiceInstance;
},
};
});
jest.mock('../../../../../../common/components/user_privileges/use_endpoint_privileges');
const mockUseEndpointPrivileges = useEndpointPrivileges as jest.Mock;
let mockedContext: AppContextTestRender;
let waitForAction: MiddlewareActionSpyHelper['waitForAction'];
@ -42,8 +36,17 @@ let coreStart: AppContextTestRender['coreStart'];
let http: typeof coreStart.http;
const generator = new EndpointDocGenerator();
// unhandled promise rejection: https://github.com/elastic/kibana/issues/112699
describe.skip('Policy trusted apps layout', () => {
describe('Policy trusted apps layout', () => {
const loadedUserEndpointPrivilegesState = (
endpointOverrides: Partial<EndpointPrivileges> = {}
): EndpointPrivileges => ({
loading: false,
canAccessFleet: true,
canAccessEndpointManagement: true,
isPlatinumPlus: true,
...endpointOverrides,
});
beforeEach(() => {
mockedContext = createAppRootMockRenderer();
http = mockedContext.coreStart.http;
@ -59,6 +62,14 @@ describe.skip('Policy trusted apps layout', () => {
});
}
// GET Agent status for agent policy
if (path === '/api/fleet/agent-status') {
return Promise.resolve({
results: { events: 0, total: 5, online: 3, error: 1, offline: 1 },
success: true,
});
}
// Get package data
// Used in tests that route back to the list
if (policyListApiHandlers[path]) {
@ -78,6 +89,10 @@ describe.skip('Policy trusted apps layout', () => {
render = () => mockedContext.render(<PolicyTrustedAppsLayout />);
});
afterAll(() => {
mockUseEndpointPrivileges.mockReset();
});
afterEach(() => reactTestingLibrary.cleanup());
it('should renders layout with no existing TA data', async () => {
@ -121,7 +136,11 @@ describe.skip('Policy trusted apps layout', () => {
});
it('should hide assign button on empty state with unassigned policies when downgraded to a gold or below license', async () => {
(licenseService.isPlatinumPlus as jest.Mock).mockReturnValue(false);
mockUseEndpointPrivileges.mockReturnValue(
loadedUserEndpointPrivilegesState({
isPlatinumPlus: false,
})
);
const component = render();
mockedContext.history.push(getPolicyDetailsArtifactsListPath('1234'));
@ -133,8 +152,13 @@ describe.skip('Policy trusted apps layout', () => {
});
expect(component.queryByTestId('assign-ta-button')).toBeNull();
});
it('should hide the `Assign trusted applications` button when there is data and the license is downgraded to gold or below', async () => {
(licenseService.isPlatinumPlus as jest.Mock).mockReturnValue(false);
mockUseEndpointPrivileges.mockReturnValue(
loadedUserEndpointPrivilegesState({
isPlatinumPlus: false,
})
);
TrustedAppsHttpServiceMock.mockImplementation(() => {
return {
getTrustedAppsList: () => getMockListResponse(),