Skip to content

Commit

Permalink
[Backport 4.4-7.16] Add an environment validation to check the request (
Browse files Browse the repository at this point in the history
#4741)

Adding a environment validation to check the request (#4738)

* Adding a environment validation to check the request

* Deleting dependency

(cherry picked from commit 4ff3b8c)

Co-authored-by: Mayons95 <104914131+Mayons95@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and Mayons95 committed Oct 21, 2022
1 parent 8ff154e commit 22490ce
Showing 1 changed file with 41 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
import { Given } from 'cypress-cucumber-preprocessor/steps';
import { navigate, elementIsVisible, getSelector, getCookiesFromBrowser } from '../../utils/driver';
import { WAZUH_MENU_PAGE as pageName} from '../../utils/pages-constants';
import { WAZUH_MENU_PAGE as pageName } from '../../utils/pages-constants';
const wazuhMenuButton = getSelector('wazuhMenuButton', pageName);
let urlsList = ['https://localhost:5601/elastic/samplealerts/security','https://localhost:5601/elastic/samplealerts/auditing-policy-monitoring','https://localhost:5601/elastic/samplealerts/threat-detection'];
let urlBodys = [{"alertCount": 27000,"index": "wazuh-alerts-4.x-sample-security"},{"alertCount": 12000,"index": "wazuh-alerts-4.x-sample-auditing-policy-monitoring"},{"alertCount": 15000,"index": "wazuh-alerts-4.x-sample-threat-detection"}]
let urlsList = [
'https://localhost:5601/elastic/samplealerts/security',
'https://localhost:5601/elastic/samplealerts/auditing-policy-monitoring',
'https://localhost:5601/elastic/samplealerts/threat-detection',
];
let urlBodys = [
{ alertCount: 27000, index: 'wazuh-alerts-4.x-sample-security' },
{ alertCount: 12000, index: 'wazuh-alerts-4.x-sample-auditing-policy-monitoring' },
{ alertCount: 15000, index: 'wazuh-alerts-4.x-sample-threat-detection' },
];

Given('The wazuh admin user is logged', () => {
if (Cypress.env('type') != 'wzd') {
navigate("app/wazuh");}else{navigate("/")}
elementIsVisible(wazuhMenuButton);
})
Given('The wazuh admin user is logged', () => {
if (Cypress.env('type') != 'wzd') {
navigate('app/wazuh');
} else {
navigate('/');
}
elementIsVisible(wazuhMenuButton);
});

Given('The sample data is loaded', () => {
cy.readFile('cookies.json').then((cookies) => {
let headersFormat = {"content-type":"application/json; charset=utf-8","Cookie": getCookiesFromBrowser(cookies),"Accept":"application/json, text/plain, */*","Accept-Encoding":"gzip, deflate, br","osd-xsrf":"kibana"};
for(let i = 0; i < urlsList.length; i++){
cy.request({
method: 'POST',
url: urlsList[i],
headers: headersFormat,
body: urlBodys[i]
}).should((response) => {
expect(response.status).to.eq(200)
})
}

})
})
cy.readFile('cookies.json').then((cookies) => {
let headersFormat = {
'content-type': 'application/json; charset=utf-8',
Cookie: getCookiesFromBrowser(cookies),
Accept: 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate, br',
};
Cypress.env('type') == 'xpack'
? (headersFormat['kbn-xsrf'] = 'kibana')
: (headersFormat['osd-xsrf'] = 'kibana');
for (let i = 0; i < urlsList.length; i++) {
cy.request({
method: 'POST',
url: urlsList[i],
headers: headersFormat,
body: urlBodys[i],
}).should((response) => {
expect(response.status).to.eq(200);
});
}
});
});

0 comments on commit 22490ce

Please sign in to comment.