Skip to content

Commit

Permalink
[2.11.1] Revert feature commits (#782)
Browse files Browse the repository at this point in the history
* Revert "Make notifications optional 2.11 (#770)"

This reverts commit de6001a.

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>

* Revert "Threat intel feed support for detector creation (#762) (#769)"

This reverts commit 64982b9.

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>

* Revert "[Backport 2.11] Improved display of log types. (#766)"

This reverts commit 25901f6.

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>

* fixed cypress workflow

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>

---------

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
  • Loading branch information
amsiglan committed Nov 8, 2023
1 parent 2feeafd commit c00df74
Show file tree
Hide file tree
Showing 65 changed files with 3,891 additions and 3,262 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cypress-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
branches:
- "*"
env:
OPENSEARCH_DASHBOARDS_VERSION: '2.11.0'
SECURITY_ANALYTICS_BRANCH: '2.11.0.0'
OPENSEARCH_DASHBOARDS_VERSION: '2.11'
SECURITY_ANALYTICS_BRANCH: '2.11'
jobs:
tests:
name: Run Cypress E2E tests
Expand Down
46 changes: 12 additions & 34 deletions cypress/integration/1_detectors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import dns_name_rule_data from '../fixtures/integration_tests/rule/create_dns_ru
import dns_type_rule_data from '../fixtures/integration_tests/rule/create_dns_rule_with_type_selection.json';
import _ from 'lodash';
import { getMappingFields } from '../../public/pages/Detectors/utils/helpers';
import { getLogTypeLabel } from '../../public/pages/LogTypes/utils/helpers';

const cypressIndexDns = 'cypress-index-dns';
const cypressIndexWindows = 'cypress-index-windows';
const detectorName = 'test detector';
const cypressLogTypeDns = 'dns';
const sampleNotificationChannel = 'sample_chime_channel';

const cypressDNSRule = dns_name_rule_data.title;

Expand All @@ -38,14 +36,10 @@ const dataSourceLabel = 'Select or input source indexes or index patterns';

const getDataSourceField = () => cy.getFieldByLabel(dataSourceLabel);

const logTypeLabel = 'Log type';
const logTypeLabel = 'Select a log type you would like to detect';

const getLogTypeField = () => cy.getFieldByLabel(logTypeLabel);

const notificationLabel = 'Notification channel';

const getNotificationField = () => cy.getFieldByLabel(notificationLabel);

const openDetectorDetails = (detectorName) => {
cy.getInputByPlaceholder('Search threat detectors').type(`${detectorName}`).pressEnterKey();
cy.getElementByText('.euiTableCellContent button', detectorName).click();
Expand Down Expand Up @@ -120,19 +114,19 @@ const validatePendingFieldMappingsPanel = (mappings) => {
const fillDetailsForm = (detectorName, dataSource) => {
getNameField().type(detectorName);
getDataSourceField().selectComboboxItem(dataSource);
getDataSourceField().focus().blur();
getLogTypeField().selectComboboxItem(getLogTypeLabel(cypressLogTypeDns));
getLogTypeField().focus().blur();
getDataSourceField().blur();
getLogTypeField().selectComboboxItem(cypressLogTypeDns);
getLogTypeField().blur();
};

const createDetector = (detectorName, dataSource, expectFailure) => {
getCreateDetectorButton().click({ force: true });

fillDetailsForm(detectorName, dataSource);

cy.getElementByText('.euiAccordion .euiTitle', 'Selected detection rules (14)')
cy.getElementByText('.euiAccordion .euiTitle', 'Detection rules (14 selected)')
.click({ force: true, timeout: 5000 })
.then(() => cy.contains('.euiTable .euiTableRow', getLogTypeLabel(cypressLogTypeDns)));
.then(() => cy.contains('.euiTable .euiTableRow', 'Dns'));

cy.getElementByText('.euiAccordion .euiTitle', 'Field mapping - optional');
cy.get('[aria-controls="mappedTitleFieldsAccordion"]').then(($btn) => {
Expand All @@ -155,7 +149,7 @@ const createDetector = (detectorName, dataSource, expectFailure) => {
.focus()
.blur();

getNotificationField().selectComboboxItem(`[Channel] ${sampleNotificationChannel}`);
cy.getFieldByLabel('Specify alert severity').selectComboboxItem('1 (Highest)');

cy.intercept('POST', '/_plugins/_security_analytics/mappings').as('createMappingsRequest');
cy.intercept('POST', '/_plugins/_security_analytics/detectors').as('createDetectorRequest');
Expand All @@ -173,6 +167,8 @@ const createDetector = (detectorName, dataSource, expectFailure) => {
cy.url()
.should('contain', detectorId)
.then(() => {
cy.getElementByText('.euiCallOut', `Detector created successfully: ${detectorName}`);

// Confirm detector state
cy.getElementByText('.euiTitle', detectorName);
cy.getElementByText('.euiHealth', 'Active').then(() => {
Expand Down Expand Up @@ -220,20 +216,6 @@ describe('Detectors', () => {

cy.createRule(dns_name_rule_data);
cy.createRule(dns_type_rule_data);

cy.request('POST', 'http://localhost:9200/_plugins/_notifications/configs/', {
config_id: 'sa_notification-channel_id',
name: sampleNotificationChannel,
config: {
name: sampleNotificationChannel,
description: 'This is a sample chime channel',
config_type: 'chime',
is_enabled: true,
chime: {
url: 'https://sample-chime-webhook',
},
},
}).should('have.property', 'status', 200);
});

describe('...should validate form fields', () => {
Expand Down Expand Up @@ -349,6 +331,8 @@ describe('Detectors', () => {
.find('.euiFormErrorText')
.should('not.exist');

getCreateDetectorButton().should('be.enabled');

getTriggerNameField().type('{selectall}').type('{backspace}').focus().blur();
getCreateDetectorButton().should('be.disabled');

Expand Down Expand Up @@ -512,11 +496,5 @@ describe('Detectors', () => {
});
});

after(() => {
cy.cleanUpTests();
cy.request(
'DELETE',
'http://localhost:9200/_plugins/_notifications/configs/sa_notification-channel_id'
);
});
after(() => cy.cleanUpTests());
});
17 changes: 6 additions & 11 deletions cypress/integration/2_rules.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import { OPENSEARCH_DASHBOARDS_URL } from '../support/constants';
import { getLogTypeLabel } from '../../public/pages/LogTypes/utils/helpers';

const uniqueId = Cypress._.random(0, 1e6);
const SAMPLE_RULE = {
Expand Down Expand Up @@ -56,9 +55,7 @@ const checkRulesFlyout = () => {
cy.get('[data-test-subj="rule_flyout_rule_name"]').contains(SAMPLE_RULE.name);

// Validate log type
cy.get('[data-test-subj="rule_flyout_rule_log_type"]').contains(
getLogTypeLabel(SAMPLE_RULE.logType)
);
cy.get('[data-test-subj="rule_flyout_rule_log_type"]').contains(SAMPLE_RULE.logType);

// Validate description
cy.get('[data-test-subj="rule_flyout_rule_description"]').contains(SAMPLE_RULE.description);
Expand Down Expand Up @@ -164,7 +161,7 @@ const fillCreateForm = () => {
getAuthorField().type(`${SAMPLE_RULE.author}`);

// rule details
getLogTypeField().selectComboboxItem(getLogTypeLabel(SAMPLE_RULE.logType));
getLogTypeField().selectComboboxItem(SAMPLE_RULE.logType);
getRuleLevelField().selectComboboxItem(SAMPLE_RULE.severity);

// rule detection
Expand Down Expand Up @@ -287,7 +284,7 @@ describe('Rules', () => {
getLogTypeField().focus().blur();
getLogTypeField().containsError('Log type is required');

getLogTypeField().selectComboboxItem(getLogTypeLabel(SAMPLE_RULE.logType));
getLogTypeField().selectComboboxItem(SAMPLE_RULE.logType);
getLogTypeField().focus().blur().shouldNotHaveError();
});

Expand Down Expand Up @@ -428,7 +425,7 @@ describe('Rules', () => {
// log field
getLogTypeField().clearCombobox();
toastShouldExist();
getLogTypeField().selectComboboxItem(getLogTypeLabel(SAMPLE_RULE.logType));
getLogTypeField().selectComboboxItem(SAMPLE_RULE.logType);

// severity field
getRuleLevelField().clearCombobox();
Expand Down Expand Up @@ -553,10 +550,8 @@ describe('Rules', () => {
SAMPLE_RULE.logType = 'dns';
YAML_RULE_LINES[2] = `product: ${SAMPLE_RULE.logType}`;
YAML_RULE_LINES[3] = `title: ${SAMPLE_RULE.name}`;
getLogTypeField().selectComboboxItem(getLogTypeLabel(SAMPLE_RULE.logType));
getLogTypeField()
.containsValue(SAMPLE_RULE.logType)
.contains(getLogTypeLabel(SAMPLE_RULE.logType));
getLogTypeField().selectComboboxItem(SAMPLE_RULE.logType);
getLogTypeField().containsValue(SAMPLE_RULE.logType).contains(SAMPLE_RULE.logType);

SAMPLE_RULE.description += ' edited';
YAML_RULE_LINES[4] = `description: ${SAMPLE_RULE.description}`;
Expand Down
50 changes: 39 additions & 11 deletions cypress/integration/3_alerts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import aliasMappings from '../fixtures/sample_alias_mappings.json';
import indexDoc from '../fixtures/sample_document.json';
import ruleSettings from '../fixtures/integration_tests/rule/create_windows_usb_rule.json';
import { createDetector } from '../support/helpers';
import { getLogTypeLabel } from '../../public/pages/LogTypes/utils/helpers';

const indexName = 'test-index';
const detectorName = 'test-detector';
Expand Down Expand Up @@ -119,9 +118,7 @@ describe('Alerts', () => {
expect($tr, `timestamp`).to.contain(date);
expect($tr, `rule name`).to.contain('Cypress USB Rule');
expect($tr, `detector name`).to.contain(testDetector.name);
expect($tr, `log type`).to.contain(
`System Activity: ${getLogTypeLabel(testDetector.detector_type)}`
);
expect($tr, `log type`).to.contain('System Activity: Windows');
});

// Close the flyout
Expand Down Expand Up @@ -165,10 +162,8 @@ describe('Alerts', () => {
// Confirm finding timestamp
cy.get('[data-test-subj="finding-details-flyout-timestamp"]').contains(date);

// Confirm finding detection type
cy.get('[data-test-subj="finding-details-flyout-detection-type"]').contains(
'Detection rules'
);
// Confirm finding detector name
cy.get('[data-test-subj="finding-details-flyout-detector-link"]').contains(testDetector.name);

// Confirm there's only 1 rule details accordion
cy.get('[data-test-subj="finding-details-flyout-rule-accordion-1"]').should('not.exist');
Expand All @@ -194,9 +189,7 @@ describe('Alerts', () => {
cy.get('[data-test-subj="finding-details-flyout-rule-severity"]').contains('High');

// Confirm the rule category
cy.get('[data-test-subj="finding-details-flyout-rule-category"]').contains(
getLogTypeLabel(testDetector.detector_type)
);
cy.get('[data-test-subj="finding-details-flyout-rule-category"]').contains('Windows');

// Confirm the rule description
cy.get('[data-test-subj="finding-details-flyout-rule-description"]').contains(
Expand Down Expand Up @@ -360,5 +353,40 @@ describe('Alerts', () => {
});
});

it('detector name hyperlink on finding details flyout redirects to the detector details page', () => {
// Open first alert details flyout
cy.get('tbody > tr')
.first()
.within(() => {
// Click the "View details" button for the first alert
cy.get('[aria-label="View details"]').click({ force: true });
});

cy.get('[data-test-subj="alert-details-flyout"]').within(() => {
// Wait for findings table to finish loading
cy.contains('Cypress USB Rule');

// Click the details button for the first finding
cy.get('tbody > tr')
.first()
.within(() => {
cy.get('[data-test-subj="finding-details-flyout-button"]').click({
force: true,
});
});
});

cy.get('[data-test-subj="finding-details-flyout"]').within(() => {
// Click the detector name hyperlink
cy.get('[data-test-subj="finding-details-flyout-detector-link"]')
// Removing the "target" attribute so the link won't open a new tab. Cypress wouldn't test the new tab.
.invoke('removeAttr', 'target')
.click({ force: true });
});

// Confirm the detector details page is for the expected detector
cy.get('[data-test-subj="detector-details-detector-name"]').contains(testDetector.name);
});

after(() => cy.cleanUpTests());
});
3 changes: 1 addition & 2 deletions cypress/integration/4_findings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import aliasMappings from '../fixtures/sample_alias_mappings.json';
import indexDoc from '../fixtures/sample_document.json';
import ruleSettings from '../fixtures/integration_tests/rule/create_windows_usb_rule.json';
import { createDetector } from '../support/helpers';
import { getLogTypeLabel } from '../../public/pages/LogTypes/utils/helpers';

const indexName = 'test-index';
const detectorName = 'test-detector';
Expand Down Expand Up @@ -53,7 +52,7 @@ describe('Findings', () => {
cy.contains('No items found').should('not.exist');

// Check for expected findings
cy.contains(`System Activity: ${getLogTypeLabel(testDetector.detector_type)}`);
cy.contains('System Activity: Windows');
cy.contains('High');
});

Expand Down
Loading

0 comments on commit c00df74

Please sign in to comment.