[8.6] [Security Solution][Endpoint] Flx and unskip flaky test (#149839) (#150006)

# Backport

This will backport the following commits from `main` to `8.6`:
- [[Security Solution][Endpoint] Flx and unskip flaky test
(#149839)](https://github.com/elastic/kibana/pull/149839)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Ashokaditya","email":"1849116+ashokaditya@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-02-01T09:00:09Z","message":"[Security
Solution][Endpoint] Flx and unskip flaky test (#149839)\n\n##
Summary\r\n\r\nFixes flaky test
elastic/kibana/issues/145635\r\n\r\nflaky test
runners:\r\n-\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1816\r\nx
50 (successful on all
50)\r\n-\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1828\r\nx
150 (successful on all
150)\r\n-\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1829\r\nx
200 (failed on a single run for an
[unrelated\r\ntest](92cb000a2f/x-pack/test/security_solution_endpoint/apps/endpoint/responder.ts (L113)))\r\n-\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1832\r\nx
100 (successful on all 100)\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"511aaf3004aab84ec2f9ae452e3f739a58876dd8","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","test-failure-flaky","Team:Defend
Workflows","OLM
Sprint","v8.6.0","v8.7.0"],"number":149839,"url":"https://github.com/elastic/kibana/pull/149839","mergeCommit":{"message":"[Security
Solution][Endpoint] Flx and unskip flaky test (#149839)\n\n##
Summary\r\n\r\nFixes flaky test
elastic/kibana/issues/145635\r\n\r\nflaky test
runners:\r\n-\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1816\r\nx
50 (successful on all
50)\r\n-\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1828\r\nx
150 (successful on all
150)\r\n-\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1829\r\nx
200 (failed on a single run for an
[unrelated\r\ntest](92cb000a2f/x-pack/test/security_solution_endpoint/apps/endpoint/responder.ts (L113)))\r\n-\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1832\r\nx
100 (successful on all 100)\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"511aaf3004aab84ec2f9ae452e3f739a58876dd8"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/149839","number":149839,"mergeCommit":{"message":"[Security
Solution][Endpoint] Flx and unskip flaky test (#149839)\n\n##
Summary\r\n\r\nFixes flaky test
elastic/kibana/issues/145635\r\n\r\nflaky test
runners:\r\n-\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1816\r\nx
50 (successful on all
50)\r\n-\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1828\r\nx
150 (successful on all
150)\r\n-\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1829\r\nx
200 (failed on a single run for an
[unrelated\r\ntest](92cb000a2f/x-pack/test/security_solution_endpoint/apps/endpoint/responder.ts (L113)))\r\n-\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1832\r\nx
100 (successful on all 100)\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"511aaf3004aab84ec2f9ae452e3f739a58876dd8"}}]}]
BACKPORT-->

---------

Co-authored-by: Ashokaditya <1849116+ashokaditya@users.noreply.github.com>
Co-authored-by: Ashokaditya <ashokaditya@elastic.co>
This commit is contained in:
Kibana Machine 2023-02-01 06:56:52 -05:00 committed by GitHub
parent 9702dadc77
commit fd93843e5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,7 +27,7 @@ import { RESPONSE_ACTION_API_COMMANDS_NAMES } from '../../../../common/endpoint/
import { useUserPrivileges as _useUserPrivileges } from '../../../common/components/user_privileges';
import { responseActionsHttpMocks } from '../../mocks/response_actions_http_mocks';
import { waitFor } from '@testing-library/react';
import { getUserPrivilegesMockDefaultValue } from '../../../common/components/user_privileges/__mocks__';
import { getEndpointAuthzInitialStateMock } from '../../../../common/endpoint/service/authz/mocks';
let mockUseGetEndpointActionList: {
isFetched?: boolean;
@ -123,6 +123,7 @@ jest.mock('../../hooks/endpoint/use_get_endpoints_list');
jest.mock('../../../common/experimental_features_service');
jest.mock('../../../common/components/user_privileges');
const useUserPrivilegesMock = _useUserPrivileges as jest.Mock;
let mockUseGetFileInfo: {
isFetching?: boolean;
@ -139,12 +140,13 @@ jest.mock('../../hooks/response_actions/use_get_file_info', () => {
const mockUseGetEndpointsList = useGetEndpointsList as jest.Mock;
// FLAKY https://github.com/elastic/kibana/issues/145635
describe.skip('Response actions history', () => {
const useUserPrivilegesMock = _useUserPrivileges as jest.Mock<
ReturnType<typeof _useUserPrivileges>
>;
const getBaseMockedActionList = () => ({
isFetched: true,
isFetching: false,
error: null,
refetch: jest.fn(),
});
describe('Response actions history', () => {
const testPrefix = 'response-actions-list';
let render: (
@ -155,14 +157,6 @@ describe.skip('Response actions history', () => {
let mockedContext: AppContextTestRender;
let apiMocks: ReturnType<typeof responseActionsHttpMocks>;
const refetchFunction = jest.fn();
const baseMockedActionList = {
isFetched: true,
isFetching: false,
error: null,
refetch: refetchFunction,
};
beforeEach(async () => {
mockedContext = createAppRootMockRenderer();
({ history } = mockedContext);
@ -173,7 +167,7 @@ describe.skip('Response actions history', () => {
});
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data: await getActionListMock({ actionCount: 13 }),
};
@ -189,20 +183,20 @@ describe.skip('Response actions history', () => {
pageSize: 50,
total: 50,
});
useUserPrivilegesMock.mockReturnValue({
endpointPrivileges: getEndpointAuthzInitialStateMock(),
});
});
afterEach(() => {
mockUseGetEndpointActionList = {
...baseMockedActionList,
};
jest.clearAllMocks();
useUserPrivilegesMock.mockImplementation(getUserPrivilegesMockDefaultValue);
mockUseGetEndpointActionList = getBaseMockedActionList();
useUserPrivilegesMock.mockReset();
});
describe('When index does not exist yet', () => {
it('should show global loader when waiting for response', () => {
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
isFetched: false,
isFetching: true,
};
@ -211,7 +205,7 @@ describe.skip('Response actions history', () => {
});
it('should show empty page when there is no index', () => {
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
error: {
body: { statusCode: 404, message: 'index_not_found_exception' },
},
@ -234,7 +228,7 @@ describe.skip('Response actions history', () => {
it('should show empty state when there is no data', async () => {
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data: await getActionListMock({ actionCount: 0 }),
};
render();
@ -295,7 +289,7 @@ describe.skip('Response actions history', () => {
};
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data,
};
render({ showHostNames: true });
@ -316,7 +310,7 @@ describe.skip('Response actions history', () => {
};
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data,
};
render({ showHostNames: true });
@ -339,7 +333,7 @@ describe.skip('Response actions history', () => {
};
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data,
};
render({ showHostNames: true });
@ -367,7 +361,7 @@ describe.skip('Response actions history', () => {
it('should update per page rows on the table', async () => {
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data: await getActionListMock({ actionCount: 33 }),
};
@ -398,7 +392,7 @@ describe.skip('Response actions history', () => {
it('should show 1-1 record label when only 1 record', async () => {
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data: await getActionListMock({ actionCount: 1 }),
};
render();
@ -446,7 +440,7 @@ describe.skip('Response actions history', () => {
it('should contain download link in expanded row for `get-file` action WITH file operation permission', async () => {
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data: await getActionListMock({ actionCount: 1, commands: ['get-file'] }),
};
@ -475,7 +469,7 @@ describe.skip('Response actions history', () => {
it('should show file unavailable for download for `get-file` action WITH file operation permission when file is deleted', async () => {
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data: await getActionListMock({ actionCount: 1, commands: ['get-file'] }),
};
@ -507,20 +501,14 @@ describe.skip('Response actions history', () => {
});
it('should not contain download link in expanded row for `get-file` action when NO file operation permission', async () => {
const privileges = useUserPrivilegesMock();
useUserPrivilegesMock.mockImplementationOnce(() => {
return {
...privileges,
endpointPrivileges: {
...privileges.endpointPrivileges,
canWriteFileOperations: false,
},
};
useUserPrivilegesMock.mockReturnValue({
endpointPrivileges: getEndpointAuthzInitialStateMock({
canWriteFileOperations: false,
}),
});
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data: await getActionListMock({ actionCount: 1, commands: ['get-file'] }),
};
@ -536,6 +524,7 @@ describe.skip('Response actions history', () => {
});
it('should refresh data when autoRefresh is toggled on', async () => {
mockUseGetEndpointActionList = getBaseMockedActionList();
render();
const { getByTestId } = renderResult;
@ -550,16 +539,19 @@ describe.skip('Response actions history', () => {
reactTestingLibrary.fireEvent.change(intervalInput, { target: { value: 1 } });
await reactTestingLibrary.waitFor(() => {
expect(refetchFunction).toHaveBeenCalledTimes(3);
expect(mockUseGetEndpointActionList.refetch).toHaveBeenCalledTimes(3);
});
});
it('should refresh data when super date picker refresh button is clicked', async () => {
mockUseGetEndpointActionList = getBaseMockedActionList();
render();
const superRefreshButton = renderResult.getByTestId(`${testPrefix}-super-refresh-button`);
userEvent.click(superRefreshButton);
expect(refetchFunction).toHaveBeenCalledTimes(1);
await waitFor(() => {
expect(mockUseGetEndpointActionList.refetch).toHaveBeenCalled();
});
});
it('should set date picker with relative dates', async () => {
@ -592,7 +584,7 @@ describe.skip('Response actions history', () => {
it('shows completed status badge for successfully completed actions', async () => {
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data: await getActionListMock({ actionCount: 2 }),
};
render();
@ -609,7 +601,7 @@ describe.skip('Response actions history', () => {
it('shows Failed status badge for failed actions', async () => {
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data: await getActionListMock({ actionCount: 2, wasSuccessful: false, status: 'failed' }),
};
render();
@ -623,7 +615,7 @@ describe.skip('Response actions history', () => {
it('shows Failed status badge for expired actions', async () => {
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data: await getActionListMock({
actionCount: 2,
isCompleted: false,
@ -645,7 +637,7 @@ describe.skip('Response actions history', () => {
it('shows Pending status badge for pending actions', async () => {
mockUseGetEndpointActionList = {
...baseMockedActionList,
...getBaseMockedActionList(),
data: await getActionListMock({ actionCount: 2, isCompleted: false, status: 'pending' }),
};
render();