Skip to content

Commit

Permalink
Add catch for Enterprise Search sending back a 401 response instead o…
Browse files Browse the repository at this point in the history
…f redirect

- apparently this changed at some point between 7.9 and 7.10
  • Loading branch information
cee-chen committed Oct 16, 2020
1 parent 9157a62 commit f97b7a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit f97b7a0

Please sign in to comment.