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

feature search by parameters And , Or #4720

Merged

Conversation

mauceballos
Copy link
Contributor

Description

this PR adds a feature to increase coverage in some modules for search by filter with parameters AND, OR

Feature

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" |

Feature Implemented

In order to implement both features, we need to include a pre-step after the user is logged step and the request is executed to activate the sample data.
The activation of the sample data allows us to use the search with filters and we will have results to be able to validate them

code
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';
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)
            })
        }

    })
})

The requests must include the cookie in the header, with a special format for these to be successful.

code by @asteriscos
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(';');
}
draft evidencie

2022-10-19_12-44

2022-10-19_12-46

Issues Resolved

#4709

Evidence

2022-10-19_16-47

### Test [Provide instructions to test this PR] ### Check List - [ ] All tests pass - [ ] New functionality includes testing. - [ ] New functionality has been documented.

@mauceballos mauceballos requested a review from a team as a code owner October 19, 2022 20:13
@github-actions
Copy link
Contributor

Code coverage (Jest) % values
Statements 7.19% ( 2608 / 36280 )
Branches 3.03% ( 846 / 27948 )
Functions 5.02% ( 444 / 8845 )
Lines 7.27% ( 2524 / 34732 )

@Mayons95 Mayons95 linked an issue Oct 19, 2022 that may be closed by this pull request
Copy link
Member

@Machi3mfl Machi3mfl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Mayons95 Mayons95 merged commit bbad2d1 into 4.4-7.10 Oct 20, 2022
@Mayons95 Mayons95 deleted the 4709-wzd-feature-search-by-parameters-with-and-or branch October 20, 2022 14:10
github-actions bot pushed a commit that referenced this pull request Oct 20, 2022
github-actions bot pushed a commit that referenced this pull request Oct 20, 2022
Mayons95 pushed a commit that referenced this pull request Oct 20, 2022
feature search by parameters And , Or (#4720)

(cherry picked from commit bbad2d1)

Co-authored-by: mauceballos <76791841+mauceballos@users.noreply.github.com>
Mayons95 pushed a commit that referenced this pull request Oct 20, 2022
feature search by parameters And , Or (#4720)

(cherry picked from commit bbad2d1)

Co-authored-by: mauceballos <76791841+mauceballos@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automation automation type/test Test issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WZD - Feature - Search by parameters with AND, OR
3 participants