Skip to content

Commit

Permalink
[Backport 4.4-7.16] feature search by parameters And , Or (#4725)
Browse files Browse the repository at this point in the history
feature search by parameters And , Or (#4720)

(cherry picked from commit bbad2d1)

Co-authored-by: mauceballos <76791841+mauceballos@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and mauceballos authored Oct 20, 2022
1 parent 640241a commit 68c1695
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Feature: Search by parameters

As a Wazuh user
I want to pin a filter
in order to aplly it across the modules
Background:
Given The wazuh admin user is logged
And The sample data is loaded

Scenario Outline: Search by parameters with AND
When The user goes to <Module Name>
And The user types a particular search <key> on the search bar
Then The query is accepted and the results should be displayed
Examples:
| Module Name | key |
| Security Events | cluster.name : "wazuh" and rule.level : "3" |
| Integrity Monitoring | cluster.name : "wazuh" and agent.id : "001" |
| NIST | cluster.name : "wazuh" and agent.name : "Ubuntu" |
| TSC | cluster.name : "wazuh" and agent.name : "Ubuntu" |
| PCIDSS | cluster.name : "wazuh" and agent.name : "Ubuntu" |

Scenario Outline: Search by parameters with OR
When The user goes to <Module Name>
And The user types a particular search <key> on the search bar
Then The query is accepted and the results should be displayed
Examples:
| Module Name | key |
| Security Events | cluster.name : "wazuh" or rule.level : "3" |
| Integrity Monitoring | cluster.name : "wazuh" or agent.id : "001" |
| NIST | cluster.name : "wazuh" or agent.name : "Ubuntu" |
| TSC | cluster.name : "wazuh" or agent.name : "Ubuntu" |
| PCIDSS | cluster.name : "wazuh" or agent.name : "Ubuntu" |
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ Feature: Pin filter - from dashboard to event page
| NIST |
| TSC |
| Policy Monitoring |
| PCIDSS |

| PCIDSS |
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ export const FILTERS_PAGE = {
pinnedFilter: '[data-test-subj="filter filter-enabled filter-key-rule.level filter-value-7 filter-pinned "]',
eventsButton: '//*[contains(@class,"euiTabs")]//*[contains(text(),"Events")]',
removeFilterButton: '//*[contains(@class,"euiContextMenuPanel")]//*[contains(text(),"Delete")]',
operatorList: '.euiPanel[data-test-subj="comboBoxOptionsList filterOperatorList-optionsList"] .euiComboBoxOptionsList__rowWrap'
operatorList: '.euiPanel[data-test-subj="comboBoxOptionsList filterOperatorList-optionsList"] .euiComboBoxOptionsList__rowWrap',
searchInputSelector: '[role="combobox"] [data-test-subj="queryInput"]',
noResultMessage: '#moduleDashboard .euiCallOut--warning span'
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { When } from 'cypress-cucumber-preprocessor/steps';
import { fillField, elementIsVisible, getSelector, forceEnter} from '../../utils/driver';
import { FILTERS_PAGE as pageName} from '../../utils/pages-constants';
const searchInputSelector = getSelector('searchInputSelector', pageName);

When('The user types a particular search {} on the search bar', (key) => {
elementIsVisible(searchInputSelector);
fillField(searchInputSelector, key);
forceEnter(searchInputSelector);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
import { elementIsNotVisible, getSelector } from '../../utils/driver';
import { FILTERS_PAGE as pageName} from '../../utils/pages-constants';
const noResultMessage = getSelector('noResultMessage', pageName);

Then('The query is accepted and the results should be displayed', () => {
elementIsNotVisible(noResultMessage)
})
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import { Given } from 'cypress-cucumber-preprocessor/steps';
import { navigate, elementIsVisible, getSelector } from '../../utils/driver';
import { navigate, elementIsVisible, getSelector, getCookiesFromBrowser } from '../../utils/driver';
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"}]

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)
})
}

})
})
17 changes: 17 additions & 0 deletions test/cypress/cypress/integration/utils/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,20 @@ export const xpathCheckInformationElement= (webLocator, optionsNames, optionLen
expect(optionsNames, 'has expected [' + optionsNames + '] text in each paragraph [' + paragraphs + ']').to.contains(paragraphs)
})
}


export const getCookiesFromBrowser = (values) => {
return values.filter(item=>['wz-token', 'wz-user', 'wz-api', 'security_authentication'].includes(item.name))
.map(item=>{
return `${item.name}:${item.value}`
}).join(';');
}

export const retrieveInformation = (url,method,headers,bodyPost) => {
return cy.request({
method: method,
url: url,
headers: headers,
body: bodyPost
}).as('response');
}

0 comments on commit 68c1695

Please sign in to comment.