Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an environment validation to check the request #4738

Merged
Merged
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
@@ -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);
});
}
});
});