mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* Temporary Core workarounds. * Move files to NP Security Plugin. * Fix references. * Migrate to the New Platform. * Review#1: remove unused `loginAttempt` from provider iterator, rely more on RecursiveReadonly, etc. * Integrate latest core changes: isTlsEnabled and get rid of legacy ES config. * Revert `deepFreeze` changes and rely on `src/core/utils`. * Review#2: do not mutate injectedVars in onInit. Integrate latest upstream changes. * Use mocks provided by the Core. * Expect ElasticsearchError instead of Boom errors as 401 Cluster client errors. * Simplify session handling for `login`. * Review#3: properly handle session updates for `login`, remove redundant hapi-auth-cookie deps from x-pack package.json, migrate to new core sessionStorage API, integrate latest Kerberos provider changes from upstream * Do not clear session on login if it does not exist.
68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
*/
|
|
|
|
import Boom from 'boom';
|
|
import { errors as esErrors } from 'elasticsearch';
|
|
import * as errors from './errors';
|
|
|
|
describe('lib/errors', () => {
|
|
describe('#wrapError', () => {
|
|
it('returns given object', () => {
|
|
const err = new Error();
|
|
const returned = errors.wrapError(err);
|
|
expect(returned).toEqual(err);
|
|
});
|
|
|
|
it('error becomes boom error', () => {
|
|
const err = new Error();
|
|
errors.wrapError(err);
|
|
expect(err).toHaveProperty('isBoom', true);
|
|
});
|
|
|
|
it('defaults output.statusCode to 500', () => {
|
|
const err = new Error();
|
|
errors.wrapError(err);
|
|
expect(err).toHaveProperty('output.statusCode', 500);
|
|
});
|
|
|
|
it('sets output.statusCode to .status if given', () => {
|
|
const err: any = new Error();
|
|
err.status = 400;
|
|
errors.wrapError(err);
|
|
expect(err).toHaveProperty('output.statusCode', 400);
|
|
});
|
|
|
|
it('defaults message to "Internal Server Error"', () => {
|
|
const err = new Error();
|
|
errors.wrapError(err);
|
|
expect(err.message).toBe('Internal Server Error');
|
|
});
|
|
|
|
it('sets custom message if a 400 level error', () => {
|
|
const err: any = new Error('wat');
|
|
err.status = 499;
|
|
errors.wrapError(err);
|
|
expect(err).toHaveProperty('output.payload.message', 'wat');
|
|
});
|
|
});
|
|
|
|
describe('#getErrorStatusCode', () => {
|
|
it('extracts status code from Boom error', () => {
|
|
expect(errors.getErrorStatusCode(Boom.badRequest())).toBe(400);
|
|
expect(errors.getErrorStatusCode(Boom.unauthorized())).toBe(401);
|
|
});
|
|
|
|
it('extracts status code from Elasticsearch client error', () => {
|
|
expect(errors.getErrorStatusCode(new esErrors.BadRequest())).toBe(400);
|
|
expect(errors.getErrorStatusCode(new esErrors.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);
|
|
});
|
|
});
|
|
});
|