import { HOSTS_STAT , SOURCERER } from '../screens/sourcerer' ; import { TIMELINE_TITLE } from '../screens/timeline' ; import { HOSTS_URL } from '../urls/navigation' ; import { waitForPage } from './login' ; import { openTimelineUsingToggle } from './security_main' ; import { DEFAULT_ALERTS_INDEX } from '../../common/constants' ; import { waitForAlertsIndexToBeCreated } from './alerts' ; import { createCustomRuleActivated } from './api_calls/rules' ; import { getNewRule } from '../objects/rule' ; export const openSourcerer = ( sourcererScope ? ) => { if ( sourcererScope != null && sourcererScope === 'timeline' ) { return openTimelineSourcerer ( ) ; } cy . get ( SOURCERER . trigger ) . should ( 'be.enabled' ) ; cy . get ( SOURCERER . trigger ) . should ( 'be.visible' ) ; cy . get ( SOURCERER . trigger ) . click ( ) ; cy . get ( SOURCERER . wrapper ) . should ( 'be.visible' ) ; } ; export const openTimelineSourcerer = ( ) => { cy . get ( SOURCERER . triggerTimeline ) . should ( 'be.enabled' ) ; cy . get ( SOURCERER . triggerTimeline ) . should ( 'be.visible' ) ; cy . get ( SOURCERER . triggerTimeline ) . first ( ) . click ( ) ; cy . get ( SOURCERER . wrapperTimeline ) . should ( 'be.visible' ) ; } ; export const openAdvancedSettings = ( ) => { cy . get ( SOURCERER . advancedSettings ) . should ( 'be.visible' ) ; cy . get ( SOURCERER . advancedSettings ) . click ( ) ; } ; export const clickOutOfSelector = ( ) => { return cy . get ( SOURCERER . popoverTitle ) . first ( ) . click ( ) ; } ; export const isDataViewSelection = ( dataView ) => { return cy . get ( SOURCERER . selectActiveOption ) . should ( 'contain' , dataView ) ; } ; export const openDataViewSelection = ( ) => cy . get ( SOURCERER . selectActiveOption ) . click ( ) ; export const isKibanaDataViewOption = ( dataViews ) => { return dataViews . every ( ( dataView ) => { return cy . get ( SOURCERER . selectListOption ) . should ( `contain` , dataView ) ; } ) ; } ; export const isSourcererSelection = ( patternName ) => { return cy . get ( SOURCERER . comboBoxInput ) . find ( `span[title="${ patternName }"]` ) . should ( 'exist' ) ; } ; export const isHostsStatValue = ( value ) => { return cy . get ( HOSTS_STAT ) . first ( ) . should ( 'have.text' , value ) ; } ; export const isNotSourcererSelection = ( patternName ) => { return cy . get ( SOURCERER . comboBoxInput ) . find ( `span[title="${ patternName }"]` ) . should ( 'not.exist' ) ; } ; export const isNotSourcererOption = ( patternName ) => { return cy . get ( SOURCERER . comboBoxOptions ) . find ( `button[title="${ patternName }"]` ) . should ( 'not.exist' ) ; } ; export const isSourcererOptions = ( patternNames ) => { cy . get ( SOURCERER . comboBoxInput ) . click ( ) ; return patternNames . every ( ( patternName ) => { return cy . get ( SOURCERER . comboBoxOptions ) . should ( `contain` , patternName ) ; } ) ; } ; export const selectSourcererOption = ( patternName ) => { cy . get ( SOURCERER . comboBoxInput ) . click ( ) ; cy . get ( SOURCERER . comboBoxOptions ) . find ( `button.euiFilterSelectItem[title="${ patternName }"]` ) . click ( ) ; clickOutOfSelector ( ) ; return cy . get ( SOURCERER . saveButton ) . click ( { force : true } ) ; } ; export const deselectSourcererOption = ( patternName ) => { cy . get ( SOURCERER . comboBoxInput ) . find ( `span[title="${ patternName }"] button` ) . click ( ) ; clickOutOfSelector ( ) ; return cy . get ( SOURCERER . saveButton ) . click ( { force : true } ) ; } ; export const deselectSourcererOptions = ( patternNames ) => { patternNames . forEach ( ( patternName ) => cy . get ( SOURCERER . comboBoxInput ) . find ( `span[title="${ patternName }"] button` ) . click ( ) ) ; } ; export const saveSourcerer = ( ) => { clickOutOfSelector ( ) ; return cy . get ( SOURCERER . saveButton ) . click ( { force : true } ) ; } ; export const resetSourcerer = ( ) => { return cy . get ( SOURCERER . resetButton ) . click ( ) ; } ; export const setSourcererOption = ( patternName , sourcererScope ? ) => { openSourcerer ( sourcererScope ) ; isNotSourcererSelection ( patternName ) ; selectSourcererOption ( patternName ) ; } ; export const unsetSourcererOption = ( patternName , sourcererScope ? ) => { openSourcerer ( sourcererScope ) ; isSourcererSelection ( patternName ) ; deselectSourcererOption ( patternName ) ; } ; export const clickOutOfSourcererTimeline = ( ) => cy . get ( TIMELINE_TITLE ) . first ( ) . click ( ) ; export const clickAlertCheckbox = ( ) => cy . get ( SOURCERER . alertCheckbox ) . check ( { force : true } ) ; export const addIndexToDefault = ( index ) => { cy . visit ( `/app/management/kibana/settings?query=category:(securitySolution)` ) ; cy . get ( SOURCERER . siemDefaultIndexInput ) . invoke ( 'val' ) . then ( ( patterns ) => { cy . get ( SOURCERER . siemDefaultIndexInput ) . type ( `${ patterns },${ index }` ) ; cy . get ( 'body' ) . then ( ( $body ) => { if ( $body . find ( '[data-test-subj="toastCloseButton]"' ) . length > 0 ) { cy . get ( '[data-test-subj="toastCloseButton]"' ) . click ( ) ; } } ) ; cy . get ( 'button[data-test-subj="advancedSetting-saveButton"]' ) . click ( ) ; cy . get ( '.euiToast .euiButton--primary' ) . click ( ) ; waitForPage ( HOSTS_URL ) ; } ) ; } ; export const deleteAlertsIndex = ( ) => { const alertsIndexUrl = `${ Cypress . env ( 'ELASTICSEARCH_URL' ) }/.internal.alerts-security.alerts-default-000001` ; cy . request ( { url : alertsIndexUrl , method : 'GET' , headers : { 'kbn-xsrf' : 'cypress-creds' } , failOnStatusCode : false , } ) . then ( ( response ) => { if ( response . status === 200 ) { cy . request ( { url : alertsIndexUrl , method : 'DELETE' , headers : { 'kbn-xsrf' : 'cypress-creds' } , } ) ; } } ) ; } ; export const refreshUntilAlertsIndexExists = async ( ) => { cy . waitUntil ( ( ) => { cy . reload ( ) ; openTimelineUsingToggle ( ) ; openSourcerer ( 'timeline' ) ; openAdvancedSettings ( ) ; return cy . get ( SOURCERER . comboBoxInput ) . invoke ( 'text' ) . then ( ( txt ) => txt . includes ( `${ DEFAULT_ALERTS_INDEX }-default` ) ) ; } , { interval : 500 , timeout : 12000 } ) ; } ; export const waitForAlertsIndexToExist = ( ) => { waitForAlertsIndexToBeCreated ( ) ; createCustomRuleActivated ( getNewRule ( ) , '1' , '100m' , 100 ) ; refreshUntilAlertsIndexExists ( ) ; } ;