Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

METRON-1958: Optimize Cypress to use best practices #1317

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ port: {{metron_alerts_ui_port}}
rest:
host: {{metron_rest_host}}
port: {{metron_rest_port}}

dirPath: alerts-ui
2 changes: 2 additions & 0 deletions metron-interface/metron-alerts/alerts_ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ port: 4201
rest:
host: localhost
port: 8080

dirPath: alerts-ui
23 changes: 23 additions & 0 deletions metron-interface/metron-alerts/alerts_ui_cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
port: 4200

rest:
host: localhost
port: 4200

dirPath: dist
3 changes: 2 additions & 1 deletion metron-interface/metron-alerts/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"viewportHeight": 850,
"video": false,
"supportFile": false,
"pluginsFile": false
"pluginsFile": false,
"baseUrl": "http://localhost:4200"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,28 @@ context('PCAP Tab', () => {
url: '/api/v1/user',
response: 'user'
});
cy.route({
method: 'POST',
url: 'logout',
response: []
});

cy.route('GET', 'config', 'fixture:config.json');
cy.route('GET', '/api/v1/global/config', 'fixture:config.json');
cy.route('POST', 'search', 'fixture:search.json');

cy.route({
method: 'GET',
url: '/api/v1/pcap?state=*',
response: []
}).as('runningJobs');
cy.visit('http://localhost:4200/login');

cy.visit('login');
cy.get('[name="user"]').type('user');
cy.get('[name="password"]').type('password');
cy.contains('LOG IN').click();
});

afterEach(() => {
cy.get('.logout-link').click();
});

it('checking running jobs on navigating to PCAP tab', () => {
Expand All @@ -62,7 +66,7 @@ context('PCAP Tab', () => {
cy.get('[data-qe-id="protocol"]').type('24');
cy.get('[data-qe-id="include-reverse"]').check();
cy.get('[data-qe-id="packet-filter"]').type('filter');

cy.get('[data-qe-id="submit-button"]').click();

cy.wait('@postingPcapJob').then((xhr) => {
Expand All @@ -82,7 +86,7 @@ context('PCAP Tab', () => {

cy.contains('PCAP').click();
cy.get('[data-qe-id="submit-button"]').click();

cy.wait('@jobStatusCheck').its('url').should('include', '/api/v1/pcap/job_1537878471649_0001');
});

Expand All @@ -92,7 +96,7 @@ context('PCAP Tab', () => {

cy.contains('PCAP').click();
cy.get('[data-qe-id="submit-button"]').click();

cy.wait('@jobStatusCheck');

cy.contains('75%').should('be.visible');
Expand All @@ -105,7 +109,7 @@ context('PCAP Tab', () => {

cy.contains('PCAP').click();
cy.get('[data-qe-id="submit-button"]').click();

cy.wait('@statusCheck');

cy.wait('@gettingPdml').its('url').should('include', '/api/v1/pcap/job_1537878471649_0001/pdml?page=1');
Expand All @@ -119,7 +123,7 @@ context('PCAP Tab', () => {

cy.contains('PCAP').click();
cy.get('[data-qe-id="submit-button"]').click();

cy.wait('@statusCheck');

cy.wait('@gettingPdml');
Expand All @@ -135,15 +139,15 @@ context('PCAP Tab', () => {

cy.contains('PCAP').click();
cy.get('[data-qe-id="submit-button"]').click();

cy.wait('@statusCheck');
cy.wait('@gettingPdml');

cy.get('app-pcap-list table').should('be.visible');
cy.contains('General information').should('not.be.visible');

cy.get(':nth-child(3) > .timestamp').click();

cy.contains('General information').should('be.visible');
cy.get('[data-qe-id="proto"]').should('have.length', 6);
});
Expand All @@ -155,12 +159,12 @@ context('PCAP Tab', () => {

cy.contains('PCAP').click();
cy.get('[data-qe-id="submit-button"]').click();

cy.wait('@statusCheck');
cy.wait('@gettingPdml');

cy.contains('Page 1 of 2').should('be.visible');

cy.get('.fa-chevron-right').click();

cy.wait('@gettingPdml').its('url').should('include', '?page=2');
Expand All @@ -174,7 +178,7 @@ context('PCAP Tab', () => {

cy.contains('PCAP').click();
cy.get('[data-qe-id="submit-button"]').click();

cy.wait('@statusCheck');
cy.wait('@gettingPdml');

Expand All @@ -194,7 +198,7 @@ context('PCAP Tab', () => {

cy.contains('PCAP').click();
cy.get('[data-qe-id="submit-button"]').click();

cy.wait('@jobStatusCheck');

cy.get('[data-qe-id="pcap-cancel-query-button"]').click();
Expand All @@ -210,7 +214,7 @@ context('PCAP Tab', () => {
cy.get('[data-qe-id="ip-dst-addr"]').type('ccc.ddd.222.000');
cy.get('[data-qe-id="ip-src-port"]').type('99999');
cy.get('[data-qe-id="ip-dst-port"]').type('aaaa');

cy.get('.pcap-search-validation-errors').should('be.visible');
cy.get('.pcap-search-validation-errors li').should('have.length', 4);
});
Expand All @@ -221,7 +225,7 @@ context('PCAP Tab', () => {
cy.get('[data-qe-id="end-time"]').click();
cy.get('.pika-select-year').select('2015');
cy.get('[data-day="11"] > .pika-button').click();

cy.get('.pcap-search-validation-errors').should('be.visible');
cy.get('.pcap-search-validation-errors li').should('have.length', 1);
});
Expand Down
10 changes: 10 additions & 0 deletions metron-interface/metron-alerts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions metron-interface/metron-alerts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"e2e": "protractor-flake --protractor-path=./node_modules/.bin/protractor --max-attempts=3 -- ./protractor.conf.js",
"cypress:run": "cypress run",
"cypress:open": "cypress open",
"cypress:ci": "run-p --race start cypress:run"
"cypress:ci": "ng build --prod && run-p --race start:ci cypress:run",
"start:ci": "node ./scripts/alerts-server.js -c alerts_ui_cypress.yml"
},
"private": true,
"dependencies": {
Expand Down Expand Up @@ -75,6 +76,7 @@
"serve-static": "^1.13.2",
"ssh2": "^0.5.5",
"tslint": "~5.0.0",
"typescript": "~2.9.2"
"typescript": "~2.9.2",
"yamljs": "^0.3.0"
}
}
6 changes: 3 additions & 3 deletions metron-interface/metron-alerts/scripts/alerts-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ var restUrl = 'http://' + uiConfig.rest.host + ':' + uiConfig.rest.port;
app.use('/api/v1', proxy(restUrl));
app.use('/logout', proxy(restUrl));

app.use(favicon(path.join(__dirname, '../alerts-ui/favicon.ico')));
app.use(favicon(path.join(__dirname, '../' + uiConfig.dirPath + '/favicon.ico')));

app.use(serveStatic(path.join(__dirname, '../alerts-ui'), {
app.use(serveStatic(path.join(__dirname, '../' + uiConfig.dirPath), {
maxAge: '1d',
setHeaders: setCustomCacheControl
}));

app.get('*', function(req, res){
res.sendFile(path.join(__dirname, '../alerts-ui/index.html'));
res.sendFile(path.join(__dirname, '../' + uiConfig.dirPath + '/index.html'));
});

app.listen(uiConfig.port, function(){
Expand Down