Skip to content

Commit

Permalink
Merge branch 'main' into alerting/maintenance_windows_create_form
Browse files Browse the repository at this point in the history
  • Loading branch information
doakalexi authored Apr 10, 2023
2 parents 740d17c + 17ed210 commit e5d8d89
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 86 deletions.
27 changes: 10 additions & 17 deletions src/dev/build/tasks/fetch_agent_versions_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,22 @@ const getAvailableVersions = async (log: ToolingLog) => {
};
// Endpoint maintained by the web-team and hosted on the elastic website
// See https://github.com/elastic/website-development/issues/9331
const url = 'https://www.elastic.co/content/product_versions';
log.info('Fetching Elastic Agent versions list');
const results = await fetch(url, options);
const rawBody = await results.text();

const url = 'https://www.elastic.co/api/product_versions';
try {
const jsonBody = JSON.parse(rawBody);
log.info('Fetching Elastic Agent versions list');
const results = await fetch(url, options);

const jsonBody = await results.json();

const versions: string[] = (jsonBody.length ? jsonBody[0] : [])
.filter((item: any) => item?.title?.includes('Elastic Agent'))
.map((item: any) => item?.version_number);

log.info(`Retrieved available Elastic Agent versions`);
log.info(`Retrieved available versions`);
return versions;
} catch (error) {
log.warning(`Failed to fetch Elastic Agent versions list`);
log.info(`Status: ${results.status}`);
log.info(rawBody);
if (process.env.BUILDKITE_PULL_REQUEST === 'true') {
log.warning(error);
} else {
throw new Error(error);
}
log.warning(`Failed to fetch versions list`);
log.warning(error);
}
return [];
};
Expand All @@ -54,8 +47,8 @@ export const FetchAgentVersionsList: Task = {
const versionsList = await getAvailableVersions(log);
const AGENT_VERSION_BUILD_FILE = 'x-pack/plugins/fleet/target/agent_versions_list.json';

if (versionsList.length !== 0) {
log.info(`Writing Elastic Agent versions list to ${AGENT_VERSION_BUILD_FILE}`);
if (versionsList !== []) {
log.info(`Writing versions list to ${AGENT_VERSION_BUILD_FILE}`);
await write(
build.resolvePath(AGENT_VERSION_BUILD_FILE),
JSON.stringify(versionsList, null, ' ')
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/cloud_security_posture/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export const CSP_RULE_TEMPLATE_SAVED_OBJECT_TYPE = 'csp-rule-template';

export const CLOUDBEAT_VANILLA = 'cloudbeat/cis_k8s';
export const CLOUDBEAT_EKS = 'cloudbeat/cis_eks';
export const CLOUDBEAT_AKS = 'cloudbeat/cis_aks';
export const CLOUDBEAT_GKE = 'cloudbeat/cis_gke';
export const CLOUDBEAT_AWS = 'cloudbeat/cis_aws';
export const CLOUDBEAT_GCP = 'cloudbeat/cis_gcp';
export const CLOUDBEAT_AZURE = 'cloudbeat/cis_azure';
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 38 additions & 3 deletions x-pack/plugins/cloud_security_posture/public/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ import {
VULN_MGMT_POLICY_TEMPLATE,
CLOUDBEAT_VULN_MGMT_GCP,
CLOUDBEAT_VULN_MGMT_AZURE,
CLOUDBEAT_AKS,
CLOUDBEAT_GKE,
} from '../../common/constants';

import eksLogo from '../assets/icons/cis_eks_logo.svg';
import aksLogo from '../assets/icons/cis_aks_logo.svg';
import gkeLogo from '../assets/icons/cis_gke_logo.svg';

export const statusColors = {
passed: euiThemeVars.euiColorVis0,
Expand All @@ -48,7 +52,7 @@ export interface CloudPostureIntegrationProps {
name: string;
shortName: string;
options: Array<{
type: PostureInput;
type: PostureInput | typeof CLOUDBEAT_AKS | typeof CLOUDBEAT_GKE;
name: string;
benchmark: string;
disabled?: boolean;
Expand Down Expand Up @@ -119,7 +123,7 @@ export const cloudPostureIntegrations: CloudPostureIntegrations = {
{
type: CLOUDBEAT_VANILLA,
name: i18n.translate('xpack.csp.kspmIntegration.vanillaOption.nameTitle', {
defaultMessage: 'Self-Managed/Vanilla Kubernetes',
defaultMessage: 'Self-Managed',
}),
benchmark: i18n.translate('xpack.csp.kspmIntegration.vanillaOption.benchmarkTitle', {
defaultMessage: 'CIS Kubernetes',
Expand All @@ -129,12 +133,43 @@ export const cloudPostureIntegrations: CloudPostureIntegrations = {
{
type: CLOUDBEAT_EKS,
name: i18n.translate('xpack.csp.kspmIntegration.eksOption.nameTitle', {
defaultMessage: 'EKS (Elastic Kubernetes Service)',
defaultMessage: 'EKS',
}),
benchmark: i18n.translate('xpack.csp.kspmIntegration.eksOption.benchmarkTitle', {
defaultMessage: 'CIS EKS',
}),
icon: eksLogo,
tooltip: i18n.translate('xpack.csp.kspmIntegration.eksOption.tooltipContent', {
defaultMessage: 'Elastic Kubernetes Service',
}),
},
{
type: CLOUDBEAT_AKS,
name: i18n.translate('xpack.csp.kspmIntegration.aksOption.nameTitle', {
defaultMessage: 'AKS',
}),
benchmark: i18n.translate('xpack.csp.kspmIntegration.aksOption.benchmarkTitle', {
defaultMessage: 'CIS AKS',
}),
disabled: true,
icon: aksLogo,
tooltip: i18n.translate('xpack.csp.kspmIntegration.aksOption.tooltipContent', {
defaultMessage: 'Azure Kubernetes Service - Coming soon',
}),
},
{
type: CLOUDBEAT_GKE,
name: i18n.translate('xpack.csp.kspmIntegration.gkeOption.nameTitle', {
defaultMessage: 'GKE',
}),
benchmark: i18n.translate('xpack.csp.kspmIntegration.gkeOption.benchmarkTitle', {
defaultMessage: 'CIS GKE',
}),
disabled: true,
icon: gkeLogo,
tooltip: i18n.translate('xpack.csp.kspmIntegration.gkeOption.tooltipContent', {
defaultMessage: 'Google Kubernetes Engine - Coming soon',
}),
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ describe('<CspPolicyTemplateForm />', () => {
it('renders KSPM input selector', () => {
const { getByLabelText } = render(<WrappedComponent newPolicy={getMockPolicyK8s()} />);

const option1 = getByLabelText('Self-Managed/Vanilla Kubernetes');
const option2 = getByLabelText('EKS (Elastic Kubernetes Service)');
const option1 = getByLabelText('Self-Managed');
const option2 = getByLabelText('EKS');

expect(option1).toBeInTheDocument();
expect(option2).toBeInTheDocument();
Expand All @@ -116,7 +116,7 @@ describe('<CspPolicyTemplateForm />', () => {
const eksPolicy = getMockPolicyEKS();

const { getByLabelText } = render(<WrappedComponent newPolicy={k8sPolicy} />);
const option = getByLabelText('EKS (Elastic Kubernetes Service)');
const option = getByLabelText('EKS');
userEvent.click(option);

// Listen to the 2nd triggered by the test.
Expand Down Expand Up @@ -148,8 +148,8 @@ describe('<CspPolicyTemplateForm />', () => {
<WrappedComponent newPolicy={getMockPolicyK8s()} edit={true} />
);

const option1 = getByLabelText('Self-Managed/Vanilla Kubernetes');
const option2 = getByLabelText('EKS (Elastic Kubernetes Service)');
const option1 = getByLabelText('Self-Managed');
const option2 = getByLabelText('EKS');

expect(option1).toBeInTheDocument();
expect(option2).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export class EndpointActionGenerator extends BaseDataGenerator {
stderr_truncated: true,
shell_code: 0,
shell: 'bash',
cwd: '/some/path',
cwd: this.randomChoice(['/some/path', '/a-very/long/path'.repeat(30)]),
output_file_id: 'some-output-file-id',
output_file_stdout_truncated: this.randomChoice([true, false]),
output_file_stderr_truncated: this.randomChoice([true, false]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,42 @@ describe('When using the `ExecuteActionHostResponse` component', () => {
};
});

const outputSuffix = 'output';

it('should show shell info and shell code', async () => {
render();
const { queryByTestId } = renderResult;
expect(queryByTestId(`test-executeResponseOutput-context`)).toBeInTheDocument();
expect(queryByTestId(`test-executeResponseOutput-shell`)).toBeInTheDocument();
expect(queryByTestId(`test-executeResponseOutput-cwd`)).toBeInTheDocument();
});

it('should show execute context accordion as `closed`', async () => {
render();
expect(renderResult.getByTestId('test-executeResponseOutput-context').className).toEqual(
'euiAccordion'
);
});

it('should show current working directory', async () => {
render();
const { queryByTestId } = renderResult;
expect(queryByTestId(`test-executeResponseOutput-context`)).toBeInTheDocument();
expect(queryByTestId(`test-executeResponseOutput-cwd`)).toBeInTheDocument();
});

it('should show execute output and execute errors', async () => {
render();
expect(renderResult.getByTestId('test-executeResponseOutput')).toBeTruthy();
const { queryByTestId } = renderResult;
expect(queryByTestId(`test-executeResponseOutput-${outputSuffix}`)).toBeInTheDocument();
expect(queryByTestId(`test-executeResponseOutput-error`)).toBeInTheDocument();
});

it('should show execute output accordion as `open`', async () => {
render();
const accordionOutputButton = Array.from(
renderResult.getByTestId('test-executeResponseOutput').querySelectorAll('.euiAccordion')
)[0];
expect(accordionOutputButton.className).toContain('isOpen');
expect(
renderResult.getByTestId(`test-executeResponseOutput-${outputSuffix}`).className
).toContain('isOpen');
});

it('should show `-` in output accordion when no output content', async () => {
Expand All @@ -66,13 +91,11 @@ describe('When using the `ExecuteActionHostResponse` component', () => {
},
},
};

render();
const accordionOutputButton = Array.from(
renderResult.getByTestId('test-executeResponseOutput').querySelectorAll('.euiAccordion')
)[0];
expect(accordionOutputButton.textContent).toContain(
`Execution output (truncated)${getEmptyValue()}`
);
expect(
renderResult.getByTestId(`test-executeResponseOutput-${outputSuffix}`).textContent
).toContain(`Execution output (truncated)${getEmptyValue()}`);
});

it('should show `-` in error accordion when no error content', async () => {
Expand All @@ -85,18 +108,19 @@ describe('When using the `ExecuteActionHostResponse` component', () => {
},
},
};

render();
const accordionErrorButton = Array.from(
renderResult.getByTestId('test-executeResponseOutput').querySelectorAll('.euiAccordion')
)[1];
expect(accordionErrorButton.textContent).toContain(
expect(renderResult.getByTestId('test-executeResponseOutput-error').textContent).toContain(
`Execution error (truncated)${getEmptyValue()}`
);
});

it('should not show execute output accordions when no output in action details', () => {
(renderProps.action as ActionDetails).outputs = undefined;

render();
expect(renderResult.queryByTestId('test-executeResponseOutput')).toBeNull();
const { queryByTestId } = renderResult;
expect(queryByTestId(`test-executeResponseOutput-context`)).not.toBeInTheDocument();
expect(queryByTestId(`test-executeResponseOutput-${outputSuffix}`)).not.toBeInTheDocument();
});
});
Loading

0 comments on commit e5d8d89

Please sign in to comment.