Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ describe('EnterpriseSearchRequestHandler', () => {
expect(mockLogger.error).toHaveBeenCalled();
});

it('errors when receiving a 401 response', async () => {
EnterpriseSearchAPI.mockReturn({}, { status: 401 });
});

it('errors when redirected to /login', async () => {
EnterpriseSearchAPI.mockReturn({}, { url: 'http://localhost:3002/login' });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ export class EnterpriseSearchRequestHandler {
// Handle response headers
this.setResponseHeaders(apiResponse);

// Handle authentication redirects
if (apiResponse.url.endsWith('/login') || apiResponse.url.endsWith('/ent/select')) {
// Handle unauthenticated users / authentication redirects
if (
apiResponse.status === 401 ||
apiResponse.url.endsWith('/login') ||
apiResponse.url.endsWith('/ent/select')
) {
return this.handleAuthenticationError(response);
}

Expand Down Expand Up @@ -213,6 +217,10 @@ export class EnterpriseSearchRequestHandler {
return response.customError({ statusCode: 502, headers: this.headers, body: errorMessage });
}

/**
* Note: Kibana auto logs users out when it receives a 401 response, so we want to catch and
* return 401 responses from Enterprise Search as a 502 so Kibana sessions aren't interrupted
*/
handleAuthenticationError(response: KibanaResponseFactory) {
const errorMessage = 'Cannot authenticate Enterprise Search user';

Expand Down