From 22490ce8b378692cf629511ed87a5226f52d9e4d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 21 Oct 2022 09:00:45 -0300 Subject: [PATCH] [Backport 4.4-7.16] Add an environment validation to check the request (#4741) Adding a environment validation to check the request (#4738) * Adding a environment validation to check the request * Deleting dependency (cherry picked from commit 4ff3b8c70232c0d73e63882e75f7f3fc82cd0dad) Co-authored-by: Mayons95 <104914131+Mayons95@users.noreply.github.com> --- .../The-wazuh-admin-user-is-logged.given.js | 64 ++++++++++++------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/test/cypress/cypress/integration/step-definitions/settings/The-wazuh-admin-user-is-logged.given.js b/test/cypress/cypress/integration/step-definitions/settings/The-wazuh-admin-user-is-logged.given.js index 0341d86291..49c388d3af 100644 --- a/test/cypress/cypress/integration/step-definitions/settings/The-wazuh-admin-user-is-logged.given.js +++ b/test/cypress/cypress/integration/step-definitions/settings/The-wazuh-admin-user-is-logged.given.js @@ -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) - }) - } - - }) -}) \ No newline at end of file + 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); + }); + } + }); +});