Skip to content

Commit

Permalink
Do not expect legacy Elasticsearch JS client errors in tests. (#107135)…
Browse files Browse the repository at this point in the history
… (#107151)

Co-authored-by: Aleh Zasypkin <aleh.zasypkin@gmail.com>
  • Loading branch information
kibanamachine and azasypkin committed Jul 29, 2021
1 parent 7b9a76d commit 0d3cc2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
13 changes: 0 additions & 13 deletions x-pack/plugins/security/server/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import { errors as esErrors } from '@elastic/elasticsearch';
import Boom from '@hapi/boom';
import { errors as legacyESErrors } from 'elasticsearch';

import * as errors from './errors';
import { securityMock } from './mocks';
Expand Down Expand Up @@ -72,11 +71,6 @@ describe('lib/errors', () => {
).toBe(401);
});

it('extracts status code from legacy Elasticsearch client error', () => {
expect(errors.getErrorStatusCode(new legacyESErrors.BadRequest())).toBe(400);
expect(errors.getErrorStatusCode(new legacyESErrors.AuthenticationException())).toBe(401);
});

it('extracts status code from `status` property', () => {
expect(errors.getErrorStatusCode({ statusText: 'Bad Request', status: 400 })).toBe(400);
expect(errors.getErrorStatusCode({ statusText: 'Unauthorized', status: 401 })).toBe(401);
Expand Down Expand Up @@ -120,13 +114,6 @@ describe('lib/errors', () => {
).toBe(JSON.stringify({ field1: 'value-1', field2: 'value-2' }));
});

it('extracts status code from legacy Elasticsearch client error', () => {
expect(errors.getDetailedErrorMessage(new legacyESErrors.BadRequest())).toBe('Bad Request');
expect(errors.getDetailedErrorMessage(new legacyESErrors.AuthenticationException())).toBe(
'Authentication Exception'
);
});

it('extracts `message` property', () => {
expect(errors.getDetailedErrorMessage(new Error('some-message'))).toBe('some-message');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { errors } from 'elasticsearch';
import { errors } from '@elastic/elasticsearch';

import type { ObjectType } from '@kbn/config-schema';
import type { PublicMethodsOf } from '@kbn/utility-types';
Expand All @@ -18,6 +18,7 @@ import { mockAuthenticatedUser } from '../../../common/model/authenticated_user.
import { AuthenticationResult } from '../../authentication';
import type { InternalAuthenticationServiceStart } from '../../authentication';
import { authenticationServiceMock } from '../../authentication/authentication_service.mock';
import { securityMock } from '../../mocks';
import type { Session } from '../../session_management';
import { sessionMock } from '../../session_management/session.mock';
import type { SecurityRequestHandlerContext, SecurityRouter } from '../../types';
Expand Down Expand Up @@ -109,9 +110,9 @@ describe('Change password', () => {
});

it('returns 403 if old password is wrong.', async () => {
const changePasswordFailure = new (errors.AuthenticationException as any)('Unauthorized', {
body: { error: { header: { 'WWW-Authenticate': 'Negotiate' } } },
});
const changePasswordFailure = new errors.ResponseError(
securityMock.createApiResponse({ statusCode: 401, body: {} })
);
mockContext.core.elasticsearch.client.asCurrentUser.security.changePassword.mockRejectedValue(
changePasswordFailure
);
Expand Down

0 comments on commit 0d3cc2e

Please sign in to comment.