From 72de9c34c412eba8acdb85433b923e2ac7af7791 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Mon, 12 Sep 2022 15:59:00 -0400 Subject: [PATCH 01/21] synthetics - enable/disable - prevent incorrect keys from being added to the monitor saved object --- .../management/monitor_list_table/monitor_enabled.tsx | 2 +- .../monitors_page/overview/overview/actions_popover.tsx | 3 +-- .../apps/synthetics/hooks/use_monitor_enable_handler.tsx | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/monitor_enabled.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/monitor_enabled.tsx index be1123b12d417..e5e7c6bbe3781 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/monitor_enabled.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/monitor_enabled.tsx @@ -51,7 +51,7 @@ export const MonitorEnabled = ({ const handleEnabledChange = (event: EuiSwitchEvent) => { const checked = event.target.checked; - updateMonitorEnabledState(monitor, checked); + updateMonitorEnabledState(checked); }; return ( diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.tsx index 932c6344c4716..c0534c931edbc 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.tsx @@ -140,8 +140,7 @@ export function ActionsPopover({ name: enableLabel, icon: 'invert', onClick: () => { - if (status !== FETCH_STATUS.LOADING) - updateMonitorEnabledState(monitor, !monitor.isEnabled); + if (status !== FETCH_STATUS.LOADING) updateMonitorEnabledState(isEnabled); }, }, ], diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_enable_handler.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_enable_handler.tsx index 6fed27f2df6b5..b6a6fa60749bd 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_enable_handler.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_enable_handler.tsx @@ -41,11 +41,11 @@ export function useMonitorEnableHandler({ const savedObjEnabledState = upsertStatuses[id]?.enabled; const [isEnabled, setIsEnabled] = useState(null); const updateMonitorEnabledState = useCallback( - (monitor: EncryptedSyntheticsMonitor | MonitorOverviewItem, enabled: boolean) => { + (enabled: boolean) => { dispatch( fetchUpsertMonitorAction({ id, - monitor: { ...monitor, [ConfigKey.ENABLED]: enabled }, + monitor: { [ConfigKey.ENABLED]: enabled }, }) ); }, From 3520486fea2d8c5f5d9d5e4340195e3cf98fba20 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 12 Sep 2022 20:10:12 +0000 Subject: [PATCH 02/21] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../apps/synthetics/hooks/use_monitor_enable_handler.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_enable_handler.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_enable_handler.tsx index b6a6fa60749bd..e00b54ec4b75d 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_enable_handler.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_enable_handler.tsx @@ -9,11 +9,7 @@ import { useKibana } from '@kbn/kibana-react-plugin/public'; import { FETCH_STATUS } from '@kbn/observability-plugin/public'; import React, { useCallback, useEffect, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; -import { - ConfigKey, - EncryptedSyntheticsMonitor, - MonitorOverviewItem, -} from '../components/monitors_page/overview/types'; +import { ConfigKey } from '../components/monitors_page/overview/types'; import { clearMonitorUpsertStatus, fetchUpsertMonitorAction, From 8878b8ced8a19f98794e945dfcd6782c95690cb8 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Sat, 24 Sep 2022 15:50:00 -0400 Subject: [PATCH 03/21] adjust types --- .../monitors_page/overview/overview/actions_popover.tsx | 3 ++- .../public/apps/synthetics/state/monitor_list/actions.ts | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.tsx index c0534c931edbc..1267c2ab43c52 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.tsx @@ -140,7 +140,8 @@ export function ActionsPopover({ name: enableLabel, icon: 'invert', onClick: () => { - if (status !== FETCH_STATUS.LOADING) updateMonitorEnabledState(isEnabled); + if (status !== FETCH_STATUS.LOADING) + updateMonitorEnabledState(!monitor.isEnabled); }, }, ], diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/actions.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/actions.ts index 3315719a6bb16..fcfc3d4f22cf7 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/actions.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/actions.ts @@ -10,7 +10,6 @@ import { createAction } from '@reduxjs/toolkit'; import { EncryptedSyntheticsMonitor, MonitorManagementListResult, - MonitorOverviewItem, } from '../../../../../common/runtime_types'; import { createAsyncAction } from '../utils/actions'; @@ -23,7 +22,7 @@ export const fetchMonitorListAction = createAsyncAction< export interface UpsertMonitorRequest { id: string; - monitor: EncryptedSyntheticsMonitor | MonitorOverviewItem; + monitor: Partial; } export const fetchUpsertMonitorAction = createAction('fetchUpsertMonitor'); export const fetchUpsertSuccessAction = createAction<{ From 8ecb794f957244484204361843f241392c4d55ba Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Sat, 24 Sep 2022 16:10:43 -0400 Subject: [PATCH 04/21] add exact typing --- .../routes/monitor_cruds/monitor_validation.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.ts index d648722e0d5cd..29df6d3429189 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.ts @@ -4,6 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ +import * as t from 'io-ts'; import { isLeft } from 'fp-ts/lib/Either'; import { formatErrors } from '@kbn/securitysolution-io-ts-utils'; @@ -58,9 +59,10 @@ export function validateMonitor(monitorFields: MonitorFields): ValidationResult }; } - const codec = monitorTypeToCodecMap[monitorType]; + // Cast it to ICMPCodec to satisfy typing. During runtime, correct codec will be used to decode. + const SyntheticsMonitorCodec = monitorTypeToCodecMap[monitorType] as typeof ICMPSimpleFieldsCodec; - if (!codec) { + if (!SyntheticsMonitorCodec) { return { valid: false, reason: `Payload is not a valid monitor object`, @@ -69,8 +71,8 @@ export function validateMonitor(monitorFields: MonitorFields): ValidationResult }; } - // Cast it to ICMPCodec to satisfy typing. During runtime, correct codec will be used to decode. - const decodedMonitor = (codec as typeof ICMPSimpleFieldsCodec).decode(monitorFields); + const ExactSyntheticsMonitorCodec = t.exact(SyntheticsMonitorCodec); + const decodedMonitor = ExactSyntheticsMonitorCodec.decode(monitorFields); if (isLeft(decodedMonitor)) { return { @@ -87,8 +89,8 @@ export function validateMonitor(monitorFields: MonitorFields): ValidationResult export function validateProjectMonitor(monitorFields: ProjectMonitor): ValidationResult { const locationsError = monitorFields.locations && - monitorFields.locations.length === 0 && - (monitorFields.privateLocations ?? []).length === 0 + monitorFields.locations.length === 0 && + (monitorFields.privateLocations ?? []).length === 0 ? 'Invalid value "[]" supplied to field "locations"' : ''; // Cast it to ICMPCodec to satisfy typing. During runtime, correct codec will be used to decode. From 6a3921129bebeca2c51ecf66a9a423bd6ebc4a69 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Sat, 24 Sep 2022 20:17:26 +0000 Subject: [PATCH 05/21] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../server/routes/monitor_cruds/monitor_validation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.ts index 29df6d3429189..c60493a6aebae 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.ts @@ -89,8 +89,8 @@ export function validateMonitor(monitorFields: MonitorFields): ValidationResult export function validateProjectMonitor(monitorFields: ProjectMonitor): ValidationResult { const locationsError = monitorFields.locations && - monitorFields.locations.length === 0 && - (monitorFields.privateLocations ?? []).length === 0 + monitorFields.locations.length === 0 && + (monitorFields.privateLocations ?? []).length === 0 ? 'Invalid value "[]" supplied to field "locations"' : ''; // Cast it to ICMPCodec to satisfy typing. During runtime, correct codec will be used to decode. From a614583169671f0019a0084f6eddfd89263db961 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Sat, 24 Sep 2022 18:13:52 -0400 Subject: [PATCH 06/21] adjust test --- .../overview/actions_popover.test.tsx | 20 ++----------------- .../apps/synthetics/state/monitor_list/api.ts | 2 +- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.test.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.test.tsx index af6799068c278..d37fb8c2a3001 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.test.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.test.tsx @@ -111,15 +111,7 @@ describe('ActionsPopover', () => { const enableButton = getByText('Disable monitor'); fireEvent.click(enableButton); expect(updateMonitorEnabledState).toHaveBeenCalledTimes(1); - expect(updateMonitorEnabledState.mock.calls[0]).toEqual([ - { - id: 'somelongstring', - isEnabled: true, - location: { id: 'us_central', isServiceManaged: true }, - name: 'Monitor 1', - }, - false, - ]); + expect(updateMonitorEnabledState.mock.calls[0]).toEqual([false]); }); it('sets enabled state to true', async () => { @@ -139,14 +131,6 @@ describe('ActionsPopover', () => { const enableButton = getByText('Enable monitor'); fireEvent.click(enableButton); expect(updateMonitorEnabledState).toHaveBeenCalledTimes(1); - expect(updateMonitorEnabledState.mock.calls[0]).toEqual([ - { - id: 'somelongstring', - isEnabled: false, - location: { id: 'us_central', isServiceManaged: true }, - name: 'Monitor 1', - }, - true, - ]); + expect(updateMonitorEnabledState.mock.calls[0]).toEqual([true]); }); }); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/api.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/api.ts index 5e4e2e1bc1a67..50945b5bf1ea0 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/api.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/api.ts @@ -55,7 +55,7 @@ export const fetchUpsertMonitor = async ({ monitor, id, }: { - monitor: SyntheticsMonitor | EncryptedSyntheticsMonitor | MonitorOverviewItem; + monitor: Partial | Partial; id?: string; }): Promise<{ attributes: { errors: ServiceLocationErrors } } | SyntheticsMonitor> => { if (id) { From aa42c58026fa8f36d4710cc71b22a1cb138332f0 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Sat, 24 Sep 2022 18:19:50 -0400 Subject: [PATCH 07/21] use exact types --- .../apps/synthetics/state/monitor_list/api.ts | 1 - .../routes/monitor_cruds/add_monitor.ts | 11 +++--- .../monitor_cruds/monitor_validation.ts | 14 ++++++-- .../synthetics_service/run_once_monitor.ts | 4 +-- .../project_monitor_formatter.ts | 6 ++-- .../apis/uptime/rest/add_monitor.ts | 35 +++++++++++++++++++ 6 files changed, 56 insertions(+), 15 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/api.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/api.ts index 50945b5bf1ea0..f6a99fd3e02ed 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/api.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/api.ts @@ -11,7 +11,6 @@ import { FetchMonitorManagementListQueryArgs, MonitorManagementListResult, MonitorManagementListResultCodec, - MonitorOverviewItem, ServiceLocationErrors, SyntheticsMonitor, } from '../../../../../common/runtime_types'; diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts index 1016e37b87e08..048b7a8686958 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts @@ -67,7 +67,7 @@ export const addSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () => ({ const validationResult = validateMonitor(monitorWithDefaults as MonitorFields); - if (!validationResult.valid) { + if (!validationResult.valid || !validationResult.decodedMonitor) { const { reason: message, details, payload } = validationResult; return response.badRequest({ body: { message, attributes: { details, ...payload } } }); } @@ -78,8 +78,7 @@ export const addSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () => ({ try { const { errors, newMonitor } = await syncNewMonitor({ - normalizedMonitor: monitorWithDefaults, - monitor, + normalizedMonitor: validationResult.decodedMonitor, server, syntheticsMonitorClient, savedObjectsClient, @@ -140,7 +139,6 @@ export const createNewSavedObjectMonitor = async ({ export const syncNewMonitor = async ({ id, - monitor, server, syntheticsMonitorClient, savedObjectsClient, @@ -150,7 +148,6 @@ export const syncNewMonitor = async ({ spaceId, }: { id?: string; - monitor: SyntheticsMonitor; normalizedMonitor: SyntheticsMonitor; server: UptimeServerSetup; syntheticsMonitorClient: SyntheticsMonitorClient; @@ -164,6 +161,8 @@ export const syncNewMonitor = async ({ string, { preserve_namespace?: boolean } >; + // console.warn('monitor', monitor); + // console.warn('normalizedMonitor', normalizedMonitor); let monitorSavedObject: SavedObject | null = null; const monitorWithNamespace = { @@ -201,7 +200,7 @@ export const syncNewMonitor = async ({ formatTelemetryEvent({ errors: syncErrors, monitor: monitorSavedObject, - isInlineScript: Boolean((monitor as MonitorFields)[ConfigKey.SOURCE_INLINE]), + isInlineScript: Boolean((normalizedMonitor as MonitorFields)[ConfigKey.SOURCE_INLINE]), kibanaVersion: server.kibanaVersion, }) ); diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.ts index 29df6d3429189..77cd0fa23a7ce 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.ts @@ -20,6 +20,7 @@ import { ICMPSimpleFieldsCodec, MonitorFields, TCPFieldsCodec, + SyntheticsMonitor, } from '../../../common/runtime_types'; type MonitorCodecType = @@ -40,6 +41,7 @@ export interface ValidationResult { reason: string; details: string; payload: object; + decodedMonitor?: SyntheticsMonitor; } /** @@ -83,14 +85,20 @@ export function validateMonitor(monitorFields: MonitorFields): ValidationResult }; } - return { valid: true, reason: '', details: '', payload: monitorFields }; + return { + valid: true, + reason: '', + details: '', + payload: monitorFields, + decodedMonitor: decodedMonitor.right, + }; } export function validateProjectMonitor(monitorFields: ProjectMonitor): ValidationResult { const locationsError = monitorFields.locations && - monitorFields.locations.length === 0 && - (monitorFields.privateLocations ?? []).length === 0 + monitorFields.locations.length === 0 && + (monitorFields.privateLocations ?? []).length === 0 ? 'Invalid value "[]" supplied to field "locations"' : ''; // Cast it to ICMPCodec to satisfy typing. During runtime, correct codec will be used to decode. diff --git a/x-pack/plugins/synthetics/server/routes/synthetics_service/run_once_monitor.ts b/x-pack/plugins/synthetics/server/routes/synthetics_service/run_once_monitor.ts index 394567f45b600..5bbc8c27e3ebe 100644 --- a/x-pack/plugins/synthetics/server/routes/synthetics_service/run_once_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/synthetics_service/run_once_monitor.ts @@ -26,7 +26,7 @@ export const runOnceSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () = const validationResult = validateMonitor(monitor); - if (!validationResult.valid) { + if (!validationResult.valid || !validationResult.decodedMonitor) { const { reason: message, details, payload } = validationResult; return response.badRequest({ body: { message, attributes: { details, ...payload } } }); } @@ -36,7 +36,7 @@ export const runOnceSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () = const errors = await syntheticsService.runOnceConfigs([ formatHeartbeatRequest({ // making it enabled, even if it's disabled in the UI - monitor: { ...monitor, enabled: true }, + monitor: { ...validationResult.decodedMonitor, enabled: true }, monitorId, runOnce: true, }), diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts index aa0be87f0e818..06679400140a0 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts @@ -233,16 +233,16 @@ export class ProjectMonitorFormatter { } /* Validates that the normalized monitor is a valid monitor saved object type */ - const { valid: isNormalizedMonitorValid } = this.validateMonitor({ + const { valid: isNormalizedMonitorValid, decodedMonitor } = this.validateMonitor({ validationResult: validateMonitor(normalizedMonitor as MonitorFields), monitorId: monitor.id, }); - if (!isNormalizedMonitorValid) { + if (!isNormalizedMonitorValid || !decodedMonitor) { return null; } - return normalizedMonitor; + return decodedMonitor; } catch (e) { this.server.logger.error(e); this.failedMonitors.push({ diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts index 4e65bf1c4dbe3..00994a42a09cc 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts @@ -140,6 +140,41 @@ export default function ({ getService }: FtrProviderContext) { expect(apiResponse.status).eql(400); }); + it('cannot create a monitor with unknown keys', async () => { + // Delete a required property to make payload invalid + const newMonitor = { + name: 'Sample name', + url: 'https://elastic.co', + unknownKey: 'unknownValue', + type: 'http', + locations: [ + { + id: 'eu-west-01', + label: 'Europe West', + geo: { + lat: 33.2343132435, + lon: 73.2342343434, + }, + url: 'https://example-url.com', + isServiceManaged: true, + }, + ], + }; + + const apiResponse = await supertestAPI + .post(API_URLS.SYNTHETICS_MONITORS) + .set('kbn-xsrf', 'true') + .send(newMonitor) + .expect(200); + + const response = await supertestAPI + .get(`${API_URLS.SYNTHETICS_MONITORS}/${apiResponse.body.id}`) + .set('kbn-xsrf', 'true') + .expect(200); + + expect(response.body.attributes).not.to.have.keys('unknownkey', 'url'); + }); + it('can create monitor with API key with proper permissions', async () => { await supertestAPI .post('/internal/security/api_key') From 7a9ff1be34e6546141a1424a50efd8168833cb8a Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Sat, 24 Sep 2022 19:07:01 -0400 Subject: [PATCH 08/21] use exact types for editing --- .../routes/monitor_cruds/edit_monitor.ts | 6 +- .../project_monitor_formatter.ts | 4 +- .../apis/uptime/rest/edit_monitor.ts | 62 ++++++++++++++++++- 3 files changed, 66 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts index a16a1ba7089e5..d6b50880ed350 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts @@ -84,13 +84,13 @@ export const editSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () => ( const validationResult = validateMonitor(editedMonitor as MonitorFields); - if (!validationResult.valid) { + if (!validationResult.valid || !validationResult.decodedMonitor) { const { reason: message, details, payload } = validationResult; return response.badRequest({ body: { message, attributes: { details, ...payload } } }); } const monitorWithRevision = { - ...editedMonitor, + ...validationResult.decodedMonitor, revision: (previousMonitor.attributes[ConfigKey.REVISION] || 0) + 1, }; const formattedMonitor = formatSecrets(monitorWithRevision); @@ -102,7 +102,7 @@ export const editSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () => ( syntheticsMonitorClient, savedObjectsClient, request, - normalizedMonitor: editedMonitor, + normalizedMonitor: validationResult.decodedMonitor, monitorWithRevision: formattedMonitor, spaceId, }); diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts index 06679400140a0..0fb441f223e16 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts @@ -154,7 +154,7 @@ export class ProjectMonitorFormatter { await this.createMonitorsBulk(normalizedNewMonitors); - const { updatedCount } = await this.updateMonitors(normalizedUpdateMonitors); + const { updatedCount } = await this.updateMonitorsBulk(normalizedUpdateMonitors); if (normalizedUpdateMonitors.length > 0) { let updateMessage = ''; @@ -357,7 +357,7 @@ export class ProjectMonitorFormatter { ); }; - private updateMonitors = async ( + private updateMonitorsBulk = async ( monitors: Array<{ monitor: BrowserFields; previousMonitor: SavedObjectsFindResult; diff --git a/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts b/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts index 480d07e7144f3..eb44aa36a76c8 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts @@ -16,7 +16,7 @@ import { getFixtureJson } from './helper/get_fixture_json'; import { PrivateLocationTestService } from './services/private_location_test_service'; export default function ({ getService }: FtrProviderContext) { - describe('[PUT] /internal/uptime/service/monitors', function () { + describe('EditMonitor', function () { this.tags('skipCloud'); const supertest = getService('supertest'); @@ -109,6 +109,66 @@ export default function ({ getService }: FtrProviderContext) { ); }); + it('strips unknown keys from monitor edits', async () => { + const newMonitor = httpMonitorJson; + + const { id: monitorId, attributes: savedMonitor } = await saveMonitor( + newMonitor as MonitorFields + ); + + expect(savedMonitor).eql(omit(newMonitor, secretKeys)); + + const updates: Partial = { + [ConfigKey.URLS]: 'https://modified-host.com', + [ConfigKey.NAME]: 'Modified name', + [ConfigKey.LOCATIONS]: [ + { + id: 'eu-west-01', + label: 'Europe West', + geo: { + lat: 33.2343132435, + lon: 73.2342343434, + }, + url: 'https://example-url.com', + isServiceManaged: true, + }, + ], + [ConfigKey.REQUEST_HEADERS_CHECK]: { + sampleHeader2: 'sampleValue2', + }, + [ConfigKey.METADATA]: { + script_source: { + is_generated_script: false, + file_name: 'test-file.name', + }, + }, + unknownkey: 'unknownvalue', + } as Partial; + + const modifiedMonitor = omit( + { + ...newMonitor, + ...updates, + [ConfigKey.METADATA]: { + ...newMonitor[ConfigKey.METADATA], + ...updates[ConfigKey.METADATA], + }, + }, + ['unknownkey'] + ); + + const editResponse = await supertest + .put(API_URLS.SYNTHETICS_MONITORS + '/' + monitorId) + .set('kbn-xsrf', 'true') + .send(modifiedMonitor) + .expect(200); + + expect(editResponse.body.attributes).eql( + omit({ ...modifiedMonitor, revision: 2 }, secretKeys) + ); + expect(editResponse.body.attributes).not.to.have.keys('unknownkey'); + }); + it('returns 404 if monitor id is not present', async () => { const invalidMonitorId = 'invalid-id'; const expected404Message = `Monitor id ${invalidMonitorId} not found!`; From a840eaa4d497920e104594715f89be39b34b4439 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Sat, 24 Sep 2022 19:50:37 -0400 Subject: [PATCH 09/21] adjust types --- .../runtime_types/monitor_management/monitor_types.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts index 58e3a31df8a37..f2eabcaa40d44 100644 --- a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts +++ b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts @@ -83,6 +83,9 @@ export const CommonFieldsCodec = t.intersection([ [ConfigKey.MONITOR_SOURCE_TYPE]: SourceTypeCodec, [ConfigKey.CONFIG_ID]: t.string, [ConfigKey.JOURNEY_ID]: t.string, + [ConfigKey.PROJECT_ID]: t.string, + [ConfigKey.ORIGINAL_SPACE]: t.string, + [ConfigKey.CUSTOM_HEARTBEAT_ID]: t.string, }), ]); @@ -216,9 +219,6 @@ export const EncryptedBrowserSimpleFieldsCodec = t.intersection([ }), t.partial({ [ConfigKey.PLAYWRIGHT_OPTIONS]: t.string, - [ConfigKey.PROJECT_ID]: t.string, - [ConfigKey.ORIGINAL_SPACE]: t.string, - [ConfigKey.CUSTOM_HEARTBEAT_ID]: t.string, [ConfigKey.TEXT_ASSERTION]: t.string, }), ]), From a3de6fc5449ccc370da9f06fe36551fc77dbbdbc Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Sat, 24 Sep 2022 21:52:27 -0400 Subject: [PATCH 10/21] adjust tests --- .../monitor_management/monitor_types.ts | 22 ++- .../project_monitor_formatter.ts | 13 +- .../apis/uptime/rest/add_monitor_project.ts | 147 +++++++++++++++++- 3 files changed, 165 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts index f2eabcaa40d44..8abd4b06b0508 100644 --- a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts +++ b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts @@ -43,7 +43,14 @@ export const TLSSensitiveFieldsCodec = t.partial({ [ConfigKey.TLS_KEY_PASSPHRASE]: t.string, }); -export const TLSCodec = t.intersection([TLSFieldsCodec, TLSSensitiveFieldsCodec]); +export const TLSCodec = t.partial({ + [ConfigKey.TLS_CERTIFICATE_AUTHORITIES]: t.string, + [ConfigKey.TLS_CERTIFICATE]: t.string, + [ConfigKey.TLS_VERIFICATION_MODE]: VerificationModeCodec, + [ConfigKey.TLS_VERSION]: t.array(TLSVersionCodec), + [ConfigKey.TLS_KEY]: t.string, + [ConfigKey.TLS_KEY_PASSPHRASE]: t.string, +}); export type TLSFields = t.TypeOf; @@ -241,7 +248,7 @@ export const BrowserSensitiveSimpleFieldsCodec = t.intersection([ CommonFieldsCodec, ]); -export const BrowserAdvancedFieldsCodec = t.interface({ +export const EncryptedBrowserAdvancedFieldsCodec = t.interface({ [ConfigKey.SCREENSHOTS]: t.string, [ConfigKey.JOURNEY_FILTERS_MATCH]: t.string, [ConfigKey.JOURNEY_FILTERS_TAGS]: t.array(t.string), @@ -263,25 +270,26 @@ export const BrowserSensitiveAdvancedFieldsCodec = t.interface({ [ConfigKey.SYNTHETICS_ARGS]: t.array(t.string), }); -export const BrowserAdvancedsCodec = t.intersection([ - BrowserAdvancedFieldsCodec, +export const BrowserAdvancedFieldsCodec = t.intersection([ + EncryptedBrowserAdvancedFieldsCodec, BrowserSensitiveAdvancedFieldsCodec, ]); export const EncryptedBrowserFieldsCodec = t.intersection([ EncryptedBrowserSimpleFieldsCodec, - BrowserAdvancedFieldsCodec, + EncryptedBrowserAdvancedFieldsCodec, + TLSFieldsCodec, ]); export const BrowserFieldsCodec = t.intersection([ BrowserSimpleFieldsCodec, BrowserAdvancedFieldsCodec, - BrowserSensitiveAdvancedFieldsCodec, + TLSCodec, ]); export type BrowserFields = t.TypeOf; export type BrowserSimpleFields = t.TypeOf; -export type BrowserAdvancedFields = t.TypeOf; +export type BrowserAdvancedFields = t.TypeOf; // MonitorFields, represents any possible monitor type export const MonitorFieldsCodec = t.intersection([ diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts index 0fb441f223e16..6b337734df5f8 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts @@ -19,7 +19,6 @@ import { deleteMonitorBulk } from '../../routes/monitor_cruds/bulk_cruds/delete_ import { SyntheticsMonitorClient } from '../synthetics_monitor/synthetics_monitor_client'; import { syncEditedMonitorBulk } from '../../routes/monitor_cruds/bulk_cruds/edit_monitor_bulk'; import { - BrowserFields, ConfigKey, SyntheticsMonitorWithSecrets, EncryptedSyntheticsMonitor, @@ -124,16 +123,16 @@ export class ProjectMonitorFormatter { const existingMonitors = await this.getProjectMonitorsForProject(); this.staleMonitorsMap = await this.getStaleMonitorsMap(existingMonitors); - const normalizedNewMonitors: BrowserFields[] = []; + const normalizedNewMonitors: SyntheticsMonitor[] = []; const normalizedUpdateMonitors: Array<{ previousMonitor: SavedObjectsFindResult; - monitor: BrowserFields; + monitor: SyntheticsMonitor; }> = []; for (const monitor of this.monitors) { const previousMonitor = existingMonitors.find( (monitorObj) => - (monitorObj.attributes as BrowserFields)[ConfigKey.JOURNEY_ID] === monitor.id + (monitorObj.attributes as SyntheticsMonitor)[ConfigKey.JOURNEY_ID] === monitor.id ); const normM = await this.validateProjectMonitor({ @@ -264,7 +263,7 @@ export class ProjectMonitorFormatter { const staleMonitors: StaleMonitorMap = {}; existingMonitors.forEach((savedObject) => { - const journeyId = (savedObject.attributes as BrowserFields)[ConfigKey.JOURNEY_ID]; + const journeyId = (savedObject.attributes as SyntheticsMonitor)[ConfigKey.JOURNEY_ID]; if (journeyId) { staleMonitors[journeyId] = { stale: true, @@ -296,7 +295,7 @@ export class ProjectMonitorFormatter { return hits; }; - private createMonitorsBulk = async (monitors: BrowserFields[]) => { + private createMonitorsBulk = async (monitors: SyntheticsMonitor[]) => { try { if (monitors.length > 0) { const { newMonitors } = await syncNewMonitorBulk({ @@ -359,7 +358,7 @@ export class ProjectMonitorFormatter { private updateMonitorsBulk = async ( monitors: Array<{ - monitor: BrowserFields; + monitor: SyntheticsMonitor; previousMonitor: SavedObjectsFindResult; }> ): Promise<{ diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts index 1110bbb875c73..40a016b2cc56e 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts @@ -96,6 +96,114 @@ export default function ({ getService }: FtrProviderContext) { icmpProjectMonitors = setUniqueIds(getFixtureJson('project_icmp_monitor')); }); + it('project monitors - handles browser monitors', async () => { + const successfulMonitors = [projectMonitors.monitors[0]]; + + try { + const messages = await parseStreamApiResponse( + projectMonitorEndpoint, + JSON.stringify(projectMonitors) + ); + + expect(messages).to.have.length(2); + expect(messages[1].updatedMonitors).eql([]); + expect(messages[1].createdMonitors).eql(successfulMonitors.map((monitor) => monitor.id)); + expect(messages[1].failedMonitors).eql([]); + + for (const monitor of successfulMonitors) { + const journeyId = monitor.id; + const createdMonitorsResponse = await supertest + .get(API_URLS.SYNTHETICS_MONITORS) + .query({ filter: `${syntheticsMonitorType}.attributes.journey_id: ${journeyId}` }) + .set('kbn-xsrf', 'true') + .expect(200); + + const decryptedCreatedMonitor = await supertest + .get(`${API_URLS.SYNTHETICS_MONITORS}/${createdMonitorsResponse.body.monitors[0].id}`) + .set('kbn-xsrf', 'true') + .expect(200); + + expect(decryptedCreatedMonitor.body.attributes).to.eql({ + __ui: { + is_zip_url_tls_enabled: false, + script_source: { + file_name: '', + is_generated_script: false, + }, + }, + config_id: '', + custom_heartbeat_id: `${journeyId}-test-suite-default`, + enabled: true, + 'filter_journeys.match': 'check if title is present', + 'filter_journeys.tags': [], + form_monitor_type: 'multistep', + ignore_https_errors: false, + journey_id: journeyId, + locations: [ + { + geo: { + lat: 0, + lon: 0, + }, + id: 'localhost', + isInvalid: false, + isServiceManaged: true, + label: 'Local Synthetics Service', + status: 'experimental', + url: 'mockDevUrl', + }, + ], + name: 'check if title is present', + namespace: 'default', + origin: 'project', + original_space: 'default', + playwright_options: '{"headless":true,"chromiumSandbox":false}', + playwright_text_assertion: '', + project_id: 'test-suite', + params: '', + revision: 1, + schedule: { + number: '10', + unit: 'm', + }, + screenshots: 'on', + 'service.name': '', + 'source.zip_url.folder': '', + 'source.zip_url.proxy_url': '', + 'source.zip_url.url': '', + 'source.zip_url.password': '', + 'source.zip_url.username': '', + synthetics_args: [], + tags: [], + 'throttling.config': '5d/3u/20l', + 'throttling.download_speed': '5', + 'throttling.is_enabled': true, + 'throttling.latency': '20', + 'throttling.upload_speed': '3', + 'ssl.certificate': '', + 'ssl.certificate_authorities': '', + 'ssl.supported_protocols': ['TLSv1.1', 'TLSv1.2', 'TLSv1.3'], + 'ssl.verification_mode': 'full', + 'ssl.key': '', + 'ssl.key_passphrase': '', + 'source.inline.script': '', + 'source.project.content': + 'UEsDBBQACAAIAON5qVQAAAAAAAAAAAAAAAAfAAAAZXhhbXBsZXMvdG9kb3MvYmFzaWMuam91cm5leS50c22Q0WrDMAxF3/sVF7MHB0LMXlc6RvcN+wDPVWNviW0sdUsp/fe5SSiD7UFCWFfHujIGlpnkybwxFTZfoY/E3hsaLEtwhs9RPNWKDU12zAOxkXRIbN4tB9d9pFOJdO6EN2HMqQguWN9asFBuQVMmJ7jiWNII9fIXrbabdUYr58l9IhwhQQZCYORCTFFUC31Btj21NRc7Mq4Nds+4bDD/pNVgT9F52Jyr2Fa+g75LAPttg8yErk+S9ELpTmVotlVwnfNCuh2lepl3+JflUmSBJ3uggt1v9INW/lHNLKze9dJe1J3QJK8pSvWkm6aTtCet5puq+x63+AFQSwcIAPQ3VfcAAACcAQAAUEsBAi0DFAAIAAgA43mpVAD0N1X3AAAAnAEAAB8AAAAAAAAAAAAgAKSBAAAAAGV4YW1wbGVzL3RvZG9zL2Jhc2ljLmpvdXJuZXkudHNQSwUGAAAAAAEAAQBNAAAARAEAAAAA', + timeout: null, + type: 'browser', + 'url.port': null, + urls: '', + }); + } + } finally { + await Promise.all([ + successfulMonitors.map((monitor) => { + return deleteMonitor(monitor.id, httpProjectMonitors.project); + }), + ]); + } + }); + it('project monitors - handles http monitors', async () => { const kibanaVersion = await kibanaServer.version.get(); const successfulMonitors = [httpProjectMonitors.monitors[1]]; @@ -125,7 +233,12 @@ export default function ({ getService }: FtrProviderContext) { .set('kbn-xsrf', 'true') .expect(200); - expect(createdMonitorsResponse.body.monitors[0].attributes).to.eql({ + const decryptedCreatedMonitor = await supertest + .get(`${API_URLS.SYNTHETICS_MONITORS}/${createdMonitorsResponse.body.monitors[0].id}`) + .set('kbn-xsrf', 'true') + .expect(200); + + expect(decryptedCreatedMonitor.body.attributes).to.eql({ __ui: { is_tls_enabled: false, }, @@ -133,6 +246,16 @@ export default function ({ getService }: FtrProviderContext) { 'check.response.status': ['200'], config_id: '', custom_heartbeat_id: `${journeyId}-test-suite-default`, + 'check.response.body.negative': [], + 'check.response.body.positive': ['Saved', 'saved'], + 'check.response.headers': {}, + 'check.request.body': { + type: 'text', + value: '', + }, + 'check.request.headers': { + 'Content-Type': 'application/x-www-form-urlencoded', + }, enabled: false, form_monitor_type: 'http', journey_id: journeyId, @@ -156,6 +279,8 @@ export default function ({ getService }: FtrProviderContext) { origin: 'project', original_space: 'default', project_id: 'test-suite', + username: '', + password: '', proxy_url: '', 'response.include_body': 'always', 'response.include_headers': false, @@ -169,6 +294,8 @@ export default function ({ getService }: FtrProviderContext) { 'ssl.certificate_authorities': '', 'ssl.supported_protocols': ['TLSv1.1', 'TLSv1.2', 'TLSv1.3'], 'ssl.verification_mode': 'full', + 'ssl.key': '', + 'ssl.key_passphrase': '', tags: Array.isArray(monitor.tags) ? monitor.tags : monitor.tags?.split(','), timeout: '80', type: 'http', @@ -213,12 +340,19 @@ export default function ({ getService }: FtrProviderContext) { .set('kbn-xsrf', 'true') .expect(200); - expect(createdMonitorsResponse.body.monitors[0].attributes).to.eql({ + const decryptedCreatedMonitor = await supertest + .get(`${API_URLS.SYNTHETICS_MONITORS}/${createdMonitorsResponse.body.monitors[0].id}`) + .set('kbn-xsrf', 'true') + .expect(200); + + expect(decryptedCreatedMonitor.body.attributes).to.eql({ __ui: { is_tls_enabled: false, }, config_id: '', custom_heartbeat_id: `${journeyId}-test-suite-default`, + 'check.receive': '', + 'check.send': '', enabled: true, form_monitor_type: 'tcp', journey_id: journeyId, @@ -253,6 +387,8 @@ export default function ({ getService }: FtrProviderContext) { 'ssl.certificate_authorities': '', 'ssl.supported_protocols': ['TLSv1.1', 'TLSv1.2', 'TLSv1.3'], 'ssl.verification_mode': 'full', + 'ssl.key': '', + 'ssl.key_passphrase': '', tags: Array.isArray(monitor.tags) ? monitor.tags : monitor.tags?.split(','), timeout: '16', type: 'tcp', @@ -297,7 +433,12 @@ export default function ({ getService }: FtrProviderContext) { .set('kbn-xsrf', 'true') .expect(200); - expect(createdMonitorsResponse.body.monitors[0].attributes).to.eql({ + const decryptedCreatedMonitor = await supertest + .get(`${API_URLS.SYNTHETICS_MONITORS}/${createdMonitorsResponse.body.monitors[0].id}`) + .set('kbn-xsrf', 'true') + .expect(200); + + expect(decryptedCreatedMonitor.body.attributes).to.eql({ config_id: '', custom_heartbeat_id: `${journeyId}-test-suite-default`, enabled: true, From bebde5173c06a6d365ad55cd85da088f985fd722 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Sat, 24 Sep 2022 23:05:49 -0400 Subject: [PATCH 11/21] adjust types --- .../synthetics/common/formatters/browser/formatters.ts | 5 ++--- .../synthetics/common/formatters/common/formatters.ts | 3 +++ .../utils/testing/__mocks__/synthetics_store.mock.ts | 6 ++++-- .../components/fleet_package/common/normalizers.ts | 3 +++ .../server/synthetics_service/formatters/browser.ts | 5 ++--- .../server/synthetics_service/formatters/common.ts | 3 +++ 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/synthetics/common/formatters/browser/formatters.ts b/x-pack/plugins/synthetics/common/formatters/browser/formatters.ts index f05003f650deb..409f2b44343e8 100644 --- a/x-pack/plugins/synthetics/common/formatters/browser/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/browser/formatters.ts @@ -18,6 +18,7 @@ import { tlsValueToStringFormatter, tlsArrayToYamlFormatter, } from '../tls/formatters'; +import { tlsFormatters } from '../tls/formatters'; export type BrowserFormatMap = Record; @@ -72,10 +73,8 @@ export const browserFormatters: BrowserFormatMap = { arrayToJsonFormatter(fields[ConfigKey.JOURNEY_FILTERS_TAGS]), [ConfigKey.THROTTLING_CONFIG]: throttlingFormatter, [ConfigKey.IGNORE_HTTPS_ERRORS]: null, - [ConfigKey.PROJECT_ID]: null, [ConfigKey.PLAYWRIGHT_OPTIONS]: null, - [ConfigKey.CUSTOM_HEARTBEAT_ID]: null, - [ConfigKey.ORIGINAL_SPACE]: null, [ConfigKey.TEXT_ASSERTION]: null, ...commonFormatters, + ...tlsFormatters, }; diff --git a/x-pack/plugins/synthetics/common/formatters/common/formatters.ts b/x-pack/plugins/synthetics/common/formatters/common/formatters.ts index 89bf8793302ba..739c7184e7221 100644 --- a/x-pack/plugins/synthetics/common/formatters/common/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/common/formatters.ts @@ -29,6 +29,9 @@ export const commonFormatters: CommonFormatMap = { [ConfigKey.MONITOR_SOURCE_TYPE]: null, [ConfigKey.FORM_MONITOR_TYPE]: null, [ConfigKey.JOURNEY_ID]: null, + [ConfigKey.PROJECT_ID]: null, + [ConfigKey.CUSTOM_HEARTBEAT_ID]: null, + [ConfigKey.ORIGINAL_SPACE]: null, }; export const arrayToJsonFormatter = (value: string[] = []) => diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/utils/testing/__mocks__/synthetics_store.mock.ts b/x-pack/plugins/synthetics/public/apps/synthetics/utils/testing/__mocks__/synthetics_store.mock.ts index 57ce5e39a8dbd..5fa93522e6c9b 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/utils/testing/__mocks__/synthetics_store.mock.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/utils/testing/__mocks__/synthetics_store.mock.ts @@ -13,6 +13,8 @@ import { LocationStatus, ScheduleUnit, SourceType, + VerificationMode, + TLSVersion, } from '../../../../../../common/runtime_types'; /** @@ -338,8 +340,8 @@ function getMonitorDetailsMockSlice() { 'ssl.certificate': '', 'ssl.key': '', 'ssl.key_passphrase': '', - 'ssl.verification_mode': 'full', - 'ssl.supported_protocols': ['TLSv1.1', 'TLSv1.2', 'TLSv1.3'], + 'ssl.verification_mode': VerificationMode.FULL, + 'ssl.supported_protocols': ['TLSv1.1', 'TLSv1.2', 'TLSv1.3'] as TLSVersion[], revision: 1, updated_at: '2022-07-24T17:15:46.342Z', }, diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts index 14fab3caeb132..d05730c5dbe17 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts @@ -93,4 +93,7 @@ export const commonNormalizers: CommonNormalizerMap = { [ConfigKey.MONITOR_SOURCE_TYPE]: getCommonNormalizer(ConfigKey.MONITOR_SOURCE_TYPE), [ConfigKey.FORM_MONITOR_TYPE]: getCommonNormalizer(ConfigKey.FORM_MONITOR_TYPE), [ConfigKey.JOURNEY_ID]: getCommonNormalizer(ConfigKey.JOURNEY_ID), + [ConfigKey.PROJECT_ID]: getCommonNormalizer(ConfigKey.PROJECT_ID), + [ConfigKey.CUSTOM_HEARTBEAT_ID]: getCommonNormalizer(ConfigKey.CUSTOM_HEARTBEAT_ID), + [ConfigKey.ORIGINAL_SPACE]: getCommonNormalizer(ConfigKey.ORIGINAL_SPACE), }; diff --git a/x-pack/plugins/synthetics/server/synthetics_service/formatters/browser.ts b/x-pack/plugins/synthetics/server/synthetics_service/formatters/browser.ts index 9c9d24a3f58f4..d9ee08ace167c 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/browser.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/browser.ts @@ -14,6 +14,7 @@ import { } from './common'; import { BrowserFields, ConfigKey } from '../../../common/runtime_types/monitor_management'; import { DEFAULT_BROWSER_ADVANCED_FIELDS } from '../../../common/constants/monitor_defaults'; +import { tlsFormatters } from './tls'; export type BrowserFormatMap = Record; @@ -66,11 +67,9 @@ export const browserFormatters: BrowserFormatMap = { [ConfigKey.JOURNEY_FILTERS_TAGS]: (fields) => arrayFormatter(fields[ConfigKey.JOURNEY_FILTERS_TAGS]), [ConfigKey.IGNORE_HTTPS_ERRORS]: null, - [ConfigKey.PROJECT_ID]: null, [ConfigKey.PLAYWRIGHT_OPTIONS]: (fields) => stringToObjectFormatter(fields[ConfigKey.PLAYWRIGHT_OPTIONS] || ''), - [ConfigKey.CUSTOM_HEARTBEAT_ID]: null, - [ConfigKey.ORIGINAL_SPACE]: null, [ConfigKey.TEXT_ASSERTION]: null, ...commonFormatters, + ...tlsFormatters, }; diff --git a/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts b/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts index 16a0829cbb710..a2427357e3682 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts @@ -31,6 +31,9 @@ export const commonFormatters: CommonFormatMap = { fields[ConfigKey.MONITOR_SOURCE_TYPE] || SourceType.UI, [ConfigKey.FORM_MONITOR_TYPE]: null, [ConfigKey.JOURNEY_ID]: null, + [ConfigKey.PROJECT_ID]: null, + [ConfigKey.CUSTOM_HEARTBEAT_ID]: null, + [ConfigKey.ORIGINAL_SPACE]: null, }; export const arrayFormatter = (value: string[] = []) => (value.length ? value : null); From 5795c5ef468b8c9b9f049d21fa0b6a5be7eed7d0 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Sat, 24 Sep 2022 23:08:39 -0400 Subject: [PATCH 12/21] Update x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts --- x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts index 00994a42a09cc..f96479a50bc6f 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts @@ -140,7 +140,7 @@ export default function ({ getService }: FtrProviderContext) { expect(apiResponse.status).eql(400); }); - it('cannot create a monitor with unknown keys', async () => { + it('omits unknown keys', async () => { // Delete a required property to make payload invalid const newMonitor = { name: 'Sample name', From df617c6824c5bcf70f86fec556a4f799e59cc173 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Sun, 25 Sep 2022 08:20:46 -0400 Subject: [PATCH 13/21] adjust normalizers --- .../components/fleet_package/browser/normalizers.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/browser/normalizers.ts b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/browser/normalizers.ts index a8b59b16a3460..d1d9917f19c3a 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/browser/normalizers.ts +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/browser/normalizers.ts @@ -18,6 +18,7 @@ import { getNormalizer, getJsonToJavascriptNormalizer, } from '../common/normalizers'; +import { tlsNormalizers } from '../tls/normalizers'; import { defaultBrowserSimpleFields, defaultBrowserAdvancedFields } from '../contexts'; @@ -107,10 +108,8 @@ export const browserNormalizers: BrowserNormalizerMap = { ConfigKey.JOURNEY_FILTERS_TAGS ), [ConfigKey.IGNORE_HTTPS_ERRORS]: getBrowserNormalizer(ConfigKey.IGNORE_HTTPS_ERRORS), - [ConfigKey.PROJECT_ID]: getBrowserNormalizer(ConfigKey.PROJECT_ID), [ConfigKey.PLAYWRIGHT_OPTIONS]: getBrowserNormalizer(ConfigKey.PLAYWRIGHT_OPTIONS), - [ConfigKey.CUSTOM_HEARTBEAT_ID]: getBrowserNormalizer(ConfigKey.CUSTOM_HEARTBEAT_ID), - [ConfigKey.ORIGINAL_SPACE]: getBrowserNormalizer(ConfigKey.ORIGINAL_SPACE), [ConfigKey.TEXT_ASSERTION]: getBrowserNormalizer(ConfigKey.TEXT_ASSERTION), ...commonNormalizers, + ...tlsNormalizers, }; From 929c451c3ccc0c4821f6906b1b5ffe892108f2b0 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Sun, 25 Sep 2022 08:24:11 -0400 Subject: [PATCH 14/21] Update x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts --- .../runtime_types/monitor_management/monitor_types.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts index 8abd4b06b0508..27d2ceab050a8 100644 --- a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts +++ b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts @@ -43,14 +43,7 @@ export const TLSSensitiveFieldsCodec = t.partial({ [ConfigKey.TLS_KEY_PASSPHRASE]: t.string, }); -export const TLSCodec = t.partial({ - [ConfigKey.TLS_CERTIFICATE_AUTHORITIES]: t.string, - [ConfigKey.TLS_CERTIFICATE]: t.string, - [ConfigKey.TLS_VERIFICATION_MODE]: VerificationModeCodec, - [ConfigKey.TLS_VERSION]: t.array(TLSVersionCodec), - [ConfigKey.TLS_KEY]: t.string, - [ConfigKey.TLS_KEY_PASSPHRASE]: t.string, -}); +export const TLSCodec = t.intersection([TLSFieldsCodec, TLSSensitiveFieldsCodec]); export type TLSFields = t.TypeOf; From ec265de734a9d4447b04bd0c01138e1dc0773d3d Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Sun, 25 Sep 2022 08:24:55 -0400 Subject: [PATCH 15/21] Update x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts --- .../synthetics/server/routes/monitor_cruds/add_monitor.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts index 048b7a8686958..1f9a55e347618 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts @@ -161,8 +161,6 @@ export const syncNewMonitor = async ({ string, { preserve_namespace?: boolean } >; - // console.warn('monitor', monitor); - // console.warn('normalizedMonitor', normalizedMonitor); let monitorSavedObject: SavedObject | null = null; const monitorWithNamespace = { From 0e68251823c280dcabb8f79aa66330fd0ffce8d0 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Mon, 26 Sep 2022 10:17:52 -0400 Subject: [PATCH 16/21] adjust types --- .../common/constants/monitor_defaults.ts | 2 ++ .../monitor_management/monitor_types.ts | 2 ++ .../apis/uptime/rest/add_monitor_project.ts | 31 ++++++++----------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts index 1d142bbe33c68..a926cba109e62 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts @@ -108,6 +108,7 @@ export const DEFAULT_HTTP_SIMPLE_FIELDS: HTTPSimpleFields = { [ConfigKey.MAX_REDIRECTS]: '0', [ConfigKey.MONITOR_TYPE]: DataStream.HTTP, [ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.HTTP, + [ConfigKey.PORT]: null, }; export const DEFAULT_HTTP_ADVANCED_FIELDS: HTTPAdvancedFields = { @@ -144,6 +145,7 @@ export const DEFAULT_TCP_SIMPLE_FIELDS: TCPSimpleFields = { [ConfigKey.HOSTS]: '', [ConfigKey.MONITOR_TYPE]: DataStream.TCP, [ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.TCP, + [ConfigKey.PORT]: null, }; export const DEFAULT_TCP_ADVANCED_FIELDS: TCPAdvancedFields = { diff --git a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts index 8abd4b06b0508..fb231503f290e 100644 --- a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts +++ b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts @@ -103,6 +103,7 @@ export const TCPSimpleFieldsCodec = t.intersection([ t.interface({ [ConfigKey.METADATA]: MetadataCodec, [ConfigKey.HOSTS]: t.string, + [ConfigKey.PORT]: t.union([t.number, t.null]), }), CommonFieldsCodec, ]); @@ -160,6 +161,7 @@ export const HTTPSimpleFieldsCodec = t.intersection([ [ConfigKey.METADATA]: MetadataCodec, [ConfigKey.MAX_REDIRECTS]: t.string, [ConfigKey.URLS]: t.string, + [ConfigKey.PORT]: t.union([t.number, t.null]), }), CommonFieldsCodec, ]); diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts index 40a016b2cc56e..a7ea092517530 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts @@ -300,6 +300,7 @@ export default function ({ getService }: FtrProviderContext) { timeout: '80', type: 'http', urls: Array.isArray(monitor.urls) ? monitor.urls?.[0] : monitor.urls, + 'url.port': null, }); } } finally { @@ -393,6 +394,7 @@ export default function ({ getService }: FtrProviderContext) { timeout: '16', type: 'tcp', hosts: Array.isArray(monitor.hosts) ? monitor.hosts?.[0] : monitor.hosts, + 'url.port': null, }); } } finally { @@ -1418,8 +1420,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); expect(packagePolicy.name).eql( @@ -1477,8 +1478,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1499,8 +1499,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1537,8 +1536,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1572,8 +1570,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1617,8 +1614,8 @@ export default function ({ getService }: FtrProviderContext) { (pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + - '-' + - testPolicyId + '-' + + testPolicyId ); expect(packagePolicy.policy_id).eql(testPolicyId); @@ -1667,8 +1664,8 @@ export default function ({ getService }: FtrProviderContext) { (pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + - '-' + - testPolicyId + '-' + + testPolicyId ); expect(packagePolicy2).eql(undefined); @@ -1710,8 +1707,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1829,8 +1825,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] } - ${testPolicyId}` ); From 187179002cc58664994fc45d0fa8a8fd04642d22 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 26 Sep 2022 14:50:00 +0000 Subject: [PATCH 17/21] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../apis/uptime/rest/add_monitor_project.ts | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts index a7ea092517530..76af9a5731256 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts @@ -1420,7 +1420,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); expect(packagePolicy.name).eql( @@ -1478,7 +1479,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1499,7 +1501,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1536,7 +1539,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1570,7 +1574,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1614,8 +1619,8 @@ export default function ({ getService }: FtrProviderContext) { (pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + - '-' + - testPolicyId + '-' + + testPolicyId ); expect(packagePolicy.policy_id).eql(testPolicyId); @@ -1664,8 +1669,8 @@ export default function ({ getService }: FtrProviderContext) { (pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + - '-' + - testPolicyId + '-' + + testPolicyId ); expect(packagePolicy2).eql(undefined); @@ -1707,7 +1712,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1825,7 +1831,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] } - ${testPolicyId}` ); From 9b3d683f685916c0734d038e7d8d1c71b6c4665f Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Mon, 26 Sep 2022 12:49:29 -0400 Subject: [PATCH 18/21] adjust jest tests --- .../components/monitor_add_edit/form/formatter.test.tsx | 2 ++ .../server/routes/monitor_cruds/monitor_validation.test.ts | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/formatter.test.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/formatter.test.tsx index 4b4e778b87b9b..6ff7cd651b334 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/formatter.test.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/formatter.test.tsx @@ -134,6 +134,7 @@ describe('format', () => { timeout: '16', type: 'http', urls: 'sample url', + 'url.port': null, username: '', }); }); @@ -347,6 +348,7 @@ describe('format', () => { timeout: '16', type: 'http', urls: 'sample url', + 'url.port': null, username: '', }); }); diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.test.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.test.ts index 8a532279dda88..76bda0f4a2f12 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.test.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.test.ts @@ -109,6 +109,7 @@ describe('validateMonitor', () => { [ConfigKey.METADATA]: testMetaData, [ConfigKey.HOSTS]: 'https://host1.com', [ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.TCP, + [ConfigKey.PORT]: null, }; testTCPAdvancedFields = { @@ -131,6 +132,7 @@ describe('validateMonitor', () => { [ConfigKey.MAX_REDIRECTS]: '3', [ConfigKey.URLS]: 'https://example.com', [ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.HTTP, + [ConfigKey.PORT]: null, }; testHTTPAdvancedFields = { @@ -453,7 +455,8 @@ function getJsonPayload() { ' },' + ' "url": "https://example-url.com",' + ' "isServiceManaged": true' + - ' }]' + + ' }],' + + ' "url.port": null' + '}'; return JSON.parse(json); From a5b2f03d2f5c979b3caf8cb1ae2779ca9c98fe37 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Mon, 26 Sep 2022 13:02:25 -0400 Subject: [PATCH 19/21] adjust types --- x-pack/plugins/synthetics/common/formatters/http/formatters.ts | 1 + x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts | 1 + .../legacy_uptime/components/fleet_package/http/normalizers.ts | 1 + .../legacy_uptime/components/fleet_package/tcp/normalizers.ts | 1 + .../synthetics/server/synthetics_service/formatters/http.ts | 1 + .../synthetics/server/synthetics_service/formatters/tcp.ts | 1 + 6 files changed, 6 insertions(+) diff --git a/x-pack/plugins/synthetics/common/formatters/http/formatters.ts b/x-pack/plugins/synthetics/common/formatters/http/formatters.ts index 0dc9b795717a0..5eeb5888255dc 100644 --- a/x-pack/plugins/synthetics/common/formatters/http/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/http/formatters.ts @@ -41,6 +41,7 @@ export const httpFormatters: HTTPFormatMap = { [ConfigKey.REQUEST_HEADERS_CHECK]: (fields) => objectToJsonFormatter(fields[ConfigKey.REQUEST_HEADERS_CHECK]), [ConfigKey.REQUEST_METHOD_CHECK]: null, + [ConfigKey.PORT]: null, ...tlsFormatters, ...commonFormatters, }; diff --git a/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts b/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts index 5b3737229a129..bec7ceb444845 100644 --- a/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts @@ -19,6 +19,7 @@ export const tcpFormatters: TCPFormatMap = { [ConfigKey.PROXY_USE_LOCAL_RESOLVER]: null, [ConfigKey.RESPONSE_RECEIVE_CHECK]: null, [ConfigKey.REQUEST_SEND_CHECK]: null, + [ConfigKey.PORT]: null, ...tlsFormatters, ...commonFormatters, }; diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/http/normalizers.ts b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/http/normalizers.ts index f7e7ad3eeac2e..a783639f1ab18 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/http/normalizers.ts +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/http/normalizers.ts @@ -34,6 +34,7 @@ export const getHTTPJsonToJavascriptNormalizer = (key: ConfigKey) => { export const httpNormalizers: HTTPNormalizerMap = { [ConfigKey.METADATA]: getHTTPJsonToJavascriptNormalizer(ConfigKey.METADATA), [ConfigKey.URLS]: getHTTPNormalizer(ConfigKey.URLS), + [ConfigKey.PORT]: getHTTPNormalizer(ConfigKey.PORT), [ConfigKey.MAX_REDIRECTS]: getHTTPNormalizer(ConfigKey.MAX_REDIRECTS), [ConfigKey.USERNAME]: getHTTPNormalizer(ConfigKey.USERNAME), [ConfigKey.PASSWORD]: getHTTPNormalizer(ConfigKey.PASSWORD), diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/tcp/normalizers.ts b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/tcp/normalizers.ts index ae36de49fb57c..86efeeae69206 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/tcp/normalizers.ts +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/tcp/normalizers.ts @@ -33,6 +33,7 @@ export const getTCPJsonToJavascriptNormalizer = (key: ConfigKey) => { export const tcpNormalizers: TCPNormalizerMap = { [ConfigKey.METADATA]: getTCPJsonToJavascriptNormalizer(ConfigKey.METADATA), [ConfigKey.HOSTS]: getTCPNormalizer(ConfigKey.HOSTS), + [ConfigKey.PORT]: getTCPNormalizer(ConfigKey.PORT), [ConfigKey.PROXY_URL]: getTCPNormalizer(ConfigKey.PROXY_URL), [ConfigKey.PROXY_USE_LOCAL_RESOLVER]: getTCPNormalizer(ConfigKey.PROXY_USE_LOCAL_RESOLVER), [ConfigKey.RESPONSE_RECEIVE_CHECK]: getTCPNormalizer(ConfigKey.RESPONSE_RECEIVE_CHECK), diff --git a/x-pack/plugins/synthetics/server/synthetics_service/formatters/http.ts b/x-pack/plugins/synthetics/server/synthetics_service/formatters/http.ts index b8652e0813a0e..83545eb198ba7 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/http.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/http.ts @@ -14,6 +14,7 @@ export type HTTPFormatMap = Record; export const httpFormatters: HTTPFormatMap = { [ConfigKey.METADATA]: (fields) => objectFormatter(fields[ConfigKey.METADATA]), [ConfigKey.URLS]: null, + [ConfigKey.PORT]: null, [ConfigKey.MAX_REDIRECTS]: null, [ConfigKey.USERNAME]: null, [ConfigKey.PASSWORD]: null, diff --git a/x-pack/plugins/synthetics/server/synthetics_service/formatters/tcp.ts b/x-pack/plugins/synthetics/server/synthetics_service/formatters/tcp.ts index c295a17ed8964..25ba5c08e9b3c 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/tcp.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/tcp.ts @@ -14,6 +14,7 @@ export type TCPFormatMap = Record; export const tcpFormatters: TCPFormatMap = { [ConfigKey.METADATA]: null, [ConfigKey.HOSTS]: null, + [ConfigKey.PORT]: null, [ConfigKey.PROXY_URL]: null, [ConfigKey.PROXY_USE_LOCAL_RESOLVER]: null, [ConfigKey.RESPONSE_RECEIVE_CHECK]: null, From 4d4ca600e9b4efad0330d1d428ded03452aa9c81 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Mon, 26 Sep 2022 13:40:51 -0400 Subject: [PATCH 20/21] adjust api_integration tests --- .../uptime/rest/fixtures/http_monitor.json | 1 + .../uptime/rest/fixtures/icmp_monitor.json | 21 ++----------------- .../uptime/rest/fixtures/tcp_monitor.json | 1 + 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/x-pack/test/api_integration/apis/uptime/rest/fixtures/http_monitor.json b/x-pack/test/api_integration/apis/uptime/rest/fixtures/http_monitor.json index 76478fd7aee1a..45a2e11e9f306 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/fixtures/http_monitor.json +++ b/x-pack/test/api_integration/apis/uptime/rest/fixtures/http_monitor.json @@ -23,6 +23,7 @@ "max_redirects": "3", "password": "test", "urls": "https://nextjs-test-synthetics.vercel.app/api/users", + "url.port": null, "proxy_url": "http://proxy.com", "check.response.body.negative": [], "check.response.body.positive": [], diff --git a/x-pack/test/api_integration/apis/uptime/rest/fixtures/icmp_monitor.json b/x-pack/test/api_integration/apis/uptime/rest/fixtures/icmp_monitor.json index d9df06d1c7c32..052c811461ae7 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/fixtures/icmp_monitor.json +++ b/x-pack/test/api_integration/apis/uptime/rest/fixtures/icmp_monitor.json @@ -1,5 +1,5 @@ { - "type": "tcp", + "type": "icmp", "locations": [], "journey_id": "", "enabled": true, @@ -14,25 +14,8 @@ "tagT2" ], "timeout": "16", - "__ui": { - "is_tls_enabled": true, - "is_zip_url_tls_enabled": false - }, "hosts": "192.33.22.111:3333", - "proxy_url": "", - "proxy_use_local_resolver": false, - "check.receive": "", - "check.send": "", - "ssl.certificate_authorities": "", - "ssl.certificate": "", - "ssl.key": "", - "ssl.key_passphrase": "", - "ssl.verification_mode": "full", - "ssl.supported_protocols": [ - "TLSv1.1", - "TLSv1.2", - "TLSv1.3" - ], + "wait": "1", "name": "Test HTTP Monitor 04", "namespace": "testnamespace", "origin": "ui", diff --git a/x-pack/test/api_integration/apis/uptime/rest/fixtures/tcp_monitor.json b/x-pack/test/api_integration/apis/uptime/rest/fixtures/tcp_monitor.json index 1c726c1bcc70e..e0b4ca03b1d8d 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/fixtures/tcp_monitor.json +++ b/x-pack/test/api_integration/apis/uptime/rest/fixtures/tcp_monitor.json @@ -15,6 +15,7 @@ "is_zip_url_tls_enabled": false }, "hosts": "example-host:40", + "url.port": null, "proxy_url": "", "proxy_use_local_resolver": false, "check.receive": "", From 5c43159793242e07a487fe6929e795ebf570cd5f Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Thu, 29 Sep 2022 10:20:10 -0400 Subject: [PATCH 21/21] update tests --- .../project_monitor/normalizers/http_monitor.test.ts | 2 ++ .../project_monitor/normalizers/icmp_monitor.test.ts | 4 ++-- .../project_monitor/normalizers/tcp_monitor.test.ts | 7 +++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.test.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.test.ts index 922c5ca6dab05..cea5aa8b50de8 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.test.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.test.ts @@ -179,6 +179,7 @@ describe('http normalizers', () => { timeout: '80', type: 'http', urls: 'http://localhost:9200', + 'url.port': null, username: '', }, unsupportedKeys: ['check.response.body', 'unsupportedKey.nestedUnsupportedKey'], @@ -232,6 +233,7 @@ describe('http normalizers', () => { timeout: '80', type: 'http', urls: 'http://localhost:9200', + 'url.port': null, username: '', }, unsupportedKeys: [], diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/icmp_monitor.test.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/icmp_monitor.test.ts index e32ddf4f328a1..74ac2cb2bfaf3 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/icmp_monitor.test.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/icmp_monitor.test.ts @@ -8,7 +8,7 @@ import { Locations, LocationStatus, PrivateLocation } from '../../../../common/runtime_types'; import { normalizeProjectMonitors } from '.'; -describe('http normalizers', () => { +describe('icmp normalizers', () => { describe('normalize push monitors', () => { const projectId = 'test-project-id'; const locations: Locations = [ @@ -81,7 +81,7 @@ describe('http normalizers', () => { }, ]; - it('properly normalizes http monitors', () => { + it('properly normalizes icmp monitors', () => { const actual = normalizeProjectMonitors({ locations, privateLocations, diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/tcp_monitor.test.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/tcp_monitor.test.ts index 094bf018ba127..a479bbc09d47b 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/tcp_monitor.test.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/tcp_monitor.test.ts @@ -8,7 +8,7 @@ import { Locations, LocationStatus, PrivateLocation } from '../../../../common/runtime_types'; import { normalizeProjectMonitors } from '.'; -describe('http normalizers', () => { +describe('tcp normalizers', () => { describe('normalize push monitors', () => { const projectId = 'test-project-id'; const locations: Locations = [ @@ -83,7 +83,7 @@ describe('http normalizers', () => { }, ]; - it('properly normalizes http monitors', () => { + it('properly normalizes tcp monitors', () => { const actual = normalizeProjectMonitors({ locations, privateLocations, @@ -106,6 +106,7 @@ describe('http normalizers', () => { enabled: true, form_monitor_type: 'tcp', hosts: 'smtp.gmail.com:587', + 'url.port': null, journey_id: 'gmail-smtp', locations: [ { @@ -157,6 +158,7 @@ describe('http normalizers', () => { enabled: true, form_monitor_type: 'tcp', hosts: 'localhost:18278', + 'url.port': null, journey_id: 'always-down', locations: [ { @@ -221,6 +223,7 @@ describe('http normalizers', () => { enabled: true, form_monitor_type: 'tcp', hosts: 'localhost', + 'url.port': null, journey_id: 'always-down', locations: [ {