Skip to content

Commit

Permalink
use internalError for exceptions in authenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Aug 2, 2019
1 parent 534ad91 commit 6fb0fec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions x-pack/plugins/security/server/authentication/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('setupAuthentication()', () => {
expect(mockAuthToolkit.authenticated).toHaveBeenCalledTimes(1);
expect(mockAuthToolkit.authenticated).toHaveBeenCalledWith();
expect(mockResponse.redirected).not.toHaveBeenCalled();
expect(mockResponse.unauthorized).not.toHaveBeenCalled();
expect(mockResponse.internalError).not.toHaveBeenCalled();

expect(authenticate).not.toHaveBeenCalled();
});
Expand All @@ -164,7 +164,7 @@ describe('setupAuthentication()', () => {
requestHeaders: mockAuthHeaders,
});
expect(mockResponse.redirected).not.toHaveBeenCalled();
expect(mockResponse.unauthorized).not.toHaveBeenCalled();
expect(mockResponse.internalError).not.toHaveBeenCalled();

expect(authenticate).toHaveBeenCalledTimes(1);
expect(authenticate).toHaveBeenCalledWith(mockRequest);
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('setupAuthentication()', () => {
responseHeaders: mockAuthResponseHeaders,
});
expect(mockResponse.redirected).not.toHaveBeenCalled();
expect(mockResponse.unauthorized).not.toHaveBeenCalled();
expect(mockResponse.internalError).not.toHaveBeenCalled();

expect(authenticate).toHaveBeenCalledTimes(1);
expect(authenticate).toHaveBeenCalledWith(mockRequest);
Expand All @@ -210,7 +210,7 @@ describe('setupAuthentication()', () => {
headers: { location: '/some/url' },
});
expect(mockAuthToolkit.authenticated).not.toHaveBeenCalled();
expect(mockResponse.unauthorized).not.toHaveBeenCalled();
expect(mockResponse.internalError).not.toHaveBeenCalled();
});

it('rejects with `Internal Server Error` when `authenticate` throws unhandled exception', async () => {
Expand All @@ -219,8 +219,8 @@ describe('setupAuthentication()', () => {

await authHandler(httpServerMock.createKibanaRequest(), mockResponse, mockAuthToolkit);

expect(mockResponse.unauthorized).toHaveBeenCalledTimes(1);
const [[error]] = mockResponse.unauthorized.mock.calls;
expect(mockResponse.internalError).toHaveBeenCalledTimes(1);
const [[error]] = mockResponse.internalError.mock.calls;
expect(String(error)).toBe('Error: something went wrong');
expect(getErrorStatusCode(error)).toBe(500);

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/security/server/authentication/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function setupAuthentication({
authenticationResult = await authenticator.authenticate(request);
} catch (err) {
authLogger.error(err);
return response.unauthorized(wrapError(err));
return response.internalError(wrapError(err));
}

if (authenticationResult.succeeded()) {
Expand Down

0 comments on commit 6fb0fec

Please sign in to comment.