-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[9.3] [Osquery] Fix profile_uid dropped in getUserInfo authc fallback (#258866)
#259258
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
Merged
+98
−1
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
14602d1
[Osquery] Fix `profile_uid` dropped in `getUserInfo` authc fallback (…
csr 4e6419f
Merge branch '9.3' into backport/9.3/pr-258866
csr a837a79
Merge branch '9.3' into backport/9.3/pr-258866
csr 1c16d13
Merge branch '9.3' into backport/9.3/pr-258866
csr a4c2030
Merge branch '9.3' into backport/9.3/pr-258866
csr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
x-pack/platform/plugins/shared/osquery/server/lib/get_user_info.test.ts
This file contains hidden or 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,97 @@ | ||
| /* | ||
| * 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 { httpServerMock, loggingSystemMock } from '@kbn/core/server/mocks'; | ||
| import type { SecurityPluginStart } from '@kbn/security-plugin/server'; | ||
| import { getUserInfo } from './get_user_info'; | ||
|
|
||
| describe('getUserInfo', () => { | ||
| const logger = loggingSystemMock.createLogger(); | ||
| const request = httpServerMock.createKibanaRequest(); | ||
|
|
||
| it('returns undefined when security is unavailable', async () => { | ||
| const result = await getUserInfo({ request, logger }); | ||
|
|
||
| expect(result).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns user profile info when available', async () => { | ||
| const security = { | ||
| userProfiles: { | ||
| getCurrent: jest.fn().mockResolvedValue({ | ||
| uid: 'profile-1', | ||
| user: { | ||
| username: 'user-name', | ||
| full_name: 'Full Name', | ||
| email: 'user@example.com', | ||
| }, | ||
| }), | ||
| }, | ||
| authc: { | ||
| getCurrentUser: jest.fn(), | ||
| }, | ||
| } as unknown as SecurityPluginStart; | ||
|
|
||
| const result = await getUserInfo({ request, security, logger }); | ||
|
|
||
| expect(result).toEqual({ | ||
| username: 'Full Name', | ||
| full_name: 'Full Name', | ||
| email: 'user@example.com', | ||
| profile_uid: 'profile-1', | ||
| }); | ||
| }); | ||
|
|
||
| it('falls back to authc when user profile lookup fails', async () => { | ||
| const security = { | ||
| userProfiles: { | ||
| getCurrent: jest.fn().mockRejectedValue(new Error('failed')), | ||
| }, | ||
| authc: { | ||
| getCurrentUser: jest.fn().mockReturnValue({ | ||
| username: 'fallback-user', | ||
| full_name: null, | ||
| email: 'fallback@example.com', | ||
| }), | ||
| }, | ||
| } as unknown as SecurityPluginStart; | ||
|
|
||
| const result = await getUserInfo({ request, security, logger }); | ||
|
|
||
| expect(result).toEqual({ | ||
| username: 'fallback@example.com', | ||
| full_name: null, | ||
| email: 'fallback@example.com', | ||
| profile_uid: null, | ||
| }); | ||
| }); | ||
|
|
||
| it('uses profile_uid from authc fallback when available', async () => { | ||
| const security = { | ||
| userProfiles: { | ||
| getCurrent: jest.fn().mockResolvedValue(null), | ||
| }, | ||
| authc: { | ||
| getCurrentUser: jest.fn().mockReturnValue({ | ||
| username: 'cloud-user', | ||
| full_name: null, | ||
| email: 'cloud-user@example.com', | ||
| profile_uid: 'u_cloud_profile_123', | ||
| }), | ||
| }, | ||
| } as unknown as SecurityPluginStart; | ||
|
|
||
| const result = await getUserInfo({ request, security, logger }); | ||
|
|
||
| expect(result).toEqual({ | ||
| username: 'cloud-user@example.com', | ||
| full_name: null, | ||
| email: 'cloud-user@example.com', | ||
| profile_uid: 'u_cloud_profile_123', | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
This test file was introduced in #249173 and doesn't exist on 9.3 (the PR wasn't backported). Is it OK if we introduce it in this backport PR? It adds coverage related to the change.