Skip to content

Commit

Permalink
Cypress custom commands (opensearch-project#365) (opensearch-project#375
Browse files Browse the repository at this point in the history
)

* [FEATURE] Detector must have at least one alert set opensearch-project#288

Signed-off-by: Jovan Cvetkovic <[email protected]>

* [FEATURE] Add cypress custom commands to support better type events opensearch-project#364

Signed-off-by: Jovan Cvetkovic <[email protected]>

* [FEATURE] Add cypress custom commands to support better type events opensearch-project#364

Signed-off-by: Jovan Cvetkovic <[email protected]>

* [FEATURE] Add cypress custom commands to support better type events opensearch-project#364

Signed-off-by: Jovan Cvetkovic <[email protected]>

* [FEATURE] Add cypress custom commands to support better type events opensearch-project#364

Signed-off-by: Jovan Cvetkovic <[email protected]>

* [FEATURE] Add cypress custom commands to support better type events opensearch-project#364

Signed-off-by: Jovan Cvetkovic <[email protected]>

* [FEATURE] Add cypress custom commands to support better type events opensearch-project#364

Signed-off-by: Jovan Cvetkovic <[email protected]>

* [FEATURE] Add cypress custom commands to support better type events opensearch-project#364

Signed-off-by: Jovan Cvetkovic <[email protected]>

* [FEATURE] Add cypress custom commands to support better type events opensearch-project#364

Signed-off-by: Jovan Cvetkovic <[email protected]>

Signed-off-by: Jovan Cvetkovic <[email protected]>
Signed-off-by: AWSHurneyt <[email protected]>

Signed-off-by: Jovan Cvetkovic <[email protected]>
Signed-off-by: AWSHurneyt <[email protected]>
Co-authored-by: Jovan Cvetkovic <[email protected]>
Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
AWSHurneyt and jovancvetkovic3006 committed Feb 22, 2023
1 parent 175286d commit 9f9e723
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 251 deletions.
96 changes: 60 additions & 36 deletions cypress/integration/1_detectors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ describe('Detectors', () => {

before(() => {
cy.cleanUpTests();

// Create test index
cy.createIndex(indexName, sample_index_settings);

Expand All @@ -56,37 +55,49 @@ describe('Detectors', () => {

it('...can be created', () => {
// Locate Create detector button click to start
cy.contains('Create detector').click({ force: true });
cy.get('.euiButton').filter(':contains("Create detector")').click({ force: true });

// Check to ensure process started
cy.waitForPageLoad('create-detector', {
contains: 'Define detector',
});

// Enter a name for the detector in the appropriate input
cy.get(`input[placeholder="Enter a name for the detector."]`).type('test detector{enter}');
cy.get(`input[placeholder="Enter a name for the detector."]`).focus().realType('test detector');

// Select our pre-seeded data source (check indexName)
cy.get(`[data-test-subj="define-detector-select-data-source"]`).type(`${indexName}{enter}`);
cy.get(`[data-test-subj="define-detector-select-data-source"]`)
.find('input')
.focus()
.realType(indexName);

cy.intercept({
pathname: '/_plugins/_security_analytics/rules/_search',
query: {
prePackaged: 'true',
},
}).as('getSigmaRules');

// Select threat detector type (Windows logs)
cy.get(`input[id="windows"]`).click({ force: true });

// Open Detection rules accordion
cy.get('[data-test-subj="detection-rules-btn"]').click({ timeout: 5000 });
cy.wait('@getSigmaRules').then(() => {
// Open Detection rules accordion
cy.get('[data-test-subj="detection-rules-btn"]').click({ force: true, timeout: 5000 });

// find search, type USB
cy.triggerSearchField('Search...', 'USB Device Plugged');
// find search, type USB
cy.get(`input[placeholder="Search..."]`).ospSearch('USB Device Plugged');

// Disable all rules
cy.contains('tr', 'USB Device Plugged', { timeout: 20000 });
cy.get('th').within(() => {
cy.get('button').first().click({ force: true });
});
// Disable all rules
cy.contains('tr', 'USB Device Plugged', { timeout: 1000 });
cy.get('table th').within(() => {
cy.get('button').first().click({ force: true });
});

// enable single rule
cy.contains('tr', 'USB Device Plugged').within(() => {
cy.get('button').eq(1).click({ force: true });
// Enable single rule
cy.contains('table tr', 'USB Device Plugged').within(() => {
cy.get('button').eq(1).click({ force: true });
});
});

// Click Next button to continue
Expand Down Expand Up @@ -119,10 +130,16 @@ describe('Detectors', () => {
cy.contains('Set up alerts');

// Type name of new trigger
cy.get(`input[placeholder="Enter a name for the alert condition."]`).type('test_trigger');
cy.get(`input[placeholder="Enter a name for the alert condition."]`)
.focus()
.realType('test_trigger');

// Type in (or select) tags for the alert condition
cy.get(`[data-test-subj="alert-tags-combo-box"]`).type('attack.defense_evasion{enter}');
cy.get(`[data-test-subj="alert-tags-combo-box"]`)
.find('input')
.focus()
.realType('attack.defense_evasion')
.realPress('Enter');

// Select applicable severity levels
cy.get(`[data-test-subj="security-levels-combo-box"]`).click({ force: true });
Expand Down Expand Up @@ -191,18 +208,26 @@ describe('Detectors', () => {
});

// Change detector name
cy.get(`[data-test-subj="define-detector-detector-name"]`).type('_edited');
cy.get(`input[placeholder="Enter a name for the detector."]`)
.realClick()
.ospClear()
.realType('test detector edited');

// Change detector description
cy.get(`[data-test-subj="define-detector-detector-description"]`).type('Edited description');
cy.get(`[data-test-subj="define-detector-detector-description"]`)
.focus()
.realType('Edited description');

// Change input source
cy.get(`[data-test-subj="define-detector-select-data-source"]`).type(
'{backspace}.opensearch-notifications-config{enter}'
);
cy.get(`[data-test-subj="define-detector-select-data-source"]`)
.find('input')
.ospClear()
.focus()
.realType('.opensearch-notifications-config')
.realPress('Enter');

// Change detector scheduling
cy.get(`[data-test-subj="detector-schedule-number-select"]`).type('{selectall}10');
cy.get(`[data-test-subj="detector-schedule-number-select"]`).ospClear().focus().realType('10');
cy.get(`[data-test-subj="detector-schedule-unit-select"]`).select('Hours');

// Save changes to detector details
Expand All @@ -214,7 +239,7 @@ describe('Detectors', () => {
});

// Verify edits are applied
cy.contains('test detector_edited');
cy.contains('test detector edited');
cy.contains('Every 10 hours');
cy.contains('Edited description');
cy.contains('.opensearch-notifications-config');
Expand All @@ -239,16 +264,15 @@ describe('Detectors', () => {
cy.get(`[data-test-subj="edit-detector-rules"]`).click({ force: true });

// Confirm arrival on "Edit detector rules" page
cy.url().should(
'include',
'http://localhost:5601/app/opensearch_security_analytics_dashboards#/edit-detector-rules'
);
cy.waitForPageLoad('edit-detector-rules', {
contains: 'Edit detector rules',
});

// Search for specific rule
cy.triggerSearchField('Search...', 'USB Device');
cy.get(`input[placeholder="Search..."]`).ospSearch('USB Device');

// Toggle single search result to unchecked
cy.contains('tr', 'USB Device Plugged').within(() => {
cy.contains('table tr', 'USB Device Plugged').within(() => {
// Of note, timeout can sometimes work instead of wait here, but is very unreliable from case to case.
cy.wait(1000);
cy.get('button').eq(1).click();
Expand All @@ -269,10 +293,10 @@ describe('Detectors', () => {
});

// Search for specific rule
cy.triggerSearchField('Search...', 'USB');
cy.get(`input[placeholder="Search..."]`).ospSearch('USB');

// Toggle single search result to checked
cy.contains('tr', 'USB Device Plugged').within(() => {
cy.contains('table tr', 'USB Device Plugged').within(() => {
cy.wait(2000);
cy.get('button').eq(1).click({ force: true });
});
Expand All @@ -289,16 +313,16 @@ describe('Detectors', () => {

it('...can be deleted', () => {
// Click on detector to be removed
cy.contains('test detector_edited').click({ force: true });
cy.contains('test detector edited').click({ force: true });

// Confirm page
cy.waitForPageLoad('detector-details', {
contains: 'Detector details',
});

// Click "Actions" button, the click "Delete"
cy.contains('Actions').click({ force: true });
cy.contains('Delete').click({ force: true });
cy.get('button').contains('Actions').click({ force: true });
cy.get('button').contains('Delete').click({ force: true });

// Confirm detector is deleted
cy.contains('There are no existing detectors');
Expand Down
6 changes: 3 additions & 3 deletions cypress/integration/2_rules.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('Rules', () => {
cy.wait('@getRules');

// Search for the rule
cy.triggerSearchField('Search rules', SAMPLE_RULE.name);
cy.get(`input[placeholder="Search rules"]`).ospSearch(SAMPLE_RULE.name);

// Click the rule link to open the details flyout
cy.get(`[data-test-subj="rule_link_${SAMPLE_RULE.name}"]`).click({ force: true });
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('Rules', () => {
url: '/rules',
}).as('deleteRule');

cy.triggerSearchField('Search rules', SAMPLE_RULE.name);
cy.get(`input[placeholder="Search rules"]`).ospSearch(SAMPLE_RULE.name);

// Click the rule link to open the details flyout
cy.get(`[data-test-subj="rule_link_${SAMPLE_RULE.name}"]`).click({ force: true });
Expand All @@ -227,7 +227,7 @@ describe('Rules', () => {
cy.wait('@deleteRule');

// Search for sample_detector, presumably deleted
cy.triggerSearchField('Search rules', SAMPLE_RULE.name);
cy.get(`input[placeholder="Search rules"]`).ospSearch(SAMPLE_RULE.name);
// Click the rule link to open the details flyout
cy.get('tbody').contains(SAMPLE_RULE.name).should('not.exist');
});
Expand Down
12 changes: 6 additions & 6 deletions cypress/integration/4_findings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Findings', () => {

it('displays finding details flyout when user clicks on View details icon', () => {
// filter table to show only sample_detector findings
cy.triggerSearchField('Search findings', 'sample_detector');
cy.get(`input[placeholder="Search findings"]`).ospSearch('sample_detector');

// Click View details icon
cy.getTableFirstRow('[data-test-subj="view-details-icon"]').then(($el) => {
Expand All @@ -73,7 +73,7 @@ describe('Findings', () => {

it('displays finding details flyout when user clicks on Finding ID', () => {
// filter table to show only sample_detector findings
cy.triggerSearchField('Search findings', 'sample_detector');
cy.get(`input[placeholder="Search findings"]`).ospSearch('sample_detector');

// Click findingId to trigger Finding details flyout
cy.getTableFirstRow('[data-test-subj="finding-details-flyout-button"]').then(($el) => {
Expand All @@ -90,7 +90,7 @@ describe('Findings', () => {

it('allows user to view details about rules that were triggered', () => {
// filter table to show only sample_detector findings
cy.triggerSearchField('Search findings', 'sample_detector');
cy.get(`input[placeholder="Search findings"]`).ospSearch('sample_detector');

// open Finding details flyout via finding id link. cy.wait essential, timeout insufficient.
cy.get(`[data-test-subj="view-details-icon"]`).eq(0).click({ force: true });
Expand All @@ -116,7 +116,7 @@ describe('Findings', () => {

it('opens rule details flyout when rule name inside accordion drop down is clicked', () => {
// filter table to show only sample_detector findings
cy.triggerSearchField('Search findings', 'sample_detector');
cy.get(`input[placeholder="Search findings"]`).ospSearch('sample_detector');

// open Finding details flyout via finding id link. cy.wait essential, timeout insufficient.
cy.getTableFirstRow('[data-test-subj="view-details-icon"]').then(($el) => {
Expand All @@ -142,7 +142,7 @@ describe('Findings', () => {
});

// filter table to show only sample_detector findings
cy.triggerSearchField('Search threat detectors', 'sample_detector');
cy.get(`input[placeholder="Search threat detectors"]`).ospSearch('sample_detector');

// intercept detectors and rules requests
cy.intercept('detectors/_search').as('getDetector');
Expand All @@ -166,7 +166,7 @@ describe('Findings', () => {
cy.get('[data-test-subj="editButton"]').contains('Delete').click({ force: true });

// Search for sample_detector, presumably deleted
cy.triggerSearchField('Search threat detectors', 'sample_detector');
cy.get(`input[placeholder="Search threat detectors"]`).ospSearch('sample_detector');

// Confirm sample_detector no longer exists
cy.contains('There are no existing detectors.');
Expand Down
Loading

0 comments on commit 9f9e723

Please sign in to comment.