Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Defend Workflows][E2E] Isolate command e2e coverage #154465

Merged
merged 22 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2f884d5
avatar aria label
szwarckonrad Apr 4, 2023
704886c
isolate command e2e coverage
szwarckonrad Apr 5, 2023
feab480
Merge branch 'main' into endpoint-isolate-e2e-coverage
szwarckonrad Apr 5, 2023
5db6e07
typings
szwarckonrad Apr 6, 2023
51b63c3
Merge branch 'main' into endpoint-isolate-e2e-coverage
szwarckonrad Apr 6, 2023
4de9906
typings
szwarckonrad Apr 6, 2023
67eb92c
cleanup
szwarckonrad Apr 17, 2023
12874a1
Merge branch 'main' into endpoint-isolate-e2e-coverage
szwarckonrad Apr 17, 2023
fcc702f
use custom document generator
szwarckonrad Apr 17, 2023
25674ff
Merge branch 'main' into endpoint-isolate-e2e-coverage
szwarckonrad Apr 17, 2023
7c9043f
Merge branch 'main' into endpoint-isolate-e2e-coverage
szwarckonrad Apr 18, 2023
c54509b
manualy refresh result list
szwarckonrad Apr 18, 2023
d2fbb5d
Merge branch 'main' into endpoint-isolate-e2e-coverage
szwarckonrad Apr 18, 2023
9415935
remove artifacts after endpoints.cy.ts test
szwarckonrad Apr 18, 2023
ac9e110
Merge branch 'main' into endpoint-isolate-e2e-coverage
szwarckonrad Apr 18, 2023
f84233b
Merge branch 'main' into endpoint-isolate-e2e-coverage
szwarckonrad Apr 20, 2023
b3a7460
cleanup
szwarckonrad Apr 20, 2023
b5b6941
tweaks
szwarckonrad Apr 21, 2023
62fa777
Merge branch 'main' into endpoint-isolate-e2e-coverage
szwarckonrad Apr 21, 2023
27101e2
Merge branch 'main' into endpoint-isolate-e2e-coverage
szwarckonrad Apr 21, 2023
391ed8c
type returns of helper functions
szwarckonrad Apr 21, 2023
db17840
Merge remote-tracking branch 'origin/endpoint-isolate-e2e-coverage' i…
szwarckonrad Apr 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const createActionAttachmentUserActionBuilder = ({
// TODO: Fix this manually. Issue #123375
// eslint-disable-next-line react/display-name
build: () => {
const actionIconName = comment.actions.type === 'isolate' ? 'lock' : 'lockOpen';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these changes intentionally done? or a result of perhaps a merge conflict resolution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these were done intentionally. Icon type does not propagate to the component correctly for lock variant, thats why I've used the aria field that works properly. I will create a PR that fixes this in the UI project. One of the tests from TestRail was about making sure the proper icon is being displayed, hence these changes.

return [
{
username: (
Expand All @@ -52,7 +53,8 @@ export const createActionAttachmentUserActionBuilder = ({
),
'data-test-subj': 'endpoint-action',
timestamp: <UserActionTimestamp createdAt={userAction.createdAt} />,
timelineAvatar: comment.actions.type === 'isolate' ? 'lock' : 'lockOpen',
timelineAvatar: actionIconName,
timelineAvatarAriaLabel: actionIconName,
actions: <UserActionCopyLink id={comment.id} />,
children: comment.comment.trim().length > 0 && (
<ContentWrapper data-test-subj="user-action-markdown">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface GetCustomEndpointMetadataGeneratorOptions {
version: string;
/** OS type for the generated endpoint hosts */
os: 'macOS' | 'windows' | 'linux';
isolation: boolean;
}

/**
Expand All @@ -33,6 +34,7 @@ export class EndpointMetadataGenerator extends BaseDataGenerator {
static custom({
version,
os,
isolation,
}: Partial<GetCustomEndpointMetadataGeneratorOptions> = {}): typeof EndpointMetadataGenerator {
return class extends EndpointMetadataGenerator {
generate(overrides: DeepPartial<HostMetadataInterface> = {}): HostMetadataInterface {
Expand All @@ -54,6 +56,9 @@ export class EndpointMetadataGenerator extends BaseDataGenerator {
set(overrides, 'host.os', EndpointMetadataGenerator.windowsOSFields);
}
}
if (isolation !== undefined) {
set(overrides, 'Endpoint.state.isolation', isolation);
}

return super.generate(overrides);
}
Expand Down Expand Up @@ -104,10 +109,10 @@ export class EndpointMetadataGenerator extends BaseDataGenerator {
/** Generate an Endpoint host metadata document */
generate(overrides: DeepPartial<HostMetadataInterface> = {}): HostMetadataInterface {
const ts = overrides['@timestamp'] ?? new Date().getTime();
const hostName = this.randomHostname();
const hostName = overrides?.host?.hostname ?? this.randomHostname();
const agentVersion = overrides?.agent?.version ?? this.randomVersion();
const agentId = this.seededUUIDv4();
const isIsolated = this.randomBoolean(0.3);
const isIsolated = overrides?.Endpoint?.state?.isolation ?? this.randomBoolean(0.3);
const capabilities: EndpointCapabilities[] = ['isolation'];

// v8.4 introduced additional endpoint capabilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class EndpointRuleAlertGenerator extends BaseDataGenerator {
const endpointMetadataGenerator = new EndpointMetadataGenerator();
const endpointMetadata = endpointMetadataGenerator.generate({
agent: { version: kibanaPackageJson.version },
host: { hostname: overrides?.host?.hostname },
Endpoint: { state: { isolation: overrides?.Endpoint?.state?.isolation } },
szwarckonrad marked this conversation as resolved.
Show resolved Hide resolved
});
const now = overrides['@timestamp'] ?? new Date().toISOString();
const endpointAgentId = overrides?.agent?.id ?? this.seededUUIDv4();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface IndexedHostsResponse
* @param policyResponseIndex
* @param enrollFleet
* @param generator
* @param disableEndpointActionsForHost
*/
export async function indexEndpointHostDocs({
numDocs,
Expand All @@ -86,6 +87,7 @@ export async function indexEndpointHostDocs({
policyResponseIndex,
enrollFleet,
generator,
withResponseActions = true,
}: {
numDocs: number;
client: Client;
Expand All @@ -96,6 +98,7 @@ export async function indexEndpointHostDocs({
policyResponseIndex: string;
enrollFleet: boolean;
generator: EndpointDocGenerator;
withResponseActions?: boolean;
}): Promise<IndexedHostsResponse> {
const timeBetweenDocs = 6 * 3600 * 1000; // 6 hours between metadata documents
const timestamp = new Date().getTime();
Expand Down Expand Up @@ -190,13 +193,15 @@ export async function indexEndpointHostDocs({
},
};

// Create some fleet endpoint actions and .logs-endpoint actions for this Host
const actionsResponse = await indexEndpointAndFleetActionsForHost(
client,
hostMetadata,
undefined
);
mergeAndAppendArrays(response, actionsResponse);
if (withResponseActions) {
// Create some fleet endpoint actions and .logs-endpoint actions for this Host
const actionsResponse = await indexEndpointAndFleetActionsForHost(
client,
hostMetadata,
undefined
);
mergeAndAppendArrays(response, actionsResponse);
}
}

await client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { EndpointRuleAlertGenerator } from '../data_generators/endpoint_rule_ale
export interface IndexEndpointRuleAlertsOptions {
esClient: Client;
endpointAgentId: string;
endpointHostname?: string;
endpointIsolated?: boolean;
count?: number;
log?: ToolingLog;
}
Expand All @@ -40,12 +42,16 @@ export interface DeletedIndexedEndpointRuleAlerts {
* written them to for a given endpoint
* @param esClient
* @param endpointAgentId
* @param endpointHostname
* @param endpointIsolated
* @param count
* @param log
*/
export const indexEndpointRuleAlerts = async ({
esClient,
endpointAgentId,
endpointHostname,
szwarckonrad marked this conversation as resolved.
Show resolved Hide resolved
endpointIsolated,
count = 1,
log = new ToolingLog(),
}: IndexEndpointRuleAlertsOptions): Promise<IndexedEndpointRuleAlerts> => {
Expand All @@ -57,7 +63,11 @@ export const indexEndpointRuleAlerts = async ({
const indexedAlerts: estypes.IndexResponse[] = [];

for (let n = 0; n < count; n++) {
const alert = alertsGenerator.generate({ agent: { id: endpointAgentId } });
const alert = alertsGenerator.generate({
szwarckonrad marked this conversation as resolved.
Show resolved Hide resolved
agent: { id: endpointAgentId },
host: { hostname: endpointHostname },
...(endpointIsolated ? { Endpoint: { state: { isolation: endpointIsolated } } } : {}),
});
const indexedAlert = await esClient.index({
index: `${DEFAULT_ALERTS_INDEX}-default`,
refresh: 'wait_for',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ export class EndpointDocGenerator extends BaseDataGenerator {

private createHostData(): CommonHostInfo {
const { agent, elastic, host, Endpoint } = this.metadataGenerator.generate({
Endpoint: { policy: { applied: this.randomChoice(APPLIED_POLICIES) } },
Endpoint: {
policy: { applied: this.randomChoice(APPLIED_POLICIES) },
},
});

return { agent, elastic, host, Endpoint };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type IndexedHostsAndAlertsResponse = IndexedHostsResponse;
* @param fleet
* @param options
* @param DocGenerator
* @param withResponseActions
*/
export async function indexHostsAndAlerts(
client: Client,
Expand All @@ -62,7 +63,8 @@ export async function indexHostsAndAlerts(
alertsPerHost: number,
fleet: boolean,
options: TreeOptions = {},
DocGenerator: typeof EndpointDocGenerator = EndpointDocGenerator
DocGenerator: typeof EndpointDocGenerator = EndpointDocGenerator,
withResponseActions = true
): Promise<IndexedHostsAndAlertsResponse> {
const random = seedrandom(seed);
const epmEndpointPackage = await getEndpointPackageInfo(kbnClient);
Expand Down Expand Up @@ -114,6 +116,7 @@ export async function indexHostsAndAlerts(
policyResponseIndex,
enrollFleet: fleet,
generator,
withResponseActions,
});

mergeAndAppendArrays(response, indexedHosts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@

import type { CasePostRequest } from '@kbn/cases-plugin/common/api';
import type { IndexedEndpointPolicyResponse } from '../../../common/endpoint/data_loaders/index_endpoint_policy_response';
import type { HostPolicyResponse } from '../../../common/endpoint/types';
import type { IndexEndpointHostsCyTaskOptions } from './types';
import type {
HostPolicyResponse,
LogsEndpointActionResponse,
} from '../../../common/endpoint/types';
import type { IndexEndpointHostsCyTaskOptions, HostActionResponse } from './types';
import type {
DeleteIndexedFleetEndpointPoliciesResponse,
IndexedFleetEndpointPolicyResponse,
Expand Down Expand Up @@ -115,6 +118,12 @@ declare global {
arg: IndexedEndpointPolicyResponse,
options?: Partial<Loggable & Timeoutable>
): Chainable<null>;

task(
name: 'sendHostActionResponse',
arg: HostActionResponse,
options?: Partial<Loggable & Timeoutable>
): Chainable<LogsEndpointActionResponse>;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,31 @@
* 2.0.
*/

import type { ReturnTypeFromChainable } from '../../types';
import { indexEndpointHosts } from '../../tasks/index_endpoint_hosts';
import { login } from '../../tasks/login';
import { runEndpointLoaderScript } from '../../tasks/run_endpoint_loader';

describe('Endpoints page', () => {
let endpointData: ReturnTypeFromChainable<typeof indexEndpointHosts>;

before(() => {
runEndpointLoaderScript();
indexEndpointHosts().then((indexEndpoints) => {
endpointData = indexEndpoints;
});
});

beforeEach(() => {
login();
});

after(() => {
if (endpointData) {
endpointData.cleanup();
// @ts-expect-error ignore setting to undefined
endpointData = undefined;
}
});

it('Loads the endpoints page', () => {
cy.visit('/app/security/administration/endpoints');
cy.contains('Hosts running Elastic Defend').should('exist');
Expand Down
Loading