[Uptime] Allow users to save uptime settings with _inspect on [Fixes #116368] (#119142) (#119327)

This commit allows users to save uptime settings when they've got the
advanced setting to inspect ES queries turned on. Previously, it was not
possible to save these settings because the UI would not strip out the
unnecessary `_inspect` field from the response and thus would send it as
part of the configurations to change, which would then get refused
because of this unexpected field.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Lucas F. da Costa <lucas@lucasfcosta.com>
This commit is contained in:
Kibana Machine 2021-11-22 11:27:23 -05:00 committed by GitHub
parent b733af73aa
commit 40e06e6de4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 3 deletions

View file

@ -7,7 +7,7 @@
import * as t from 'io-ts';
export const DynamicSettingsType = t.type({
export const DynamicSettingsType = t.strict({
heartbeatIndices: t.string,
certAgeThreshold: t.number,
certExpirationThreshold: t.number,

View file

@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { omit } from 'lodash';
import { apiService } from './utils';
import { getDynamicSettings } from './dynamic_settings';
import { HttpSetup } from 'src/core/public';
import { DynamicSettings } from '../../../common/runtime_types/dynamic_settings';
describe('Dynamic Settings API', () => {
let fetchMock: jest.SpyInstance<Partial<unknown>>;
const defaultResponse: DynamicSettings & { _inspect: never[] } = {
heartbeatIndices: 'heartbeat-8*',
certAgeThreshold: 1,
certExpirationThreshold: 1337,
defaultConnectors: [],
_inspect: [],
};
beforeEach(() => {
apiService.http = {
get: jest.fn(),
fetch: jest.fn(),
} as unknown as HttpSetup;
apiService.addInspectorRequest = jest.fn();
fetchMock = jest.spyOn(apiService.http, 'fetch');
});
afterEach(() => {
jest.clearAllMocks();
});
it('omits the _inspect prop on the response as decoding', async () => {
fetchMock.mockReturnValue(new Promise((r) => r(defaultResponse)));
const resp = await getDynamicSettings();
expect(resp).toEqual(omit(defaultResponse, ['_inspect']));
});
});

View file

@ -18,7 +18,7 @@ import {
} from '../../common/translations';
import { API_URLS } from '../../common/constants';
export const createGetDynamicSettingsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
export const createGetDynamicSettingsRoute: UMRestApiRouteFactory = (_libs: UMServerLibs) => ({
method: 'GET',
path: API_URLS.DYNAMIC_SETTINGS,
validate: false,
@ -46,7 +46,7 @@ export const validateCertsValues = (
}
};
export const createPostDynamicSettingsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
export const createPostDynamicSettingsRoute: UMRestApiRouteFactory = (_libs: UMServerLibs) => ({
method: 'POST',
path: API_URLS.DYNAMIC_SETTINGS,
validate: {

View file

@ -16,6 +16,7 @@ import {
DYNAMIC_SETTINGS_DEFAULTS,
API_URLS,
} from '../../../../../plugins/uptime/common/constants';
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');