Skip to content

Commit

Permalink
Fixed failing tests.
Browse files Browse the repository at this point in the history
Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
AWSHurneyt committed Feb 8, 2023
1 parent a9a052f commit 0d88882
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ describe('Rules', () => {
contains: 'Rules',
});

cy.wait('@getRules');

// Search for the rule
cy.triggerSearchField('Search rules', SAMPLE_RULE.name);

Expand Down Expand Up @@ -243,10 +241,6 @@ describe('Rules', () => {
});

it('...can be deleted', () => {
cy.intercept({
url: '/rules',
}).as('deleteRule');

cy.triggerSearchField('Search rules', SAMPLE_RULE.name);

// Click the rule link to open the details flyout
Expand All @@ -269,10 +263,9 @@ describe('Rules', () => {
cy.get('.euiButton').contains('Delete').click();
});

cy.wait('@deleteRule');

// Search for sample_detector, presumably deleted
cy.triggerSearchField('Search rules', SAMPLE_RULE.name);

// Click the rule link to open the details flyout
cy.get('tbody').contains(SAMPLE_RULE.name).should('not.exist');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const now = new Date(Date.now());
const month =
now.getMonth() + 1 < 10 ? `0${now.getMonth() + 1}` : `${now.getMonth() + 1}`;
const day = now.getDate() < 10 ? `0${now.getDate()}` : `${now.getDate()}`;
const year = `${now.getFullYear()}`.substr(1);
const year = `${now.getFullYear()}`.substr(2);
const date = `${month}/${day}/${year}`;

const docCount = 4;
Expand Down Expand Up @@ -377,6 +377,7 @@ describe('Alerts', () => {
cy.get('[class="euiFilterSelect__items"]').within(() => {
cy.contains('Acknowledged').click({ force: true });
});
cy.get('[data-text="Status"]').click({ force: true });

// Confirm there is an "Acknowledged" alert
cy.get('tbody > tr').should(($tr) => {
Expand All @@ -385,10 +386,11 @@ describe('Alerts', () => {
});

// Filter the table to show only "Active" alerts
cy.get('[data-text="Status"]');
cy.get('[data-text="Status"]').click({ force: true });
cy.get('[class="euiFilterSelect__items"]').within(() => {
cy.contains('Acknowledged').click({ force: true });
});
cy.get('[data-text="Status"]').click({ force: true });

// Confirm there are now 2 "Acknowledged" alerts
cy.get('tbody > tr')
Expand All @@ -403,6 +405,7 @@ describe('Alerts', () => {
cy.get('[class="euiFilterSelect__items"]').within(() => {
cy.contains('Active').click({ force: true });
});
cy.get('[data-text="Status"]').click({ force: true });

cy.get('tbody > tr')
.filter(`:contains(${testDetectorAlertCondition})`)
Expand All @@ -420,11 +423,12 @@ describe('Alerts', () => {
.should('have.length', 2);

// Filter the table to show only "Acknowledged" alerts
cy.get('[data-text="Status"]');
cy.get('[data-text="Status"]').click({ force: true });
cy.get('[class="euiFilterSelect__items"]').within(() => {
cy.contains('Active').click({ force: true });
cy.contains('Acknowledged').click({ force: true });
});
cy.get('[data-text="Status"]').click({ force: true });

// Confirm there are now 3 "Acknowledged" alerts
cy.get('tbody > tr')
Expand All @@ -438,6 +442,7 @@ describe('Alerts', () => {
cy.get('[class="euiFilterSelect__items"]').within(() => {
cy.contains('Active').click({ force: true });
});
cy.get('[data-text="Status"]').click({ force: true });

cy.get('tbody > tr')
.first()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,11 @@ describe('Findings', () => {
// filter table to show only sample_detector findings
cy.triggerSearchField('Search threat detectors', 'sample_detector');

// intercept detectors and rules requests
cy.intercept('detectors/_search').as('getDetector');
cy.intercept('rules/_search?prePackaged=true').as('getPrePackagedRules');
cy.intercept('rules/_search?prePackaged=false').as('getRules');

// Click on detector to be removed
cy.contains('sample_detector').click({ force: true });
cy.waitForPageLoad('detector-details', {
contains: sample_detector.name,
});

// wait for detector details to load before continuing
cy.wait(['@getDetector', '@getPrePackagedRules', '@getRules']).then(() => {
// Wait for detector details to load before continuing
cy.contains('Detector details').then(() => {
// Click "Actions" button, the click "Delete"
cy.get('button.euiButton')
.contains('Actions')
Expand All @@ -180,11 +172,8 @@ describe('Findings', () => {
.contains('Delete')
.click({ force: true });

// Search for sample_detector, presumably deleted
cy.triggerSearchField('Search threat detectors', 'sample_detector');

// Confirm sample_detector no longer exists
cy.contains('There are no existing detectors.');
cy.contains('sample_detector').should('not.exist');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,8 @@ describe('Integration tests', () => {
).then(() => cy.createDetector(dns_detector_data));

// Ingest docs
cy.request(
'POST',
`${Cypress.env('opensearch')}/${indexName}/_doc/101`,
add_windows_index_data
);
cy.request(
'POST',
`${Cypress.env('opensearch')}/${dnsName}/_doc/101`,
add_dns_index_data
);
cy.insertDocumentToIndex(indexName, '101', add_windows_index_data);
cy.insertDocumentToIndex(dnsName, '101', add_dns_index_data);

// Wait for detector interval to pass
cy.wait(DETECTOR_TRIGGER_TIMEOUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Cypress.Commands.add(
'insertDocumentToIndex',
(indexName, documentId, documentBody) => {
cy.request(
'PUT',
'POST',
`${Cypress.env('openSearchUrl')}/${indexName}/_doc/${documentId}`,
documentBody
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ Cypress.Commands.add('getTableFirstRow', (selector) => {
});

Cypress.Commands.add('triggerSearchField', (placeholder, text) => {
cy.get(`[placeholder="${placeholder}"]`).type(`{selectall}${text}{enter}`);
cy.get(`input[type="search"]`)
.first()
.focus()
.type(`{selectall}${text}{enter}`)
.trigger('search');
});

Cypress.Commands.add(
Expand All @@ -48,11 +52,14 @@ Cypress.Commands.add('deleteAllDetectors', () => {
});

Cypress.Commands.add('createDetector', (detectorJSON) => {
cy.request(
'POST',
`${OPENSEARCH_DASHBOARDS}${NODE_API.DETECTORS_BASE}`,
detectorJSON
);
cy.request({
method: 'POST',
url: `${OPENSEARCH_DASHBOARDS}${NODE_API.DETECTORS_BASE}`,
body: detectorJSON,
headers: {
'osd-xsrf': true,
},
});
});

Cypress.Commands.add('updateDetector', (detectorId, detectorJSON) => {
Expand Down Expand Up @@ -108,6 +115,9 @@ Cypress.Commands.add(
method: 'POST',
url: `${OPENSEARCH_DASHBOARDS}${NODE_API.MAPPINGS_BASE}`,
body: body,
headers: {
'osd-xsrf': true,
},
});
}
);
Expand All @@ -117,6 +127,9 @@ Cypress.Commands.add('createRule', (ruleJSON) => {
method: 'POST',
url: `${OPENSEARCH_DASHBOARDS}${NODE_API.RULES_BASE}?category=${ruleJSON.category}`,
body: JSON.stringify(ruleJSON),
headers: {
'osd-xsrf': true,
},
});
});

Expand Down Expand Up @@ -148,6 +161,9 @@ Cypress.Commands.add('deleteRule', (ruleName) => {
url: `${OPENSEARCH_DASHBOARDS}${NODE_API.RULES_BASE}/_search?pre_packaged=false`,
failOnStatusCode: false,
body,
headers: {
'osd-xsrf': true,
},
}).then((response) => {
if (response.status === 200) {
for (let hit of response.body.hits.hits) {
Expand All @@ -169,3 +185,54 @@ Cypress.Commands.add('deleteAllCustomRules', () => {
body: { query: { match_all: {} } },
});
});

Cypress.Commands.add('updateDetector', (detectorId, detectorJSON) => {
cy.request(
'PUT',
`${Cypress.env('opensearch')}/${NODE_API.DETECTORS_BASE}/${detectorId}`,
detectorJSON
);
});

Cypress.Commands.add('deleteAllDetectors', () => {
cy.request({
method: 'DELETE',
url: `${Cypress.env('opensearch')}/.opensearch-sap-detectors-config`,
failOnStatusCode: false,
}).as('deleteAllDetectors');
});

Cypress.Commands.add(
'ospSearch',
{
prevSubject: true,
},
(subject, text) => {
return cy.get(subject).clear().ospType(text).realPress('Enter');
}
);

Cypress.Commands.add(
'ospClear',
{
prevSubject: true,
},
(subject) => {
return cy
.get(subject)
.wait(100)
.type('{selectall}{backspace}')
.clear({ force: true })
.invoke('val', '');
}
);

Cypress.Commands.add(
'ospType',
{
prevSubject: true,
},
(subject, text) => {
return cy.get(subject).wait(10).focus().realType(text);
}
);

0 comments on commit 0d88882

Please sign in to comment.