Skip to content

Commit

Permalink
[Security Solution][Endpoint] Move all endpoint responder jest tests …
Browse files Browse the repository at this point in the history
…for response actions to (jest) integration tests (#142006)

* un-skip tests in endpoint_responder

* move endpoint responder tests to integration tests

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* Add jest integration config file

* add standard setup for react testing `data-test-subj` testIdAttribute

* change `@kbn/test/jest_integration` preset to include all `setupFilesAfterEnv` from base preset

* Fix jest testing warning/error about missing react `key` in command_usage.tsx component

* Stabilise test when checking calls to action details api

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
paul-tavares and kibanamachine authored Sep 29, 2022
1 parent 7c9875c commit b2ab340
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 66 deletions.
3 changes: 1 addition & 2 deletions packages/kbn-test/jest_integration/jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ module.exports = {
(pattern) => !pattern.includes('integration_tests')
),
setupFilesAfterEnv: [
...preset.setupFilesAfterEnv,
'<rootDir>/node_modules/@kbn/test/target_node/src/jest/setup/after_env.integration.js',
'<rootDir>/node_modules/@kbn/test/target_node/src/jest/setup/mocks.moment_timezone.js',
'<rootDir>/node_modules/@kbn/test/target_node/src/jest/setup/mocks.eui.js',
],
reporters: [
'default',
Expand Down
12 changes: 12 additions & 0 deletions x-pack/plugins/security_solution/jest.integration.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

module.exports = {
preset: '@kbn/test/jest_integration',
rootDir: '../../..',
roots: ['<rootDir>/x-pack/plugins/security_solution'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export const CommandInputUsage = memo<Pick<CommandUsageProps, 'commandDef'>>(({
const usageHelp = useMemo(() => {
return getArgumentsForCommand(commandDef).map((usage, index) => {
return (
<>
<React.Fragment key={`helpUsage-${index}`}>
{index > 0 && <EuiSpacer size="xs" />}
<ConsoleCodeBlock>{`${commandDef.name} ${usage}`}</ConsoleCodeBlock>
</>
</React.Fragment>
);
});
}, [commandDef]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
* 2.0.
*/

import type { AppContextTestRender } from '../../../common/mock/endpoint';
import { createAppRootMockRenderer } from '../../../common/mock/endpoint';
import type { AppContextTestRender } from '../../../../common/mock/endpoint';
import { createAppRootMockRenderer } from '../../../../common/mock/endpoint';
import {
ConsoleManagerTestComponent,
getConsoleManagerMockRenderResultQueriesAndActions,
} from '../console/components/console_manager/mocks';
} from '../../console/components/console_manager/mocks';
import React from 'react';
import { getEndpointResponseActionsConsoleCommands } from './endpoint_response_actions_console_commands';
import { responseActionsHttpMocks } from '../../mocks/response_actions_http_mocks';
import { enterConsoleCommand } from '../console/mocks';
import { getEndpointResponseActionsConsoleCommands } from '../endpoint_response_actions_console_commands';
import { responseActionsHttpMocks } from '../../../mocks/response_actions_http_mocks';
import { enterConsoleCommand } from '../../console/mocks';
import { waitFor } from '@testing-library/react';
import type { ResponderCapabilities } from '../../../../common/endpoint/constants';
import { RESPONDER_CAPABILITIES } from '../../../../common/endpoint/constants';
import type { ResponderCapabilities } from '../../../../../common/endpoint/constants';
import { RESPONDER_CAPABILITIES } from '../../../../../common/endpoint/constants';

describe('When using processes action from response actions console', () => {
let render: (
Expand Down Expand Up @@ -161,6 +161,7 @@ describe('When using processes action from response actions console', () => {

await waitFor(() => {
expect(apiMocks.responseProvider.processes).toHaveBeenCalledTimes(1);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);
});

// Hide the console
Expand All @@ -182,20 +183,20 @@ describe('When using processes action from response actions console', () => {
path: '/api/endpoint/action/1.2.3',
});
pendingDetailResponse.data.isCompleted = false;
apiMocks.responseProvider.actionDetails.mockClear();
apiMocks.responseProvider.actionDetails.mockReturnValue(pendingDetailResponse);
await render();

expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(2);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);

await consoleManagerMockAccess.openRunningConsole();

await waitFor(() => {
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(3);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(2);
});
});

// FLAKY: https://github.com/elastic/kibana/issues/139707
it.skip('should display completion output if done (no additional API calls)', async () => {
it('should display completion output if done (no additional API calls)', async () => {
await render();

expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
* 2.0.
*/

import type { AppContextTestRender } from '../../../common/mock/endpoint';
import { createAppRootMockRenderer } from '../../../common/mock/endpoint';
import type { AppContextTestRender } from '../../../../common/mock/endpoint';
import { createAppRootMockRenderer } from '../../../../common/mock/endpoint';
import {
ConsoleManagerTestComponent,
getConsoleManagerMockRenderResultQueriesAndActions,
} from '../console/components/console_manager/mocks';
} from '../../console/components/console_manager/mocks';
import React from 'react';
import { getEndpointResponseActionsConsoleCommands } from './endpoint_response_actions_console_commands';
import { responseActionsHttpMocks } from '../../mocks/response_actions_http_mocks';
import { enterConsoleCommand } from '../console/mocks';
import { getEndpointResponseActionsConsoleCommands } from '../endpoint_response_actions_console_commands';
import { responseActionsHttpMocks } from '../../../mocks/response_actions_http_mocks';
import { enterConsoleCommand } from '../../console/mocks';
import { waitFor } from '@testing-library/react';
import type { ResponderCapabilities } from '../../../../common/endpoint/constants';
import { RESPONDER_CAPABILITIES } from '../../../../common/endpoint/constants';
import { getDeferred } from '../../mocks/utils';
import type { ResponderCapabilities } from '../../../../../common/endpoint/constants';
import { RESPONDER_CAPABILITIES } from '../../../../../common/endpoint/constants';
import { getDeferred } from '../../../mocks/utils';

describe('When using isolate action from response actions console', () => {
let render: (
Expand Down Expand Up @@ -170,6 +170,7 @@ describe('When using isolate action from response actions console', () => {

await waitFor(() => {
expect(apiMocks.responseProvider.isolateHost).toHaveBeenCalledTimes(1);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);
});

// Hide the console
Expand All @@ -191,20 +192,20 @@ describe('When using isolate action from response actions console', () => {
path: '/api/endpoint/action/1.2.3',
});
pendingDetailResponse.data.isCompleted = false;
apiMocks.responseProvider.actionDetails.mockClear();
apiMocks.responseProvider.actionDetails.mockReturnValue(pendingDetailResponse);
await render();

expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(2);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);

await consoleManagerMockAccess.openRunningConsole();

await waitFor(() => {
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(3);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(2);
});
});

// SKIP: https://github.com/elastic/kibana/issues/139586
it.skip('should display completion output if done (no additional API calls)', async () => {
it('should display completion output if done (no additional API calls)', async () => {
await render();

expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
* 2.0.
*/

import type { AppContextTestRender } from '../../../common/mock/endpoint';
import { createAppRootMockRenderer } from '../../../common/mock/endpoint';
import type { AppContextTestRender } from '../../../../common/mock/endpoint';
import { createAppRootMockRenderer } from '../../../../common/mock/endpoint';
import {
ConsoleManagerTestComponent,
getConsoleManagerMockRenderResultQueriesAndActions,
} from '../console/components/console_manager/mocks';
} from '../../console/components/console_manager/mocks';
import React from 'react';
import { getEndpointResponseActionsConsoleCommands } from './endpoint_response_actions_console_commands';
import { enterConsoleCommand } from '../console/mocks';
import { getEndpointResponseActionsConsoleCommands } from '../endpoint_response_actions_console_commands';
import { enterConsoleCommand } from '../../console/mocks';
import { waitFor } from '@testing-library/react';
import { responseActionsHttpMocks } from '../../mocks/response_actions_http_mocks';
import type { ResponderCapabilities } from '../../../../common/endpoint/constants';
import { RESPONDER_CAPABILITIES } from '../../../../common/endpoint/constants';
import { responseActionsHttpMocks } from '../../../mocks/response_actions_http_mocks';
import type { ResponderCapabilities } from '../../../../../common/endpoint/constants';
import { RESPONDER_CAPABILITIES } from '../../../../../common/endpoint/constants';

describe('When using the kill-process action from response actions console', () => {
let render: (
Expand Down Expand Up @@ -250,6 +250,7 @@ describe('When using the kill-process action from response actions console', ()

await waitFor(() => {
expect(apiMocks.responseProvider.killProcess).toHaveBeenCalledTimes(1);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);
});

// Hide the console
Expand All @@ -270,21 +271,23 @@ describe('When using the kill-process action from response actions console', ()
const pendingDetailResponse = apiMocks.responseProvider.actionDetails({
path: '/api/endpoint/action/1.2.3',
});

pendingDetailResponse.data.isCompleted = false;
apiMocks.responseProvider.actionDetails.mockClear();
apiMocks.responseProvider.actionDetails.mockReturnValue(pendingDetailResponse);

await render();

expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(2);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);

await consoleManagerMockAccess.openRunningConsole();

await waitFor(() => {
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(3);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(2);
});
});

// FLAKY: https://github.com/elastic/kibana/issues/139962
it.skip('should display completion output if done (no additional API calls)', async () => {
it('should display completion output if done (no additional API calls)', async () => {
await render();

expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
* 2.0.
*/

import type { AppContextTestRender } from '../../../common/mock/endpoint';
import { createAppRootMockRenderer } from '../../../common/mock/endpoint';
import type { AppContextTestRender } from '../../../../common/mock/endpoint';
import { createAppRootMockRenderer } from '../../../../common/mock/endpoint';
import {
ConsoleManagerTestComponent,
getConsoleManagerMockRenderResultQueriesAndActions,
} from '../console/components/console_manager/mocks';
} from '../../console/components/console_manager/mocks';
import React from 'react';
import { getEndpointResponseActionsConsoleCommands } from './endpoint_response_actions_console_commands';
import { enterConsoleCommand } from '../console/mocks';
import { getEndpointResponseActionsConsoleCommands } from '../endpoint_response_actions_console_commands';
import { enterConsoleCommand } from '../../console/mocks';
import { waitFor } from '@testing-library/react';
import { responseActionsHttpMocks } from '../../mocks/response_actions_http_mocks';
import type { ResponderCapabilities } from '../../../../common/endpoint/constants';
import { RESPONDER_CAPABILITIES } from '../../../../common/endpoint/constants';
import { getDeferred } from '../../mocks/utils';
import { responseActionsHttpMocks } from '../../../mocks/response_actions_http_mocks';
import type { ResponderCapabilities } from '../../../../../common/endpoint/constants';
import { RESPONDER_CAPABILITIES } from '../../../../../common/endpoint/constants';
import { getDeferred } from '../../../mocks/utils';

describe('When using the release action from response actions console', () => {
let render: (
Expand Down Expand Up @@ -171,6 +171,7 @@ describe('When using the release action from response actions console', () => {

await waitFor(() => {
expect(apiMocks.responseProvider.releaseHost).toHaveBeenCalledTimes(1);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);
});

// Hide the console
Expand All @@ -192,20 +193,20 @@ describe('When using the release action from response actions console', () => {
path: '/api/endpoint/action/1.2.3',
});
pendingDetailResponse.data.isCompleted = false;
apiMocks.responseProvider.actionDetails.mockClear();
apiMocks.responseProvider.actionDetails.mockReturnValue(pendingDetailResponse);
await render();

expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(2);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);

await consoleManagerMockAccess.openRunningConsole();

await waitFor(() => {
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(3);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(2);
});
});

// FLAKY: https://github.com/elastic/kibana/issues/139641
it.skip('should display completion output if done (no additional API calls)', async () => {
it('should display completion output if done (no additional API calls)', async () => {
await render();

expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
* 2.0.
*/

import type { AppContextTestRender } from '../../../common/mock/endpoint';
import { createAppRootMockRenderer } from '../../../common/mock/endpoint';
import type { AppContextTestRender } from '../../../../common/mock/endpoint';
import { createAppRootMockRenderer } from '../../../../common/mock/endpoint';
import {
ConsoleManagerTestComponent,
getConsoleManagerMockRenderResultQueriesAndActions,
} from '../console/components/console_manager/mocks';
} from '../../console/components/console_manager/mocks';
import React from 'react';
import { getEndpointResponseActionsConsoleCommands } from './endpoint_response_actions_console_commands';
import { enterConsoleCommand } from '../console/mocks';
import { getEndpointResponseActionsConsoleCommands } from '../endpoint_response_actions_console_commands';
import { enterConsoleCommand } from '../../console/mocks';
import { waitFor } from '@testing-library/react';
import { responseActionsHttpMocks } from '../../mocks/response_actions_http_mocks';
import type { ResponderCapabilities } from '../../../../common/endpoint/constants';
import { RESPONDER_CAPABILITIES } from '../../../../common/endpoint/constants';
import { responseActionsHttpMocks } from '../../../mocks/response_actions_http_mocks';
import type { ResponderCapabilities } from '../../../../../common/endpoint/constants';
import { RESPONDER_CAPABILITIES } from '../../../../../common/endpoint/constants';

describe('When using the suspend-process action from response actions console', () => {
let render: (
Expand Down Expand Up @@ -241,6 +241,7 @@ describe('When using the suspend-process action from response actions console',

await waitFor(() => {
expect(apiMocks.responseProvider.suspendProcess).toHaveBeenCalledTimes(1);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);
});

// Hide the console
Expand All @@ -262,20 +263,20 @@ describe('When using the suspend-process action from response actions console',
path: '/api/endpoint/action/1.2.3',
});
pendingDetailResponse.data.isCompleted = false;
apiMocks.responseProvider.actionDetails.mockClear();
apiMocks.responseProvider.actionDetails.mockReturnValue(pendingDetailResponse);
await render();

expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(2);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);

await consoleManagerMockAccess.openRunningConsole();

await waitFor(() => {
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(3);
expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(2);
});
});

// FLAKY: https://github.com/elastic/kibana/issues/140119
it.skip('should display completion output if done (no additional API calls)', async () => {
it('should display completion output if done (no additional API calls)', async () => {
await render();

expect(apiMocks.responseProvider.actionDetails).toHaveBeenCalledTimes(1);
Expand Down

0 comments on commit b2ab340

Please sign in to comment.