[UA] Protects against Cloud plugin being disabled (#31637) (#33167)

Currently, if the Cloud plugin is disabled the server will fail to start

Fixes #31612

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
This commit is contained in:
Josh Dover 2019-03-13 14:33:57 -05:00 committed by GitHub
parent aa7427414f
commit 44be79f323
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 13 deletions

View file

@ -16,26 +16,58 @@ import { registerClusterCheckupRoutes } from './cluster_checkup';
const MigrationApis = require('../lib/es_migration_apis');
MigrationApis.getUpgradeAssistantStatus = jest.fn();
function register(plugins = {}) {
const server = new Server();
server.plugins = {
elasticsearch: {
getCluster: () => ({ callWithRequest: jest.fn() } as any),
} as any,
...plugins,
} as any;
server.config = () => ({ get: () => '' } as any);
registerClusterCheckupRoutes(server);
return server;
}
/**
* Since these route callbacks are so thin, these serve simply as integration tests
* to ensure they're wired up to the lib functions correctly. Business logic is tested
* more thoroughly in the es_migration_apis test.
*/
describe('cluster checkup API', () => {
const server = new Server();
server.plugins = {
elasticsearch: {
getCluster: () => ({ callWithRequest: jest.fn() } as any),
} as any,
cloud: {
config: { isCloudEnabled: false },
},
} as any;
server.config = () => ({ get: () => '' } as any);
const spy = jest.spyOn(MigrationApis, 'getUpgradeAssistantStatus');
registerClusterCheckupRoutes(server);
afterEach(() => jest.clearAllMocks());
describe('with cloud enabled', () => {
it('is provided to getUpgradeAssistantStatus', async () => {
const server = register({
cloud: {
config: {
isCloudEnabled: true,
},
},
});
MigrationApis.getUpgradeAssistantStatus.mockResolvedValue({
cluster: [],
indices: [],
nodes: [],
});
await server.inject({
method: 'GET',
url: '/api/upgrade_assistant/status',
});
expect(spy.mock.calls[0][2]).toBe(true);
});
});
describe('GET /api/upgrade_assistant/reindex/{indexName}.json', () => {
const server = register();
it('returns state', async () => {
MigrationApis.getUpgradeAssistantStatus.mockResolvedValue({
cluster: [],

View file

@ -6,13 +6,14 @@
import Boom from 'boom';
import { Legacy } from 'kibana';
import _ from 'lodash';
import { getUpgradeAssistantStatus } from '../lib/es_migration_apis';
import { EsVersionPrecheck } from '../lib/es_version_precheck';
export function registerClusterCheckupRoutes(server: Legacy.Server) {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');
const { isCloudEnabled } = server.plugins.cloud.config;
const isCloudEnabled = _.get(server.plugins, 'cloud.config.isCloudEnabled', false);
server.route({
path: '/api/upgrade_assistant/status',

View file

@ -11,7 +11,7 @@ import { XPackMainPlugin } from 'x-pack/plugins/xpack_main/xpack_main';
declare module 'hapi' {
interface PluginProperties {
cloud: CloudPlugin;
cloud?: CloudPlugin;
xpack_main: XPackMainPlugin;
}
}