-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Risk engine initialisation, update from legacy risk engine workflow and status change #162400
Changes from 43 commits
34a040e
62b04b6
ef9d3e5
9f2e3d9
347f4ff
ad59803
8423d5c
fdc0084
05f28c5
e7079c9
4ffaa99
1b74331
8518cbb
27e39c2
b4c212d
805d243
34fa0ed
2cce865
189e941
6d7c016
b99c3e1
b4f5955
a835c61
e1ed39e
e6dcad4
e31d85b
8373a58
e72b7d4
38e23bc
9a53d21
450871a
1527f2a
b47ec84
5dffa4d
ca8329b
7aad6cb
dac1f34
6265ac3
7fd2016
b31ab04
a77a838
ba83b7b
9742878
c77a82e
96b6ddc
3b1bb9f
f8cf032
7237b5f
7df7d22
ddbe593
1bc3314
d9b03b0
b8b638e
b44c3b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,81 +14,144 @@ import { | |
RISK_PREVIEW_ERROR, | ||
RISK_PREVIEW_ERROR_BUTTON, | ||
LOCAL_QUERY_BAR_SELECTOR, | ||
RISK_SCORE_ERROR_PANEL, | ||
RISK_SCORE_STATUS, | ||
} from '../../screens/entity_analytics_management'; | ||
|
||
import { deleteRiskScore, installRiskScoreModule } from '../../tasks/api_calls/risk_scores'; | ||
import { RiskScoreEntity } from '../../tasks/risk_scores/common'; | ||
import { login, visit, visitWithoutDateRange } from '../../tasks/login'; | ||
import { cleanKibana } from '../../tasks/common'; | ||
import { ENTITY_ANALYTICS_MANAGEMENT_URL, ALERTS_URL } from '../../urls/navigation'; | ||
import { getNewRule } from '../../objects/rule'; | ||
import { createRule } from '../../tasks/api_calls/rules'; | ||
import { deleteConfiguration } from '../../tasks/api_calls/risk_engine'; | ||
import { updateDateRangeInLocalDatePickers } from '../../tasks/date_picker'; | ||
import { fillLocalSearchBar, submitLocalSearch } from '../../tasks/search_bar'; | ||
import { | ||
riskEngineStatusChange, | ||
updateRiskEngine, | ||
updateRiskEngineConfirm, | ||
} from '../../tasks/entity_analytics'; | ||
|
||
describe( | ||
'Entity analytics management page', | ||
{ env: { ftrConfig: { enableExperimental: ['riskScoringRoutesEnabled'] } } }, | ||
() => { | ||
before(() => { | ||
cleanKibana(); | ||
cy.task('esArchiverLoad', 'all_users'); | ||
}); | ||
|
||
describe('Entity analytics management page', () => { | ||
before(() => { | ||
cleanKibana(); | ||
cy.task('esArchiverLoad', 'all_users'); | ||
}); | ||
beforeEach(() => { | ||
login(); | ||
visitWithoutDateRange(ALERTS_URL); | ||
createRule(getNewRule({ query: 'user.name:* or host.name:*', risk_score: 70 })); | ||
deleteConfiguration(); | ||
visit(ENTITY_ANALYTICS_MANAGEMENT_URL); | ||
}); | ||
|
||
beforeEach(() => { | ||
login(); | ||
visitWithoutDateRange(ALERTS_URL); | ||
createRule(getNewRule({ query: 'user.name:* or host.name:*', risk_score: 70 })); | ||
visit(ENTITY_ANALYTICS_MANAGEMENT_URL); | ||
}); | ||
after(() => { | ||
cy.task('esArchiverUnload', 'all_users'); | ||
}); | ||
|
||
after(() => { | ||
cy.task('esArchiverUnload', 'all_users'); | ||
}); | ||
it('renders page as expected', () => { | ||
cy.get(PAGE_TITLE).should('have.text', 'Entity Risk Score'); | ||
}); | ||
|
||
it('renders page as expected', () => { | ||
cy.get(PAGE_TITLE).should('have.text', 'Entity Risk Score'); | ||
}); | ||
describe('Risk preview', () => { | ||
it('risk scores reacts on change in datepicker', () => { | ||
const START_DATE = 'Jan 18, 2019 @ 20:33:29.186'; | ||
const END_DATE = 'Jan 19, 2019 @ 20:33:29.186'; | ||
|
||
describe('Risk preview', () => { | ||
it('risk scores reacts on change in datepicker', () => { | ||
const START_DATE = 'Jan 18, 2019 @ 20:33:29.186'; | ||
const END_DATE = 'Jan 19, 2019 @ 20:33:29.186'; | ||
cy.get(HOST_RISK_PREVIEW_TABLE_ROWS).should('have.length', 5); | ||
cy.get(USER_RISK_PREVIEW_TABLE_ROWS).should('have.length', 5); | ||
|
||
cy.get(HOST_RISK_PREVIEW_TABLE_ROWS).should('have.length', 5); | ||
cy.get(USER_RISK_PREVIEW_TABLE_ROWS).should('have.length', 5); | ||
updateDateRangeInLocalDatePickers(LOCAL_QUERY_BAR_SELECTOR, START_DATE, END_DATE); | ||
|
||
updateDateRangeInLocalDatePickers(LOCAL_QUERY_BAR_SELECTOR, START_DATE, END_DATE); | ||
cy.get(HOST_RISK_PREVIEW_TABLE).contains('No items found'); | ||
cy.get(USER_RISK_PREVIEW_TABLE).contains('No items found'); | ||
}); | ||
|
||
cy.get(HOST_RISK_PREVIEW_TABLE).contains('No items found'); | ||
cy.get(USER_RISK_PREVIEW_TABLE).contains('No items found'); | ||
}); | ||
it('risk scores reacts on change in search bar query', () => { | ||
cy.get(HOST_RISK_PREVIEW_TABLE_ROWS).should('have.length', 5); | ||
cy.get(USER_RISK_PREVIEW_TABLE_ROWS).should('have.length', 5); | ||
|
||
it('risk scores reacts on change in search bar query', () => { | ||
cy.get(HOST_RISK_PREVIEW_TABLE_ROWS).should('have.length', 5); | ||
cy.get(USER_RISK_PREVIEW_TABLE_ROWS).should('have.length', 5); | ||
fillLocalSearchBar('host.name: "test-host1"'); | ||
submitLocalSearch(LOCAL_QUERY_BAR_SELECTOR); | ||
|
||
fillLocalSearchBar('host.name: "test-host1"'); | ||
submitLocalSearch(LOCAL_QUERY_BAR_SELECTOR); | ||
cy.get(HOST_RISK_PREVIEW_TABLE_ROWS).should('have.length', 1); | ||
cy.get(HOST_RISK_PREVIEW_TABLE_ROWS).contains('test-host1'); | ||
cy.get(USER_RISK_PREVIEW_TABLE_ROWS).should('have.length', 1); | ||
cy.get(USER_RISK_PREVIEW_TABLE_ROWS).contains('test1'); | ||
}); | ||
|
||
it('show error panel if API returns error and then try to refetch data', () => { | ||
cy.intercept('POST', '/internal/risk_score/preview', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Wrapt these intercepts into a task method making clear what you are doing or just add a simple comment about the stubbing you are doing :) |
||
statusCode: 500, | ||
}); | ||
|
||
cy.get(RISK_PREVIEW_ERROR).contains('Preview failed'); | ||
|
||
cy.get(HOST_RISK_PREVIEW_TABLE_ROWS).should('have.length', 1); | ||
cy.get(HOST_RISK_PREVIEW_TABLE_ROWS).contains('test-host1'); | ||
cy.get(USER_RISK_PREVIEW_TABLE_ROWS).should('have.length', 1); | ||
cy.get(USER_RISK_PREVIEW_TABLE_ROWS).contains('test1'); | ||
cy.intercept('POST', '/internal/risk_score/preview', { | ||
statusCode: 200, | ||
body: { | ||
scores: { host: [], user: [] }, | ||
}, | ||
}); | ||
|
||
cy.get(RISK_PREVIEW_ERROR_BUTTON).click(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Wrap this into a task method. |
||
|
||
cy.get(RISK_PREVIEW_ERROR).should('not.exist'); | ||
}); | ||
}); | ||
|
||
it('show error panel if API returns error and then try to refetch data', () => { | ||
cy.intercept('POST', '/internal/risk_score/preview', { | ||
statusCode: 500, | ||
describe('Risk engine', () => { | ||
it('should init, disable and enable risk engine', () => { | ||
cy.get(RISK_SCORE_STATUS).should('have.text', 'Off'); | ||
|
||
// init | ||
riskEngineStatusChange(); | ||
|
||
cy.get(RISK_SCORE_STATUS).should('have.text', 'On'); | ||
|
||
// disable | ||
riskEngineStatusChange(); | ||
|
||
cy.get(RISK_SCORE_STATUS).should('have.text', 'Off'); | ||
|
||
// enable | ||
riskEngineStatusChange(); | ||
|
||
cy.get(RISK_SCORE_STATUS).should('have.text', 'On'); | ||
}); | ||
|
||
cy.get(RISK_PREVIEW_ERROR).contains('Preview failed'); | ||
it('should show error panel if API returns error ', () => { | ||
cy.get(RISK_SCORE_STATUS).should('have.text', 'Off'); | ||
|
||
cy.intercept('POST', '/internal/risk_score/preview', { | ||
statusCode: 200, | ||
body: { | ||
scores: { host: [], user: [] }, | ||
}, | ||
cy.intercept('POST', '/internal/risk_score/engine/init', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for this intercept. |
||
statusCode: 500, | ||
}); | ||
|
||
// init | ||
riskEngineStatusChange(); | ||
|
||
cy.get(RISK_SCORE_ERROR_PANEL).contains('Sorry, there was an error'); | ||
}); | ||
|
||
cy.get(RISK_PREVIEW_ERROR_BUTTON).click(); | ||
it('should update if there legacy risk score installed', () => { | ||
installRiskScoreModule(); | ||
visit(ENTITY_ANALYTICS_MANAGEMENT_URL); | ||
|
||
cy.get(RISK_SCORE_STATUS).should('not.exist'); | ||
|
||
cy.get(RISK_PREVIEW_ERROR).should('not.exist'); | ||
updateRiskEngine(); | ||
updateRiskEngineConfirm(); | ||
|
||
cy.get(RISK_SCORE_STATUS).should('have.text', 'On'); | ||
|
||
deleteRiskScore({ riskScoreEntity: RiskScoreEntity.host, spaceId: 'default' }); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I tend to pluralize enums to distinguish them from other types: