Skip to content

Commit 4e75f2d

Browse files
amsiglandjindjicjovancvetkovic3006
authored
Merge failed backports #201, #209, #248, #261 (#287)
* resolved conflicts Signed-off-by: Amardeepsingh Siglani <[email protected]> * resolved conflicts Signed-off-by: Amardeepsingh Siglani <[email protected]> * resolved conflicts Signed-off-by: Amardeepsingh Siglani <[email protected]> * resolved conflicts Signed-off-by: Amardeepsingh Siglani <[email protected]> * updated latest code from the main branch Signed-off-by: Amardeepsingh Siglani <[email protected]> * updated integration test to latest from main Signed-off-by: Amardeepsingh Siglani <[email protected]> Signed-off-by: Amardeepsingh Siglani <[email protected]> Co-authored-by: Aleksandar Djindjic <[email protected]> Co-authored-by: Jovan Cvetkovic <[email protected]>
1 parent eac482e commit 4e75f2d

34 files changed

+2651
-622
lines changed

cypress.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"viewportHeight": 900,
33
"viewportWidth": 1440,
4-
"defaultCommandTimeout": 10000,
4+
"defaultCommandTimeout": 20000,
5+
"retries": 1,
56
"env": {
67
"opensearch_url": "localhost:9200",
78
"opensearch_dashboards": "http://localhost:5601",

cypress/integration/1_detectors.spec.js

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,47 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { PLUGIN_NAME } from '../support/constants';
6+
import { OPENSEARCH_DASHBOARDS_URL } from '../support/constants';
77
import sample_field_mappings from '../fixtures/sample_field_mappings.json';
88
import sample_index_settings from '../fixtures/sample_index_settings.json';
99

1010
describe('Detectors', () => {
1111
const indexName = 'cypress-test-windows';
12+
const detectorName = 'test detector';
1213

1314
before(() => {
14-
cy.deleteAllIndices();
15+
cy.cleanUpTests();
1516

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

19-
cy.contains('test detector').should('not.exist');
20+
cy.contains(detectorName).should('not.exist');
2021
});
2122

2223
beforeEach(() => {
2324
// Visit Detectors page
24-
cy.visit(`${Cypress.env('opensearch_dashboards')}/app/${PLUGIN_NAME}#/detectors`);
25-
26-
//wait for page to load
27-
cy.wait(7000);
25+
cy.visit(`${OPENSEARCH_DASHBOARDS_URL}/detectors`);
2826

2927
// Check that correct page is showing
30-
cy.url().should(
31-
'eq',
32-
'http://localhost:5601/app/opensearch_security_analytics_dashboards#/detectors'
33-
);
28+
cy.waitForPageLoad('detectors', {
29+
contains: 'Threat detectors',
30+
});
3431
});
3532

3633
it('...can be created', () => {
3734
// Locate Create detector button click to start
3835
cy.contains('Create detector').click({ force: true });
3936

4037
// Check to ensure process started
41-
cy.contains('Define detector');
42-
cy.url().should(
43-
'eq',
44-
'http://localhost:5601/app/opensearch_security_analytics_dashboards#/create-detector'
45-
);
38+
cy.waitForPageLoad('create-detector', {
39+
contains: 'Define detector',
40+
});
4641

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

50-
// Select our pre-seeded data source (cypress-test-windows)
51-
cy.get(`[data-test-subj="define-detector-select-data-source"]`).type(
52-
'cypress-test-windows{enter}'
53-
);
45+
// Select our pre-seeded data source (check indexName)
46+
cy.get(`[data-test-subj="define-detector-select-data-source"]`).type(`${indexName}{enter}`);
5447

5548
// Select threat detector type (Windows logs)
5649
cy.get(`input[id="windows"]`).click({ force: true });
@@ -59,7 +52,7 @@ describe('Detectors', () => {
5952
cy.get('[data-test-subj="detection-rules-btn"]').click({ timeout: 5000 });
6053

6154
// find search, type USB
62-
cy.get(`[placeholder="Search..."]`).type('USB Device Plugged').trigger('search');
55+
cy.triggerSearchField('Search...', 'USB Device Plugged');
6356

6457
// Disable all rules
6558
cy.contains('tr', 'USB Device Plugged', { timeout: 20000 });
@@ -121,21 +114,23 @@ describe('Detectors', () => {
121114

122115
// Confirm entries user has made
123116
cy.contains('Detector details');
124-
cy.contains('test detector');
117+
cy.contains(detectorName);
125118
cy.contains('windows');
126119
cy.contains(indexName);
127120
cy.contains('Alert on test_trigger');
128121

129122
// Create the detector
130123
cy.get('button').contains('Create').click({ force: true });
131-
132-
cy.wait(10000);
124+
cy.waitForPageLoad('detector-details', {
125+
contains: detectorName,
126+
});
133127

134128
// Confirm detector active
135-
cy.contains('There are no existing detectors.', { timeout: 20000 }).should('not.exist');
136-
cy.contains('test detector');
129+
cy.contains(detectorName);
137130
cy.contains('Active');
131+
cy.contains('View Alerts');
138132
cy.contains('View Findings');
133+
cy.contains('Actions');
139134
cy.contains('Detector configuration');
140135
cy.contains('Field mappings');
141136
cy.contains('Alert triggers');
@@ -146,21 +141,19 @@ describe('Detectors', () => {
146141

147142
it('...basic details can be edited', () => {
148143
// Click on detector name
149-
cy.contains('test detector').click({ force: true });
150-
151-
// Confirm on detector details page
152-
cy.contains('test detector');
144+
cy.contains(detectorName).click({ force: true });
145+
cy.waitForPageLoad('detector-details', {
146+
contains: detectorName,
147+
});
153148

154149
// Click "Edit" button in detector details
155150
cy.get(`[data-test-subj="edit-detector-basic-details"]`).click({ force: true });
156151

157152
// Confirm arrival at "Edit detector details" page
158-
cy.url().should(
159-
'include',
160-
'http://localhost:5601/app/opensearch_security_analytics_dashboards#/edit-detector-details'
161-
);
153+
cy.waitForPageLoad('edit-detector-details', {
154+
contains: 'Edit detector details',
155+
});
162156

163-
cy.wait(5000);
164157
// Change detector name
165158
cy.get(`[data-test-subj="define-detector-detector-name"]`).type('_edited');
166159

@@ -173,18 +166,16 @@ describe('Detectors', () => {
173166
);
174167

175168
// Change detector scheduling
176-
cy.get(`[data-test-subj="detector-schedule-number-select"]`).type('0');
169+
cy.get(`[data-test-subj="detector-schedule-number-select"]`).type('{selectall}10');
177170
cy.get(`[data-test-subj="detector-schedule-unit-select"]`).select('Hours');
178171

179-
cy.wait(7000);
180172
// Save changes to detector details
181173
cy.get(`[data-test-subj="save-basic-details-edits"]`).click({ force: true });
182174

183175
// Confirm taken to detector details page
184-
cy.url({ timeout: 20000 }).should(
185-
'include',
186-
'http://localhost:5601/app/opensearch_security_analytics_dashboards#/detector-details'
187-
);
176+
cy.waitForPageLoad('detector-details', {
177+
contains: detectorName,
178+
});
188179

189180
// Verify edits are applied
190181
cy.contains('test detector_edited');
@@ -195,13 +186,15 @@ describe('Detectors', () => {
195186

196187
it('...rules can be edited', () => {
197188
// Ensure start on main detectors page
198-
cy.url().should(
199-
'eq',
200-
'http://localhost:5601/app/opensearch_security_analytics_dashboards#/detectors'
201-
);
189+
cy.waitForPageLoad('detectors', {
190+
contains: 'Threat detectors',
191+
});
202192

203193
// Click on detector name
204-
cy.contains('test detector').click({ force: true });
194+
cy.contains(detectorName).click({ force: true });
195+
cy.waitForPageLoad('detector-details', {
196+
contains: detectorName,
197+
});
205198

206199
// Confirm number of rules before edit
207200
cy.contains('Active rules (1)');
@@ -216,7 +209,7 @@ describe('Detectors', () => {
216209
);
217210

218211
// Search for specific rule
219-
cy.get(`[placeholder="Search..."]`).type('USB Device').trigger('search', { timeout: 5000 });
212+
cy.triggerSearchField('Search...', 'USB Device');
220213

221214
// Toggle single search result to unchecked
222215
cy.contains('tr', 'USB Device Plugged').within(() => {
@@ -235,13 +228,12 @@ describe('Detectors', () => {
235228
cy.get(`[data-test-subj="edit-detector-rules"]`).click({ force: true });
236229

237230
// Confirm arrival on "Edit detector rules" page
238-
cy.url().should(
239-
'include',
240-
'http://localhost:5601/app/opensearch_security_analytics_dashboards#/edit-detector-rules'
241-
);
231+
cy.waitForPageLoad('edit-detector-rules', {
232+
contains: 'Edit detector rules',
233+
});
242234

243235
// Search for specific rule
244-
cy.get(`[placeholder="Search..."]`).focus().type('USB').trigger('search', { timeout: 5000 });
236+
cy.triggerSearchField('Search...', 'USB');
245237

246238
// Toggle single search result to checked
247239
cy.contains('tr', 'USB Device Plugged').within(() => {
@@ -251,6 +243,9 @@ describe('Detectors', () => {
251243

252244
// Save changes
253245
cy.get(`[data-test-subj="save-detector-rules-edits"]`).click({ force: true });
246+
cy.waitForPageLoad('detector-details', {
247+
contains: detectorName,
248+
});
254249

255250
// Confirm 1 rule has been added to detector
256251
cy.contains('Active rules (1)');
@@ -261,7 +256,9 @@ describe('Detectors', () => {
261256
cy.contains('test detector_edited').click({ force: true });
262257

263258
// Confirm page
264-
cy.contains('Detector details');
259+
cy.waitForPageLoad('detector-details', {
260+
contains: 'Detector details',
261+
});
265262

266263
// Click "Actions" button, the click "Delete"
267264
cy.contains('Actions').click({ force: true });
@@ -270,4 +267,6 @@ describe('Detectors', () => {
270267
// Confirm detector is deleted
271268
cy.contains('There are no existing detectors');
272269
});
270+
271+
after(() => cy.cleanUpTests());
273272
});

0 commit comments

Comments
 (0)