Skip to content

Commit a3af1ad

Browse files
committed
Addresses review feedback
1 parent 2355630 commit a3af1ad

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

x-pack/platform/plugins/shared/security/server/user_profile/user_profile_service.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('UserProfileService', () => {
7979
let mockRequest: ReturnType<typeof httpServerMock.createKibanaRequest>;
8080
beforeEach(() => {
8181
mockRequest = httpServerMock.createKibanaRequest({
82-
headers: { cookie: 'some-cookie' },
82+
headers: { sid: 'some-cookie' },
8383
});
8484

8585
mockUserProfile = userProfileMock.createWithSecurity({
@@ -99,7 +99,13 @@ describe('UserProfileService', () => {
9999
});
100100

101101
describe(`with session`, () => {
102-
// ToDo: test anonymous access case
102+
beforeEach(() => {
103+
mockStartParams.session.getSID.mockResolvedValue('some-session-id');
104+
});
105+
106+
afterEach(() => {
107+
mockStartParams.session.getSID.mockReset();
108+
});
103109

104110
it('returns `null` if session is not available', async () => {
105111
const startContract = userProfileService.start(mockStartParams);

x-pack/platform/plugins/shared/security/server/user_profile/user_profile_service.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ export class UserProfileService {
265265
const base64Credentials = authHeader.trim().substring('basic '.length);
266266
const [username, password] = Buffer.from(base64Credentials, 'base64').toString().split(':');
267267
if (!username || !password) {
268-
this.logger.debug(`Basic credentials are malformed, cannot extract username and password.`);
269-
return undefined;
268+
throw new Error(`Malformed basic credentials in Authorization header.`);
270269
}
271270

272271
const activatedProfile = await this.activate(clusterClient, {
@@ -338,16 +337,15 @@ export class UserProfileService {
338337
{ request, dataPath }: UserProfileGetCurrentParams
339338
) {
340339
if (request.auth.isAuthenticated === false) {
341-
this.logger.debug(`Request to get current user profile is not authenticated.`);
342-
return null;
340+
throw new Error('Request to get current user profile is not authenticated.');
343341
}
344342

345343
let profileId: string | undefined;
346344
let sessionId: string | undefined;
347345
let profileActivationRequired: boolean | undefined;
348346
let apiKeyRetrievalRequired: boolean | undefined;
349347

350-
if (request.headers.cookie) {
348+
if (await session.getSID(request)) {
351349
this.logger.debug(`Request to get current user profile is authenticated via session.`);
352350
({ profileId, sessionId } = await this.getCurrentUserProfileIdViaSession(session, request));
353351
} else {

0 commit comments

Comments
 (0)