Skip to content

Commit

Permalink
Merge branch '8.11' into backport/8.11/pr-170127
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Nov 1, 2023
2 parents 0917698 + 1015325 commit e8dce55
Show file tree
Hide file tree
Showing 18 changed files with 893 additions and 590 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const useGetCaseConfiguration = () => {
const { showErrorToast } = useCasesToast();

return useQuery<CasesConfigurationUI | null, ServerError, CasesConfigurationUI>(
casesQueriesKeys.configuration(),
casesQueriesKeys.configuration({ owner }),
({ signal }) => getCaseConfigure({ owner, signal }),
{
select: transformConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as api from './api';
import { useToasts } from '../../common/lib/kibana';
import type { AppMockRenderer } from '../../common/mock';
import { createAppMockRenderer } from '../../common/mock';
import { ConnectorTypes } from '../../../common';
import { ConnectorTypes, SECURITY_SOLUTION_OWNER } from '../../../common';
import { casesQueriesKeys } from '../constants';

jest.mock('./api');
Expand Down Expand Up @@ -130,7 +130,9 @@ describe('useCreateAttachments', () => {

await waitForNextUpdate();

expect(queryClientSpy).toHaveBeenCalledWith(casesQueriesKeys.configuration());
expect(queryClientSpy).toHaveBeenCalledWith(
casesQueriesKeys.configuration({ owner: [SECURITY_SOLUTION_OWNER] })
);
});

it('shows the success toaster', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const usePersistConfiguration = () => {
{
mutationKey: casesMutationsKeys.persistCaseConfiguration,
onSuccess: () => {
queryClient.invalidateQueries(casesQueriesKeys.configuration());
queryClient.invalidateQueries(casesQueriesKeys.configuration({ owner }));
showSuccessToast(i18n.SUCCESS_CONFIGURE);
},
onError: (error: ServerError) => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/public/containers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const casesQueriesKeys = {
categories: () => [...casesQueriesKeys.all, 'categories'] as const,
alertFeatureIds: (alertRegistrationContexts: string[]) =>
[...casesQueriesKeys.alerts, 'features', alertRegistrationContexts] as const,
configuration: () => [...casesQueriesKeys.all, 'configuration'] as const,
configuration: (params: unknown) => [...casesQueriesKeys.all, 'configuration', params] as const,
};

export const casesMutationsKeys = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* 2.0.
*/

import { getEndpointSecurityPolicyManager } from '../../../../../scripts/endpoint/common/roles_users';
import { getRoleWithArtifactReadPrivilege } from '../../fixtures/role_with_artifact_read_privilege';
import { getEndpointSecurityPolicyManager } from '../../../../../scripts/endpoint/common/roles_users/endpoint_security_policy_manager';
import { getArtifactsListTestsData } from '../../fixtures/artifacts_page';
import { visitPolicyDetailsPage } from '../../screens/policy_details';
import {
createPerPolicyArtifact,
createArtifactList,
createPerPolicyArtifact,
removeAllArtifacts,
removeExceptionsList,
yieldFirstPolicyID,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.
*/
import type { PolicyData } from '../../../../../../common/endpoint/types';
import type { CreateAndEnrollEndpointHostResponse } from '../../../../../../scripts/endpoint/common/endpoint_host_services';
import {
inputConsoleCommand,
openResponseConsoleFromEndpointList,
submitCommand,
waitForCommandToBeExecuted,
waitForEndpointListPageToBeLoaded,
} from '../../../tasks/response_console';
import type { IndexedFleetEndpointPolicyResponse } from '../../../../../../common/endpoint/data_loaders/index_fleet_endpoint_policy';
import { createAgentPolicyTask, getEndpointIntegrationVersion } from '../../../tasks/fleet';

import { login } from '../../../tasks/login';
import { enableAllPolicyProtections } from '../../../tasks/endpoint_policy';
import { createEndpointHost } from '../../../tasks/create_endpoint_host';
import { deleteAllLoadedEndpointData } from '../../../tasks/delete_all_endpoint_data';

describe('Response console', { tags: ['@ess', '@serverless'] }, () => {
beforeEach(() => {
login();
});

describe('Execute operations: execute', () => {
const homeFilePath = process.env.CI || true ? '/home/vagrant' : `/home/ubuntu`;

let indexedPolicy: IndexedFleetEndpointPolicyResponse;
let policy: PolicyData;
let createdHost: CreateAndEnrollEndpointHostResponse;

before(() => {
getEndpointIntegrationVersion().then((version) =>
createAgentPolicyTask(version).then((data) => {
indexedPolicy = data;
policy = indexedPolicy.integrationPolicies[0];

return enableAllPolicyProtections(policy.id).then(() => {
// Create and enroll a new Endpoint host
return createEndpointHost(policy.policy_id).then((host) => {
createdHost = host as CreateAndEnrollEndpointHostResponse;
});
});
})
);
});

after(() => {
if (createdHost) {
cy.task('destroyEndpointHost', createdHost);
}

if (indexedPolicy) {
cy.task('deleteIndexedFleetEndpointPolicies', indexedPolicy);
}

if (createdHost) {
deleteAllLoadedEndpointData({ endpointAgentIds: [createdHost.agentId] });
}
});

it('"execute --command" - should execute a command', () => {
waitForEndpointListPageToBeLoaded(createdHost.hostname);
openResponseConsoleFromEndpointList();
inputConsoleCommand(`execute --command "ls -al ${homeFilePath}"`);
submitCommand();
waitForCommandToBeExecuted('execute');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* 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.
*/
import type { PolicyData } from '../../../../../../common/endpoint/types';
import type { CreateAndEnrollEndpointHostResponse } from '../../../../../../scripts/endpoint/common/endpoint_host_services';
import {
inputConsoleCommand,
openResponseConsoleFromEndpointList,
submitCommand,
waitForCommandToBeExecuted,
waitForEndpointListPageToBeLoaded,
} from '../../../tasks/response_console';
import type { IndexedFleetEndpointPolicyResponse } from '../../../../../../common/endpoint/data_loaders/index_fleet_endpoint_policy';
import { createAgentPolicyTask, getEndpointIntegrationVersion } from '../../../tasks/fleet';

import { login } from '../../../tasks/login';
import { enableAllPolicyProtections } from '../../../tasks/endpoint_policy';
import { createEndpointHost } from '../../../tasks/create_endpoint_host';
import { deleteAllLoadedEndpointData } from '../../../tasks/delete_all_endpoint_data';

describe('Response console', { tags: ['@ess', '@serverless'] }, () => {
beforeEach(() => {
login();
});

describe('File operations: get-file and upload', () => {
const homeFilePath = process.env.CI || true ? '/home/vagrant' : `/home/ubuntu`;

const fileContent = 'This is a test file for the get-file command.';
const filePath = `${homeFilePath}/test_file.txt`;

let indexedPolicy: IndexedFleetEndpointPolicyResponse;
let policy: PolicyData;
let createdHost: CreateAndEnrollEndpointHostResponse;

before(() => {
getEndpointIntegrationVersion().then((version) =>
createAgentPolicyTask(version).then((data) => {
indexedPolicy = data;
policy = indexedPolicy.integrationPolicies[0];

return enableAllPolicyProtections(policy.id).then(() => {
// Create and enroll a new Endpoint host
return createEndpointHost(policy.policy_id).then((host) => {
createdHost = host as CreateAndEnrollEndpointHostResponse;
});
});
})
);
});

after(() => {
if (createdHost) {
cy.task('destroyEndpointHost', createdHost);
}

if (indexedPolicy) {
cy.task('deleteIndexedFleetEndpointPolicies', indexedPolicy);
}

if (createdHost) {
deleteAllLoadedEndpointData({ endpointAgentIds: [createdHost.agentId] });
}
});

it('"get-file --path" - should retrieve a file', () => {
waitForEndpointListPageToBeLoaded(createdHost.hostname);
cy.task('createFileOnEndpoint', {
hostname: createdHost.hostname,
path: filePath,
content: fileContent,
});
openResponseConsoleFromEndpointList();
inputConsoleCommand(`get-file --path ${filePath}`);
submitCommand();
cy.getByTestSubj('getFileSuccess', { timeout: 60000 }).within(() => {
cy.contains('File retrieved from the host.');
cy.contains('(ZIP file passcode: elastic)');
cy.contains(
'Files are periodically deleted to clear storage space. Download and save file locally if needed.'
);
cy.contains('Click here to download').click();
const downloadsFolder = Cypress.config('downloadsFolder');
cy.readFile(`${downloadsFolder}/upload.zip`);

cy.task('uploadFileToEndpoint', {
hostname: createdHost.hostname,
srcPath: `${downloadsFolder}/upload.zip`,
destPath: `${homeFilePath}/upload.zip`,
});

cy.task('readZippedFileContentOnEndpoint', {
hostname: createdHost.hostname,
path: `${homeFilePath}/upload.zip`,
password: 'elastic',
}).then((unzippedFileContent) => {
expect(unzippedFileContent).to.equal(fileContent);
});
});
});

it('"upload --file" - should upload a file', () => {
waitForEndpointListPageToBeLoaded(createdHost.hostname);
openResponseConsoleFromEndpointList();
inputConsoleCommand(`upload --file`);
cy.getByTestSubj('console-arg-file-picker').selectFile(
{
contents: Cypress.Buffer.from('upload file content here!'),
fileName: 'upload_file.txt',
lastModified: Date.now(),
},
{ force: true }
);
submitCommand();
waitForCommandToBeExecuted('upload');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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.
*/

import type { PolicyData } from '../../../../../../common/endpoint/types';
import type { CreateAndEnrollEndpointHostResponse } from '../../../../../../scripts/endpoint/common/endpoint_host_services';
import {
openResponseConsoleFromEndpointList,
performCommandInputChecks,
submitCommand,
waitForCommandToBeExecuted,
waitForEndpointListPageToBeLoaded,
} from '../../../tasks/response_console';
import type { IndexedFleetEndpointPolicyResponse } from '../../../../../../common/endpoint/data_loaders/index_fleet_endpoint_policy';
import { createAgentPolicyTask, getEndpointIntegrationVersion } from '../../../tasks/fleet';
import {
checkEndpointListForOnlyIsolatedHosts,
checkEndpointListForOnlyUnIsolatedHosts,
} from '../../../tasks/isolate';

import { login } from '../../../tasks/login';
import { enableAllPolicyProtections } from '../../../tasks/endpoint_policy';
import { createEndpointHost } from '../../../tasks/create_endpoint_host';
import { deleteAllLoadedEndpointData } from '../../../tasks/delete_all_endpoint_data';

describe('Response console', { tags: ['@ess', '@serverless'] }, () => {
beforeEach(() => {
login();
});

describe('Host Isolation: isolate and release an endpoint', () => {
let indexedPolicy: IndexedFleetEndpointPolicyResponse;
let policy: PolicyData;
let createdHost: CreateAndEnrollEndpointHostResponse;

before(() => {
getEndpointIntegrationVersion().then((version) =>
createAgentPolicyTask(version).then((data) => {
indexedPolicy = data;
policy = indexedPolicy.integrationPolicies[0];

return enableAllPolicyProtections(policy.id).then(() => {
// Create and enroll a new Endpoint host
return createEndpointHost(policy.policy_id).then((host) => {
createdHost = host as CreateAndEnrollEndpointHostResponse;
});
});
})
);
});

after(() => {
if (createdHost) {
cy.task('destroyEndpointHost', createdHost);
}

if (indexedPolicy) {
cy.task('deleteIndexedFleetEndpointPolicies', indexedPolicy);
}

if (createdHost) {
deleteAllLoadedEndpointData({ endpointAgentIds: [createdHost.agentId] });
}
});

it('should isolate host from response console', () => {
const command = 'isolate';
waitForEndpointListPageToBeLoaded(createdHost.hostname);
checkEndpointListForOnlyUnIsolatedHosts();
openResponseConsoleFromEndpointList();
performCommandInputChecks(command);
submitCommand();
waitForCommandToBeExecuted(command);
waitForEndpointListPageToBeLoaded(createdHost.hostname);
checkEndpointListForOnlyIsolatedHosts();
});

it('should release host from response console', () => {
const command = 'release';
waitForEndpointListPageToBeLoaded(createdHost.hostname);
checkEndpointListForOnlyIsolatedHosts();
openResponseConsoleFromEndpointList();
performCommandInputChecks(command);
submitCommand();
waitForCommandToBeExecuted(command);
waitForEndpointListPageToBeLoaded(createdHost.hostname);
checkEndpointListForOnlyUnIsolatedHosts();
});
});
});
Loading

0 comments on commit e8dce55

Please sign in to comment.