forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add anomalies tab to user page (elastic#126079)
* Add anomalies tab to the users page
- Loading branch information
Showing
40 changed files
with
987 additions
and
462 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...curity_solution/public/common/components/ml/criteria/get_criteria_from_users_type.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { UsersType } from '../../../../users/store/model'; | ||
import { getCriteriaFromUsersType } from './get_criteria_from_users_type'; | ||
|
||
describe('get_criteria_from_user_type', () => { | ||
test('returns user name from criteria if the user type is details', () => { | ||
const criteria = getCriteriaFromUsersType(UsersType.details, 'admin'); | ||
expect(criteria).toEqual([{ fieldName: 'user.name', fieldValue: 'admin' }]); | ||
}); | ||
|
||
test('returns empty array from criteria if the user type is page but rather an empty array', () => { | ||
const criteria = getCriteriaFromUsersType(UsersType.page, 'admin'); | ||
expect(criteria).toEqual([]); | ||
}); | ||
|
||
test('returns empty array from criteria if the user name is undefined and user type is details', () => { | ||
const criteria = getCriteriaFromUsersType(UsersType.details, undefined); | ||
expect(criteria).toEqual([]); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
...ns/security_solution/public/common/components/ml/criteria/get_criteria_from_users_type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { UsersType } from '../../../../users/store/model'; | ||
import { CriteriaFields } from '../types'; | ||
|
||
export const getCriteriaFromUsersType = ( | ||
type: UsersType, | ||
userName: string | undefined | ||
): CriteriaFields[] => { | ||
if (type === UsersType.details && userName != null) { | ||
return [{ fieldName: 'user.name', fieldValue: userName }]; | ||
} else { | ||
return []; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...y_solution/public/common/components/ml/influencers/get_user_name_from_influencers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { getUserNameFromInfluencers } from './get_user_name_from_influencers'; | ||
import { mockAnomalies } from '../mock'; | ||
|
||
describe('get_user_name_from_influencers', () => { | ||
test('returns user names from influencers from the mock', () => { | ||
expect(getUserNameFromInfluencers(mockAnomalies.anomalies[0].influencers)).toEqual('root'); | ||
}); | ||
|
||
test('returns null if there are no influencers from the mock', () => { | ||
expect(getUserNameFromInfluencers([])).toEqual(null); | ||
}); | ||
|
||
test('returns null if it is given undefined influencers', () => { | ||
expect(getUserNameFromInfluencers()).toEqual(null); | ||
}); | ||
|
||
test('returns null if there influencers is an empty object', () => { | ||
expect(getUserNameFromInfluencers([{}])).toEqual(null); | ||
}); | ||
|
||
test('returns user name mixed with other data', () => { | ||
const userName = getUserNameFromInfluencers([ | ||
{ 'user.name': 'root' }, | ||
{ 'source.ip': '127.0.0.1' }, | ||
]); | ||
expect(userName).toEqual('root'); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
...curity_solution/public/common/components/ml/influencers/get_user_name_from_influencers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { getEntries } from '../get_entries'; | ||
|
||
export const getUserNameFromInfluencers = ( | ||
influencers: Array<Record<string, string>> = [], | ||
userName?: string | ||
): string | null => { | ||
const recordFound = influencers.find((influencer) => { | ||
const [influencerName, influencerValue] = getEntries(influencer); | ||
if (influencerName === 'user.name') { | ||
if (userName == null) { | ||
return true; | ||
} else { | ||
return influencerValue === userName; | ||
} | ||
} else { | ||
return false; | ||
} | ||
}); | ||
if (recordFound != null) { | ||
return Object.values(recordFound)[0]; | ||
} else { | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.