[Synthetics] Update package version in api tests (#158264)

This commit is contained in:
Shahzad 2023-05-23 16:41:18 +02:00 committed by GitHub
parent bb1cf6609a
commit 02dcb336dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 652 additions and 688 deletions

View file

@ -9,6 +9,7 @@ import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
import expect from '@kbn/expect';
import { syntheticsParamType } from '@kbn/synthetics-plugin/common/types/saved_objects';
import { FtrProviderContext } from '../../ftr_provider_context';
import { PrivateLocationTestService } from './services/private_location_test_service';
export default function ({ getService }: FtrProviderContext) {
describe('AddEditParams', function () {
@ -19,14 +20,10 @@ export default function ({ getService }: FtrProviderContext) {
key: 'test',
value: 'test',
};
const testPrivateLocations = new PrivateLocationTestService(getService);
before(async () => {
await supertestAPI.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
await supertestAPI
.post('/api/fleet/epm/packages/synthetics/0.12.0')
.set('kbn-xsrf', 'true')
.send({ force: true })
.expect(200);
await testPrivateLocations.installSyntheticsPackage();
await kServer.savedObjects.clean({ types: [syntheticsParamType] });
});

View file

@ -36,12 +36,7 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
await kibanaServer.savedObjects.clean({ types: [syntheticsMonitorType] });
await supertestAPI.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
await supertestAPI
.post('/api/fleet/epm/packages/synthetics/0.12.0')
.set('kbn-xsrf', 'true')
.send({ force: true })
.expect(200);
await testPrivateLocations.installSyntheticsPackage();
_httpMonitorJson = getFixtureJson('http_monitor');
});
@ -162,7 +157,14 @@ export default function ({ getService }: FtrProviderContext) {
expect(packagePolicy.policy_id).eql(testFleetPolicyID);
comparePolicies(packagePolicy, getTestSyntheticsPolicy(httpMonitorJson.name, newMonitorId));
comparePolicies(
packagePolicy,
getTestSyntheticsPolicy({
name: httpMonitorJson.name,
id: newMonitorId,
location: { id: testFleetPolicyID },
})
);
});
let testFleetPolicyID2: string;
@ -209,7 +211,14 @@ export default function ({ getService }: FtrProviderContext) {
expect(packagePolicy.policy_id).eql(testFleetPolicyID);
comparePolicies(packagePolicy, getTestSyntheticsPolicy(httpMonitorJson.name, newMonitorId));
comparePolicies(
packagePolicy,
getTestSyntheticsPolicy({
name: httpMonitorJson.name,
id: newMonitorId,
location: { id: testFleetPolicyID },
})
);
packagePolicy = apiResponsePolicy.body.items.find(
(pkgPolicy: PackagePolicy) =>
@ -219,7 +228,14 @@ export default function ({ getService }: FtrProviderContext) {
expect(packagePolicy.policy_id).eql(testFleetPolicyID2);
comparePolicies(
packagePolicy,
getTestSyntheticsPolicy(httpMonitorJson.name, newMonitorId, 'Test private location 1')
getTestSyntheticsPolicy({
name: httpMonitorJson.name,
id: newMonitorId,
location: {
name: 'Test private location 1',
id: testFleetPolicyID2,
},
})
);
});
@ -245,7 +261,14 @@ export default function ({ getService }: FtrProviderContext) {
expect(packagePolicy.policy_id).eql(testFleetPolicyID);
comparePolicies(packagePolicy, getTestSyntheticsPolicy(httpMonitorJson.name, newMonitorId));
comparePolicies(
packagePolicy,
getTestSyntheticsPolicy({
name: httpMonitorJson.name,
id: newMonitorId,
location: { id: testFleetPolicyID },
})
);
packagePolicy = apiResponsePolicy.body.items.find(
(pkgPolicy: PackagePolicy) =>
@ -347,12 +370,12 @@ export default function ({ getService }: FtrProviderContext) {
expect(packagePolicy.name).eql(`${monitor.name}-Test private location 0-${SPACE_ID}`);
comparePolicies(
packagePolicy,
getTestSyntheticsPolicy(
monitor.name,
monitorId,
undefined,
formatKibanaNamespace(SPACE_ID)
)
getTestSyntheticsPolicy({
name: monitor.name,
id: monitorId,
location: { id: testFleetPolicyID },
namespace: formatKibanaNamespace(SPACE_ID),
})
);
await supertestWithoutAuth
.delete(`/s/${SPACE_ID}${API_URLS.SYNTHETICS_MONITORS}/${monitorId}`)
@ -402,7 +425,12 @@ export default function ({ getService }: FtrProviderContext) {
);
comparePolicies(
packagePolicy,
getTestSyntheticsPolicy(monitor.name, monitorId, undefined, undefined, true)
getTestSyntheticsPolicy({
name: monitor.name,
id: monitorId,
location: { id: testFleetPolicyID },
isTLSEnabled: true,
})
);
} finally {
await supertestAPI
@ -447,7 +475,14 @@ export default function ({ getService }: FtrProviderContext) {
(pkgPolicy: PackagePolicy) =>
pkgPolicy.id === monitorId + '-' + testFleetPolicyID + `-default`
);
comparePolicies(packagePolicy, getTestSyntheticsPolicy(monitor.name, monitorId));
comparePolicies(
packagePolicy,
getTestSyntheticsPolicy({
name: monitor.name,
id: monitorId,
location: { id: testFleetPolicyID },
})
);
} finally {
await supertestAPI
.delete(API_URLS.SYNTHETICS_MONITORS + '/' + monitorId)
@ -490,7 +525,7 @@ export default function ({ getService }: FtrProviderContext) {
pkgPolicy.id === monitorId + '-' + testFleetPolicyID + `-default`
);
expect(packagePolicy.package.version).eql('0.12.0');
expect(packagePolicy.package.version).eql('1.0.1');
await supertestAPI.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
const policyResponseAfterUpgrade = await supertestAPI.get(
@ -500,7 +535,7 @@ export default function ({ getService }: FtrProviderContext) {
(pkgPolicy: PackagePolicy) =>
pkgPolicy.id === monitorId + '-' + testFleetPolicyID + `-default`
);
expect(semver.gte(packagePolicyAfterUpgrade.package.version, '0.12.0')).eql(true);
expect(semver.gte(packagePolicyAfterUpgrade.package.version, '1.0.1')).eql(true);
} finally {
await supertestAPI
.delete(API_URLS.SYNTHETICS_MONITORS + '/' + monitorId)

View file

@ -78,12 +78,7 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
await supertest.put(API_URLS.SYNTHETICS_ENABLEMENT).set('kbn-xsrf', 'true').expect(200);
await supertest.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
await supertest
.post('/api/fleet/epm/packages/synthetics/0.12.0')
.set('kbn-xsrf', 'true')
.send({ force: true })
.expect(200);
await testPrivateLocations.installSyntheticsPackage();
const testPolicyName = 'Fleet test server policy' + Date.now();
const apiResponse = await testPrivateLocations.addFleetPolicy(testPolicyName);
@ -1446,6 +1441,7 @@ export default function ({ getService }: FtrProviderContext) {
id,
configId,
projectId: project,
locationId: testPolicyId,
locationName: 'Test private location 0',
})
);
@ -1514,6 +1510,7 @@ export default function ({ getService }: FtrProviderContext) {
configId,
projectId: project,
locationName: 'Test private location 0',
locationId: testPolicyId,
})
);
} finally {
@ -1636,6 +1633,7 @@ export default function ({ getService }: FtrProviderContext) {
id,
configId,
projectId: project,
locationId: testPolicyId,
locationName: 'Test private location 0',
})
);
@ -1717,6 +1715,7 @@ export default function ({ getService }: FtrProviderContext) {
id,
configId,
projectId: project,
locationId: testPolicyId,
locationName: 'Test private location 0',
})
);
@ -1754,6 +1753,7 @@ export default function ({ getService }: FtrProviderContext) {
id: id2,
configId: configId2,
projectId: project,
locationId: testPolicyId,
locationName: 'Test private location 0',
})
);

View file

@ -35,12 +35,7 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
await supertest.put(API_URLS.SYNTHETICS_ENABLEMENT).set('kbn-xsrf', 'true').expect(200);
await supertest.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
await supertest
.post('/api/fleet/epm/packages/synthetics/0.12.0')
.set('kbn-xsrf', 'true')
.send({ force: true })
.expect(200);
await testPrivateLocations.installSyntheticsPackage();
const testPolicyName = 'Fleet test server policy' + Date.now();
const apiResponse = await testPrivateLocations.addFleetPolicy(testPolicyName);

View file

@ -39,12 +39,7 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
_httpMonitorJson = getFixtureJson('http_monitor');
await supertest.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
await supertest
.post('/api/fleet/epm/packages/synthetics/0.12.0')
.set('kbn-xsrf', 'true')
.send({ force: true })
.expect(200);
await testPrivateLocations.installSyntheticsPackage();
const testPolicyName = 'Fleet test server policy' + Date.now();
const apiResponse = await testPrivateLocations.addFleetPolicy(testPolicyName);

View file

@ -38,12 +38,7 @@ export default function ({ getService }: FtrProviderContext) {
};
before(async () => {
await supertest.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
await supertest
.post('/api/fleet/epm/packages/synthetics/0.12.0')
.set('kbn-xsrf', 'true')
.send({ force: true })
.expect(200);
await testPrivateLocations.installSyntheticsPackage();
const testPolicyName = 'Fleet test server policy' + Date.now();
const apiResponse = await testPrivateLocations.addFleetPolicy(testPolicyName);

View file

@ -39,12 +39,7 @@ export default function ({ getService }: FtrProviderContext) {
};
before(async () => {
await supertest.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
await supertest
.post('/api/fleet/epm/packages/synthetics/0.12.0')
.set('kbn-xsrf', 'true')
.send({ force: true })
.expect(200);
await testPrivateLocations.installSyntheticsPackage();
const testPolicyName = 'Fleet test server policy' + Date.now();
const apiResponse = await testPrivateLocations.addFleetPolicy(testPolicyName);

View file

@ -1,288 +0,0 @@
/*
* 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 { PackagePolicy } from '@kbn/fleet-plugin/common';
export const getTestBrowserSyntheticsPolicy = ({
id,
params,
}: {
name: string;
id: string;
locationName?: string;
namespace?: string;
params?: Record<string, any>;
}): PackagePolicy => ({
id: 'abf904a4-cb9a-4b29-8c11-4d183cca289b-fe621d20-7b01-11ed-803f-475d82e1f9ca-default',
version: 'WzEzNzYsMV0=',
name: 'Test HTTP Monitor 03-Test private location 0-default',
namespace: 'testnamespace',
package: { name: 'synthetics', title: 'Elastic Synthetics', version: '0.12.0' },
enabled: true,
policy_id: 'fe621d20-7b01-11ed-803f-475d82e1f9ca',
inputs: [
{
type: 'synthetics/http',
policy_template: 'synthetics',
enabled: false,
streams: [
{
enabled: false,
data_stream: { type: 'synthetics', dataset: 'http' },
vars: {
__ui: { type: 'yaml' },
enabled: { value: true, type: 'bool' },
type: { value: 'http', type: 'text' },
name: { type: 'text' },
schedule: { value: '"@every 3m"', type: 'text' },
urls: { type: 'text' },
'service.name': { type: 'text' },
timeout: { type: 'text' },
max_redirects: { type: 'integer' },
proxy_url: { type: 'text' },
proxy_headers: { type: 'yaml' },
tags: { type: 'yaml' },
username: { type: 'text' },
password: { type: 'password' },
'response.include_headers': { type: 'bool' },
'response.include_body': { type: 'text' },
'response.include_body_max_bytes': { type: 'text' },
'check.request.method': { type: 'text' },
'check.request.headers': { type: 'yaml' },
'check.request.body': { type: 'yaml' },
'check.response.status': { type: 'yaml' },
'check.response.headers': { type: 'yaml' },
'check.response.body.positive': { type: 'yaml' },
'check.response.body.negative': { type: 'yaml' },
'check.response.json': { type: 'yaml' },
'ssl.certificate_authorities': { type: 'yaml' },
'ssl.certificate': { type: 'yaml' },
'ssl.key': { type: 'yaml' },
'ssl.key_passphrase': { type: 'text' },
'ssl.verification_mode': { type: 'text' },
'ssl.supported_protocols': { type: 'yaml' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { type: 'text' },
'monitor.project.id': { type: 'text' },
'monitor.project.name': { type: 'text' },
ipv4: { type: 'bool', value: true },
ipv6: { type: 'bool', value: true },
mode: { type: 'text' },
},
id: 'synthetics/http-http-abf904a4-cb9a-4b29-8c11-4d183cca289b-fe621d20-7b01-11ed-803f-475d82e1f9ca-default',
},
],
},
{
type: 'synthetics/tcp',
policy_template: 'synthetics',
enabled: false,
streams: [
{
enabled: false,
data_stream: { type: 'synthetics', dataset: 'tcp' },
vars: {
__ui: { type: 'yaml' },
enabled: { value: true, type: 'bool' },
type: { value: 'tcp', type: 'text' },
name: { type: 'text' },
schedule: { value: '"@every 3m"', type: 'text' },
hosts: { type: 'text' },
'service.name': { type: 'text' },
timeout: { type: 'text' },
proxy_url: { type: 'text' },
proxy_use_local_resolver: { value: false, type: 'bool' },
tags: { type: 'yaml' },
'check.send': { type: 'text' },
'check.receive': { type: 'text' },
'ssl.certificate_authorities': { type: 'yaml' },
'ssl.certificate': { type: 'yaml' },
'ssl.key': { type: 'yaml' },
'ssl.key_passphrase': { type: 'text' },
'ssl.verification_mode': { type: 'text' },
'ssl.supported_protocols': { type: 'yaml' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { type: 'text' },
'monitor.project.id': { type: 'text' },
'monitor.project.name': { type: 'text' },
ipv4: { type: 'bool', value: true },
ipv6: { type: 'bool', value: true },
mode: { type: 'text' },
},
id: 'synthetics/tcp-tcp-abf904a4-cb9a-4b29-8c11-4d183cca289b-fe621d20-7b01-11ed-803f-475d82e1f9ca-default',
},
],
},
{
type: 'synthetics/icmp',
policy_template: 'synthetics',
enabled: false,
streams: [
{
enabled: false,
data_stream: { type: 'synthetics', dataset: 'icmp' },
vars: {
__ui: { type: 'yaml' },
enabled: { value: true, type: 'bool' },
type: { value: 'icmp', type: 'text' },
name: { type: 'text' },
schedule: { value: '"@every 3m"', type: 'text' },
wait: { value: '1s', type: 'text' },
hosts: { type: 'text' },
'service.name': { type: 'text' },
timeout: { type: 'text' },
tags: { type: 'yaml' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { type: 'text' },
'monitor.project.id': { type: 'text' },
'monitor.project.name': { type: 'text' },
ipv4: { type: 'bool', value: true },
ipv6: { type: 'bool', value: true },
mode: { type: 'text' },
},
id: 'synthetics/icmp-icmp-abf904a4-cb9a-4b29-8c11-4d183cca289b-fe621d20-7b01-11ed-803f-475d82e1f9ca-default',
},
],
},
{
type: 'synthetics/browser',
policy_template: 'synthetics',
enabled: true,
streams: [
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser',
elasticsearch: { privileges: { indices: ['auto_configure', 'create_doc', 'read'] } },
},
vars: {
__ui: {
value:
'{"script_source":{"is_generated_script":false,"file_name":""},"is_tls_enabled":false}',
type: 'yaml',
},
enabled: { value: true, type: 'bool' },
type: { value: 'browser', type: 'text' },
name: { value: 'Test HTTP Monitor 03', type: 'text' },
schedule: { value: '"@every 3m"', type: 'text' },
'service.name': { value: '', type: 'text' },
timeout: { value: '16s', type: 'text' },
tags: { value: '["cookie-test","browser"]', type: 'yaml' },
'source.zip_url.url': { type: 'text' },
'source.zip_url.username': { type: 'text' },
'source.zip_url.folder': { type: 'text' },
'source.zip_url.password': { type: 'password' },
'source.inline.script': {
value:
'"step(\\"Visit /users api route\\", async () => {\\\\n const response = await page.goto(\'https://nextjs-test-synthetics.vercel.app/api/users\');\\\\n expect(response.status()).toEqual(200);\\\\n});"',
type: 'yaml',
},
'source.project.content': { value: '', type: 'text' },
params: { value: params ? JSON.stringify(params) : '', type: 'yaml' },
playwright_options: { value: '', type: 'yaml' },
screenshots: { value: 'on', type: 'text' },
synthetics_args: { value: null, type: 'text' },
ignore_https_errors: { value: false, type: 'bool' },
'throttling.config': {
value: JSON.stringify({ download: 5, upload: 3, latency: 20 }),
type: 'text',
},
'filter_journeys.tags': { value: null, type: 'yaml' },
'filter_journeys.match': { value: null, type: 'text' },
'source.zip_url.ssl.certificate_authorities': { type: 'yaml' },
'source.zip_url.ssl.certificate': { type: 'yaml' },
'source.zip_url.ssl.key': { type: 'yaml' },
'source.zip_url.ssl.key_passphrase': { type: 'text' },
'source.zip_url.ssl.verification_mode': { type: 'text' },
'source.zip_url.ssl.supported_protocols': { type: 'yaml' },
'source.zip_url.proxy_url': { type: 'text' },
location_name: { value: 'Test private location 0', type: 'text' },
id: { value: id, type: 'text' },
config_id: { value: id, type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { value: 'ui', type: 'text' },
'monitor.project.id': { value: null, type: 'text' },
'monitor.project.name': { value: null, type: 'text' },
},
id: 'synthetics/browser-browser-abf904a4-cb9a-4b29-8c11-4d183cca289b-fe621d20-7b01-11ed-803f-475d82e1f9ca-default',
compiled_stream: {
__ui: {
script_source: { is_generated_script: false, file_name: '' },
is_tls_enabled: false,
},
type: 'browser',
name: 'Test HTTP Monitor 03',
id,
origin: 'ui',
'run_from.id': 'Test private location 0',
'run_from.geo.name': 'Test private location 0',
enabled: true,
schedule: '@every 3m',
timeout: '16s',
throttling: { download: 5, upload: 3, latency: 20 },
tags: ['cookie-test', 'browser'],
'source.inline.script':
'step("Visit /users api route", async () => {\\n const response = await page.goto(\'https://nextjs-test-synthetics.vercel.app/api/users\');\\n expect(response.status()).toEqual(200);\\n});',
...(params ? { params } : {}),
screenshots: 'on',
processors: [
{
add_fields: {
target: '',
fields: {
'monitor.fleet_managed': true,
config_id: id,
},
},
},
],
},
},
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser.network',
elasticsearch: { privileges: { indices: ['auto_configure', 'create_doc', 'read'] } },
},
id: 'synthetics/browser-browser.network-abf904a4-cb9a-4b29-8c11-4d183cca289b-fe621d20-7b01-11ed-803f-475d82e1f9ca-default',
compiled_stream: {
processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }],
},
},
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser.screenshot',
elasticsearch: { privileges: { indices: ['auto_configure', 'create_doc', 'read'] } },
},
id: 'synthetics/browser-browser.screenshot-abf904a4-cb9a-4b29-8c11-4d183cca289b-fe621d20-7b01-11ed-803f-475d82e1f9ca-default',
compiled_stream: {
processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }],
},
},
],
},
],
is_managed: true,
revision: 1,
created_at: '2022-12-13T16:20:06.672Z',
created_by: 'system',
updated_at: '2022-12-13T16:20:06.672Z',
updated_by: 'system',
});

View file

@ -7,342 +7,518 @@
import { omit, sortBy } from 'lodash';
import expect from '@kbn/expect';
import { PackagePolicy } from '@kbn/fleet-plugin/common';
import { PackagePolicy, PackagePolicyConfigRecord } from '@kbn/fleet-plugin/common';
export const getTestSyntheticsPolicy = (
name: string,
id: string,
locationName?: string,
namespace?: string,
isTLSEnabled?: boolean,
proxyUrl?: string
): PackagePolicy => ({
id: '2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
version: 'WzE2MjYsMV0=',
name: 'test-monitor-name-Test private location 0-default',
namespace: namespace || 'testnamespace',
package: { name: 'synthetics', title: 'Elastic Synthetics', version: '0.12.0' },
enabled: true,
policy_id: '5347cd10-0368-11ed-8df7-a7424c6f5167',
inputs: [
{
type: 'synthetics/http',
policy_template: 'synthetics',
enabled: true,
streams: [
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'http',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
interface PolicyProps {
name?: string;
id: string;
configId?: string;
projectId?: string;
location: { name?: string; id?: string };
namespace?: string;
isTLSEnabled?: boolean;
proxyUrl?: string;
params?: Record<string, any>;
isBrowser?: boolean;
}
export const getTestSyntheticsPolicy = (props: PolicyProps): PackagePolicy => {
const { namespace } = props;
return {
id: '2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
version: 'WzE2MjYsMV0=',
name: 'test-monitor-name-Test private location 0-default',
namespace: namespace ?? 'testnamespace',
package: { name: 'synthetics', title: 'Elastic Synthetics', version: '1.0.1' },
enabled: true,
policy_id: '5347cd10-0368-11ed-8df7-a7424c6f5167',
inputs: [
getHttpInput(props),
{
type: 'synthetics/tcp',
policy_template: 'synthetics',
enabled: false,
streams: [
{
enabled: false,
data_stream: {
type: 'synthetics',
dataset: 'tcp',
},
vars: {
__ui: { type: 'yaml' },
enabled: { value: true, type: 'bool' },
type: { value: 'tcp', type: 'text' },
name: { type: 'text' },
schedule: { value: '"@every 3m"', type: 'text' },
hosts: { type: 'text' },
'service.name': { type: 'text' },
timeout: { type: 'text' },
proxy_url: { type: 'text' },
proxy_use_local_resolver: { value: false, type: 'bool' },
tags: { type: 'yaml' },
'check.send': { type: 'text' },
'check.receive': { type: 'text' },
'ssl.certificate_authorities': { type: 'yaml' },
'ssl.certificate': { type: 'yaml' },
'ssl.key': { type: 'yaml' },
'ssl.key_passphrase': { type: 'text' },
'ssl.verification_mode': { type: 'text' },
'ssl.supported_protocols': { type: 'yaml' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { type: 'text' },
'monitor.project.id': { type: 'text' },
'monitor.project.name': { type: 'text' },
ipv4: { type: 'bool', value: true },
ipv6: { type: 'bool', value: true },
mode: { type: 'text' },
},
id: 'synthetics/tcp-tcp-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
},
vars: {
__ui: {
value: `{"is_tls_enabled":${isTLSEnabled || false}}`,
type: 'yaml',
],
},
{
type: 'synthetics/icmp',
policy_template: 'synthetics',
enabled: false,
streams: [
{
enabled: false,
data_stream: {
type: 'synthetics',
dataset: 'icmp',
},
enabled: { value: true, type: 'bool' },
type: { value: 'http', type: 'text' },
name: { value: name, type: 'text' },
schedule: { value: '"@every 5m"', type: 'text' },
urls: { value: 'https://nextjs-test-synthetics.vercel.app/api/users', type: 'text' },
'service.name': { value: '', type: 'text' },
timeout: { value: '3ms', type: 'text' },
max_redirects: { value: '3', type: 'integer' },
proxy_url: { value: proxyUrl ?? 'http://proxy.com', type: 'text' },
proxy_headers: { value: null, type: 'yaml' },
tags: { value: '["tag1","tag2"]', type: 'yaml' },
username: { value: 'test-username', type: 'text' },
password: { value: 'test', type: 'password' },
'response.include_headers': { value: true, type: 'bool' },
'response.include_body': { value: 'never', type: 'text' },
'response.include_body_max_bytes': { value: '1024', type: 'text' },
'check.request.method': { value: '', type: 'text' },
'check.request.headers': {
value: '{"sampleHeader":"sampleHeaderValue"}',
type: 'yaml',
vars: {
__ui: { type: 'yaml' },
enabled: { value: true, type: 'bool' },
type: { value: 'icmp', type: 'text' },
name: { type: 'text' },
schedule: { value: '"@every 3m"', type: 'text' },
wait: { value: '1s', type: 'text' },
hosts: { type: 'text' },
'service.name': { type: 'text' },
timeout: { type: 'text' },
tags: { type: 'yaml' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { type: 'text' },
'monitor.project.id': { type: 'text' },
'monitor.project.name': { type: 'text' },
ipv4: { type: 'bool', value: true },
ipv6: { type: 'bool', value: true },
mode: { type: 'text' },
},
'check.request.body': { value: '"testValue"', type: 'yaml' },
'check.response.status': { value: '["200","201"]', type: 'yaml' },
'check.response.headers': { value: null, type: 'yaml' },
'check.response.body.positive': { value: null, type: 'yaml' },
'check.response.body.negative': { value: null, type: 'yaml' },
'check.response.json': { value: null, type: 'yaml' },
'ssl.certificate_authorities': {
value: isTLSEnabled ? '"t.string"' : null,
type: 'yaml',
},
'ssl.certificate': { value: isTLSEnabled ? '"t.string"' : null, type: 'yaml' },
'ssl.key': { value: isTLSEnabled ? '"t.string"' : null, type: 'yaml' },
'ssl.key_passphrase': { value: isTLSEnabled ? 't.string' : null, type: 'text' },
'ssl.verification_mode': { value: isTLSEnabled ? 'certificate' : null, type: 'text' },
'ssl.supported_protocols': {
value: isTLSEnabled ? '["TLSv1.1","TLSv1.2"]' : null,
type: 'yaml',
},
location_name: { value: locationName ?? 'Test private location 0', type: 'text' },
id: { value: id, type: 'text' },
config_id: { value: id, type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { value: 'ui', type: 'text' },
'monitor.project.id': { type: 'text', value: null },
'monitor.project.name': { type: 'text', value: null },
ipv4: { type: 'bool', value: true },
ipv6: { type: 'bool', value: true },
mode: { type: 'text', value: 'any' },
id: 'synthetics/icmp-icmp-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
},
id: 'synthetics/http-http-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
compiled_stream: {
__ui: {
is_tls_enabled: isTLSEnabled || false,
},
type: 'http',
name,
id,
origin: 'ui',
enabled: true,
urls: 'https://nextjs-test-synthetics.vercel.app/api/users',
schedule: '@every 5m',
timeout: '3ms',
max_redirects: 3,
proxy_url: proxyUrl ?? 'http://proxy.com',
tags: ['tag1', 'tag2'],
username: 'test-username',
password: 'test',
'run_from.geo.name': locationName ?? 'Test private location 0',
'run_from.id': locationName ?? 'Test private location 0',
'response.include_headers': true,
'response.include_body': 'never',
'check.request.method': null,
'check.request.headers': { sampleHeader: 'sampleHeaderValue' },
'check.request.body': 'testValue',
'check.response.status': ['200', '201'],
ipv4: true,
ipv6: true,
mode: 'any',
...(isTLSEnabled
? {
'ssl.certificate': 't.string',
'ssl.certificate_authorities': 't.string',
'ssl.key': 't.string',
'ssl.key_passphrase': 't.string',
'ssl.verification_mode': 'certificate',
'ssl.supported_protocols': ['TLSv1.1', 'TLSv1.2'],
}
: {}),
processors: [
{
add_fields: {
target: '',
fields: {
'monitor.fleet_managed': true,
config_id: id,
],
},
getBrowserInput(props),
],
is_managed: true,
revision: 1,
created_at: '2022-08-23T14:09:17.176Z',
created_by: 'system',
updated_at: '2022-08-23T14:09:17.176Z',
updated_by: 'system',
};
};
export const getHttpInput = ({
projectId,
id,
location,
proxyUrl,
isTLSEnabled,
isBrowser,
name = 'check if title is present-Test private location 0',
}: PolicyProps) => {
const enabled = !isBrowser;
const baseVars: PackagePolicyConfigRecord = {
__ui: { type: 'yaml' },
enabled: { value: true, type: 'bool' },
type: { value: 'http', type: 'text' },
name: { type: 'text' },
schedule: { value: '"@every 3m"', type: 'text' },
urls: { type: 'text' },
'service.name': { type: 'text' },
timeout: { type: 'text' },
max_redirects: { type: 'integer' },
proxy_url: { type: 'text' },
proxy_headers: { type: 'yaml' },
tags: { type: 'yaml' },
username: { type: 'text' },
password: { type: 'password' },
'response.include_headers': { type: 'bool' },
'response.include_body': { type: 'text' },
'response.include_body_max_bytes': { type: 'text' },
'check.request.method': { type: 'text' },
'check.request.headers': { type: 'yaml' },
'check.request.body': { type: 'yaml' },
'check.response.status': { type: 'yaml' },
'check.response.headers': { type: 'yaml' },
'check.response.body.positive': { type: 'yaml' },
'check.response.body.negative': { type: 'yaml' },
'check.response.json': { type: 'yaml' },
'ssl.certificate_authorities': { type: 'yaml' },
'ssl.certificate': { type: 'yaml' },
'ssl.key': { type: 'yaml' },
'ssl.key_passphrase': { type: 'text' },
'ssl.verification_mode': { type: 'text' },
'ssl.supported_protocols': { type: 'yaml' },
location_id: { value: 'fleet_managed', type: 'text' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { type: 'text' },
'monitor.project.id': { type: 'text' },
'monitor.project.name': { type: 'text' },
ipv4: { type: 'bool', value: true },
ipv6: { type: 'bool', value: true },
mode: { type: 'text' },
};
const enabledVars = {
__ui: {
value: `{"is_tls_enabled":${isTLSEnabled || false}}`,
type: 'yaml',
},
enabled: { value: true, type: 'bool' },
type: { value: 'http', type: 'text' },
name: { value: name, type: 'text' },
schedule: { value: '"@every 5m"', type: 'text' },
urls: { value: 'https://nextjs-test-synthetics.vercel.app/api/users', type: 'text' },
'service.name': { value: '', type: 'text' },
timeout: { value: '3ms', type: 'text' },
max_redirects: { value: '3', type: 'integer' },
proxy_url: { value: proxyUrl ?? 'http://proxy.com', type: 'text' },
proxy_headers: { value: null, type: 'yaml' },
tags: { value: '["tag1","tag2"]', type: 'yaml' },
username: { value: 'test-username', type: 'text' },
password: { value: 'test', type: 'password' },
'response.include_headers': { value: true, type: 'bool' },
'response.include_body': { value: 'never', type: 'text' },
'response.include_body_max_bytes': { value: '1024', type: 'text' },
'check.request.method': { value: '', type: 'text' },
'check.request.headers': {
value: '{"sampleHeader":"sampleHeaderValue"}',
type: 'yaml',
},
'check.request.body': { value: '"testValue"', type: 'yaml' },
'check.response.status': { value: '["200","201"]', type: 'yaml' },
'check.response.headers': { value: null, type: 'yaml' },
'check.response.body.positive': { value: null, type: 'yaml' },
'check.response.body.negative': { value: null, type: 'yaml' },
'check.response.json': { value: null, type: 'yaml' },
'ssl.certificate_authorities': {
value: isTLSEnabled ? '"t.string"' : null,
type: 'yaml',
},
'ssl.certificate': { value: isTLSEnabled ? '"t.string"' : null, type: 'yaml' },
'ssl.key': { value: isTLSEnabled ? '"t.string"' : null, type: 'yaml' },
'ssl.key_passphrase': { value: isTLSEnabled ? 't.string' : null, type: 'text' },
'ssl.verification_mode': { value: isTLSEnabled ? 'certificate' : null, type: 'text' },
'ssl.supported_protocols': {
value: isTLSEnabled ? '["TLSv1.1","TLSv1.2"]' : null,
type: 'yaml',
},
location_id: {
type: 'text',
value: location.id ?? 'aaa3c150-f94d-11ed-9895-d36d5472fafd',
},
location_name: { value: location.name ?? 'Test private location 0', type: 'text' },
id: { value: id, type: 'text' },
config_id: { value: id, type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { value: projectId ? 'project' : 'ui', type: 'text' },
'monitor.project.id': { type: 'text', value: projectId ?? null },
'monitor.project.name': { type: 'text', value: projectId ?? null },
ipv4: { type: 'bool', value: true },
ipv6: { type: 'bool', value: true },
mode: { type: 'text', value: 'any' },
};
const compiledHttpStream = {
__ui: {
is_tls_enabled: isTLSEnabled || false,
},
type: 'http',
name,
id,
origin: projectId ? 'project' : 'ui',
enabled: true,
urls: 'https://nextjs-test-synthetics.vercel.app/api/users',
schedule: '@every 5m',
timeout: '3ms',
max_redirects: 3,
proxy_url: proxyUrl ?? 'http://proxy.com',
tags: ['tag1', 'tag2'],
username: 'test-username',
password: 'test',
'run_from.geo.name': location?.name ?? 'Test private location 0',
'run_from.id': location?.id ?? 'Test private location 0',
'response.include_headers': true,
'response.include_body': 'never',
'response.include_body_max_bytes': 1024,
'check.request.method': null,
'check.request.headers': { sampleHeader: 'sampleHeaderValue' },
'check.request.body': 'testValue',
'check.response.status': ['200', '201'],
ipv4: true,
ipv6: true,
mode: 'any',
...(isTLSEnabled
? {
'ssl.certificate': 't.string',
'ssl.certificate_authorities': 't.string',
'ssl.key': 't.string',
'ssl.key_passphrase': 't.string',
'ssl.verification_mode': 'certificate',
'ssl.supported_protocols': ['TLSv1.1', 'TLSv1.2'],
}
: {}),
processors: [
{
add_fields: {
fields: {
config_id: id,
'monitor.fleet_managed': true,
},
target: '',
},
},
],
};
return {
type: 'synthetics/http',
policy_template: 'synthetics',
enabled,
streams: [
{
enabled,
data_stream: {
type: 'synthetics',
dataset: 'http',
...(enabled
? {
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
},
},
],
},
}
: {}),
},
],
},
{
type: 'synthetics/tcp',
policy_template: 'synthetics',
enabled: false,
streams: [
{
enabled: false,
data_stream: {
type: 'synthetics',
dataset: 'tcp',
},
vars: {
__ui: { type: 'yaml' },
enabled: { value: true, type: 'bool' },
type: { value: 'tcp', type: 'text' },
name: { type: 'text' },
schedule: { value: '"@every 3m"', type: 'text' },
hosts: { type: 'text' },
'service.name': { type: 'text' },
timeout: { type: 'text' },
proxy_url: { type: 'text' },
proxy_use_local_resolver: { value: false, type: 'bool' },
tags: { type: 'yaml' },
'check.send': { type: 'text' },
'check.receive': { type: 'text' },
'ssl.certificate_authorities': { type: 'yaml' },
'ssl.certificate': { type: 'yaml' },
'ssl.key': { type: 'yaml' },
'ssl.key_passphrase': { type: 'text' },
'ssl.verification_mode': { type: 'text' },
'ssl.supported_protocols': { type: 'yaml' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { type: 'text' },
'monitor.project.id': { type: 'text' },
'monitor.project.name': { type: 'text' },
ipv4: { type: 'bool', value: true },
ipv6: { type: 'bool', value: true },
mode: { type: 'text' },
},
id: 'synthetics/tcp-tcp-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
vars: enabled ? enabledVars : baseVars,
id: 'synthetics/http-http-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
...(enabled ? { compiled_stream: compiledHttpStream } : {}),
},
],
};
};
export const getBrowserInput = ({ id, params, isBrowser, projectId }: PolicyProps) => {
const compiledBrowser = isBrowser
? {
__ui: {
script_source: { is_generated_script: false, file_name: '' },
is_tls_enabled: false,
},
],
},
{
type: 'synthetics/icmp',
policy_template: 'synthetics',
enabled: false,
streams: [
{
enabled: false,
data_stream: {
type: 'synthetics',
dataset: 'icmp',
},
vars: {
__ui: { type: 'yaml' },
enabled: { value: true, type: 'bool' },
type: { value: 'icmp', type: 'text' },
name: { type: 'text' },
schedule: { value: '"@every 3m"', type: 'text' },
wait: { value: '1s', type: 'text' },
hosts: { type: 'text' },
'service.name': { type: 'text' },
timeout: { type: 'text' },
tags: { type: 'yaml' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { type: 'text' },
'monitor.project.id': { type: 'text' },
'monitor.project.name': { type: 'text' },
ipv4: { type: 'bool', value: true },
ipv6: { type: 'bool', value: true },
mode: { type: 'text' },
},
id: 'synthetics/icmp-icmp-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
},
],
},
{
type: 'synthetics/browser',
policy_template: 'synthetics',
enabled: false,
streams: [
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
type: 'browser',
name: 'Test HTTP Monitor 03',
id,
origin: 'ui',
'run_from.id': 'Test private location 0',
'run_from.geo.name': 'Test private location 0',
enabled: true,
schedule: '@every 3m',
timeout: '16s',
throttling: { download: 5, upload: 3, latency: 20 },
tags: ['cookie-test', 'browser'],
'source.inline.script':
'step("Visit /users api route", async () => {\\n const response = await page.goto(\'https://nextjs-test-synthetics.vercel.app/api/users\');\\n expect(response.status()).toEqual(200);\\n});',
...(params ? { params } : {}),
screenshots: 'on',
processors: [
{
add_fields: {
target: '',
fields: {
'monitor.fleet_managed': true,
config_id: id,
},
},
},
vars: {
__ui: { type: 'yaml' },
enabled: { value: true, type: 'bool' },
type: { value: 'browser', type: 'text' },
name: { type: 'text' },
schedule: { value: '"@every 3m"', type: 'text' },
'service.name': { type: 'text' },
timeout: { type: 'text' },
tags: { type: 'yaml' },
'source.zip_url.url': { type: 'text' },
'source.zip_url.username': { type: 'text' },
'source.zip_url.folder': { type: 'text' },
'source.zip_url.password': { type: 'password' },
'source.inline.script': { type: 'yaml' },
'source.project.content': { type: 'text' },
params: { type: 'yaml' },
playwright_options: { type: 'yaml' },
screenshots: { type: 'text' },
synthetics_args: { type: 'text' },
ignore_https_errors: { type: 'bool' },
'throttling.config': { type: 'text' },
'filter_journeys.tags': { type: 'yaml' },
'filter_journeys.match': { type: 'text' },
'source.zip_url.ssl.certificate_authorities': { type: 'yaml' },
'source.zip_url.ssl.certificate': { type: 'yaml' },
'source.zip_url.ssl.key': { type: 'yaml' },
'source.zip_url.ssl.key_passphrase': { type: 'text' },
'source.zip_url.ssl.verification_mode': { type: 'text' },
'source.zip_url.ssl.supported_protocols': { type: 'yaml' },
'source.zip_url.proxy_url': { type: 'text' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { type: 'text' },
'monitor.project.id': { type: 'text' },
'monitor.project.name': { type: 'text' },
},
id: 'synthetics/browser-browser-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
compiled_stream: {
__ui: null,
type: 'browser',
name: null,
enabled: true,
schedule: '@every 3m',
'run_from.id': 'Fleet managed',
'run_from.geo.name': 'Fleet managed',
timeout: null,
throttling: null,
processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }],
},
],
}
: {
__ui: null,
type: 'browser',
name: null,
enabled: true,
schedule: '@every 3m',
'run_from.id': 'Fleet managed',
'run_from.geo.name': 'Fleet managed',
timeout: null,
throttling: null,
processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }],
};
const browserVars = isBrowser
? {
__ui: {
value:
'{"script_source":{"is_generated_script":false,"file_name":""},"is_tls_enabled":false}',
type: 'yaml',
},
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser.network',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
enabled: { value: true, type: 'bool' },
type: { value: 'browser', type: 'text' },
name: { value: 'Test HTTP Monitor 03', type: 'text' },
schedule: { value: '"@every 3m"', type: 'text' },
'service.name': { value: '', type: 'text' },
timeout: { value: '16s', type: 'text' },
tags: { value: '["cookie-test","browser"]', type: 'yaml' },
'source.zip_url.url': { type: 'text' },
'source.zip_url.username': { type: 'text' },
'source.zip_url.folder': { type: 'text' },
'source.zip_url.password': { type: 'password' },
'source.inline.script': {
value:
'"step(\\"Visit /users api route\\", async () => {\\\\n const response = await page.goto(\'https://nextjs-test-synthetics.vercel.app/api/users\');\\\\n expect(response.status()).toEqual(200);\\\\n});"',
type: 'yaml',
},
'source.project.content': { value: '', type: 'text' },
params: { value: params ? JSON.stringify(params) : '', type: 'yaml' },
playwright_options: { value: '', type: 'yaml' },
screenshots: { value: 'on', type: 'text' },
synthetics_args: { value: null, type: 'text' },
ignore_https_errors: { value: false, type: 'bool' },
'throttling.config': {
value: JSON.stringify({ download: 5, upload: 3, latency: 20 }),
type: 'text',
},
'filter_journeys.tags': { value: null, type: 'yaml' },
'filter_journeys.match': { value: null, type: 'text' },
'source.zip_url.ssl.certificate_authorities': { type: 'yaml' },
'source.zip_url.ssl.certificate': { type: 'yaml' },
'source.zip_url.ssl.key': { type: 'yaml' },
'source.zip_url.ssl.key_passphrase': { type: 'text' },
'source.zip_url.ssl.verification_mode': { type: 'text' },
'source.zip_url.ssl.supported_protocols': { type: 'yaml' },
'source.zip_url.proxy_url': { type: 'text' },
location_id: {
type: 'text',
value: 'fleet_managed',
},
location_name: { value: 'Test private location 0', type: 'text' },
id: { value: id, type: 'text' },
config_id: { value: id, type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { value: 'ui', type: 'text' },
'monitor.project.id': { value: projectId ?? null, type: 'text' },
'monitor.project.name': { value: projectId ?? null, type: 'text' },
}
: {
__ui: { type: 'yaml' },
enabled: { value: true, type: 'bool' },
type: { value: 'browser', type: 'text' },
name: { type: 'text' },
schedule: { value: '"@every 3m"', type: 'text' },
'service.name': { type: 'text' },
timeout: { type: 'text' },
tags: { type: 'yaml' },
'source.zip_url.url': { type: 'text' },
'source.zip_url.username': { type: 'text' },
'source.zip_url.folder': { type: 'text' },
'source.zip_url.password': { type: 'password' },
'source.inline.script': { type: 'yaml' },
'source.project.content': { type: 'text' },
params: { type: 'yaml' },
playwright_options: { type: 'yaml' },
screenshots: { type: 'text' },
synthetics_args: { type: 'text' },
ignore_https_errors: { type: 'bool' },
'throttling.config': { type: 'text' },
'filter_journeys.tags': { type: 'yaml' },
'filter_journeys.match': { type: 'text' },
'source.zip_url.ssl.certificate_authorities': { type: 'yaml' },
'source.zip_url.ssl.certificate': { type: 'yaml' },
'source.zip_url.ssl.key': { type: 'yaml' },
'source.zip_url.ssl.key_passphrase': { type: 'text' },
'source.zip_url.ssl.verification_mode': { type: 'text' },
'source.zip_url.ssl.supported_protocols': { type: 'yaml' },
'source.zip_url.proxy_url': { type: 'text' },
location_name: { value: 'Fleet managed', type: 'text' },
location_id: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
run_once: { value: false, type: 'bool' },
origin: { type: 'text' },
'monitor.project.id': { type: 'text' },
'monitor.project.name': { type: 'text' },
};
return {
type: 'synthetics/browser',
policy_template: 'synthetics',
enabled: false,
streams: [
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
},
id: 'synthetics/browser-browser.network-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
compiled_stream: {
processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }],
},
},
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser.screenshot',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
vars: browserVars,
id: 'synthetics/browser-browser-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
compiled_stream: compiledBrowser,
},
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser.network',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
},
id: 'synthetics/browser-browser.screenshot-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
compiled_stream: {
processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }],
},
id: 'synthetics/browser-browser.network-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
compiled_stream: {
processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }],
},
},
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser.screenshot',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
},
},
],
},
],
is_managed: true,
revision: 1,
created_at: '2022-08-23T14:09:17.176Z',
created_by: 'system',
updated_at: '2022-08-23T14:09:17.176Z',
updated_by: 'system',
});
id: 'synthetics/browser-browser.screenshot-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
compiled_stream: {
processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }],
},
},
],
};
};
export const omitIds = (policy: PackagePolicy) => {
policy.inputs = sortBy(policy.inputs, 'type');
@ -358,7 +534,29 @@ export const omitIds = (policy: PackagePolicy) => {
};
export const comparePolicies = (aPolicy: PackagePolicy, bPolicy: PackagePolicy) => {
expect(omitIds(aPolicy)).eql(omitIds(bPolicy));
const a = omitIds(aPolicy);
const b = omitIds(bPolicy);
const aHttpInput = a.inputs?.find((input) => input.type === 'synthetics/http');
const aTcpInput = b.inputs?.find((input) => input.type === 'synthetics/tcp');
const aIcmpInput = b.inputs?.find((input) => input.type === 'synthetics/icmp');
const aBrowserInput = b.inputs?.find((input) => input.type === 'synthetics/browser');
const bHttpInput = b.inputs?.find((input) => input.type === 'synthetics/http');
const bTcpInput = b.inputs?.find((input) => input.type === 'synthetics/tcp');
const bIcmpInput = b.inputs?.find((input) => input.type === 'synthetics/icmp');
const bBrowserInput = b.inputs?.find((input) => input.type === 'synthetics/browser');
expect(aHttpInput).eql(bHttpInput);
expect(aTcpInput).eql(bTcpInput);
expect(aIcmpInput).eql(bIcmpInput);
expect(aBrowserInput).eql(bBrowserInput);
// delete inputs to compare rest of policy
delete a.inputs;
delete b.inputs;
expect(a).eql(b);
};
export const ignoreTestFields = [

View file

@ -13,6 +13,7 @@ export const getTestProjectSyntheticsPolicyLightweight = (
inputs = {},
configId,
id,
locationId,
projectId = 'test-suite',
locationName = 'Fleet Managed',
}: {
@ -21,12 +22,14 @@ export const getTestProjectSyntheticsPolicyLightweight = (
configId: string;
id: string;
projectId?: string;
locationId: string;
locationName?: string;
} = {
name: 'My Monitor 3',
inputs: {},
configId: '',
id: '',
locationId: 'fleet_managed',
locationName: 'Fleet Managed',
}
): PackagePolicy => ({
@ -34,7 +37,7 @@ export const getTestProjectSyntheticsPolicyLightweight = (
version: 'WzEzMDksMV0=',
name: `4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-Test private location 0`,
namespace: 'default',
package: { name: 'synthetics', title: 'Elastic Synthetics', version: '0.12.0' },
package: { name: 'synthetics', title: 'Elastic Synthetics', version: '1.0.1' },
enabled: true,
policy_id: '46034710-0ba6-11ed-ba04-5f123b9faa8b',
inputs: [
@ -111,6 +114,10 @@ export const getTestProjectSyntheticsPolicyLightweight = (
type: 'bool',
value: true,
},
location_id: {
type: 'text',
value: locationId ?? 'fleet_managed',
},
location_name: {
type: 'text',
value: 'Test private location 0',
@ -236,9 +243,10 @@ export const getTestProjectSyntheticsPolicyLightweight = (
tags: ['tag2', 'tag2'],
proxy_url: 'testGlobalParamOverwrite',
'run_from.geo.name': locationName ?? 'Test private location 0',
'run_from.id': locationName ?? 'Test private location 0',
'run_from.id': locationId ?? 'Test private location 0',
'response.include_headers': false,
'response.include_body': 'always',
'response.include_body_max_bytes': 900,
'ssl.supported_protocols': ['TLSv1.1', 'TLSv1.2', 'TLSv1.3'],
'ssl.verification_mode': 'strict',
'check.request.method': 'POST',
@ -304,6 +312,7 @@ export const getTestProjectSyntheticsPolicyLightweight = (
'ssl.key_passphrase': { type: 'text' },
'ssl.verification_mode': { type: 'text' },
'ssl.supported_protocols': { type: 'yaml' },
location_id: { value: 'fleet_managed', type: 'text' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
@ -341,6 +350,7 @@ export const getTestProjectSyntheticsPolicyLightweight = (
'service.name': { type: 'text' },
timeout: { type: 'text' },
tags: { type: 'yaml' },
location_id: { value: 'fleet_managed', type: 'text' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
@ -412,6 +422,7 @@ export const getTestProjectSyntheticsPolicyLightweight = (
'source.zip_url.ssl.verification_mode': { type: 'text' },
'source.zip_url.ssl.supported_protocols': { type: 'yaml' },
'source.zip_url.proxy_url': { type: 'text' },
location_id: { value: 'fleet_managed', type: 'text' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
@ -498,6 +509,7 @@ export const getTestProjectSyntheticsPolicy = (
configId,
id,
projectId = 'test-suite',
locationId,
locationName = 'Fleet Managed',
}: {
name?: string;
@ -506,11 +518,13 @@ export const getTestProjectSyntheticsPolicy = (
id: string;
projectId?: string;
locationName?: string;
locationId: string;
} = {
name: 'check if title is present-Test private location 0',
inputs: {},
configId: '',
id: '',
locationId: 'fleet_managed',
locationName: 'Fleet Managed',
}
): PackagePolicy => ({
@ -518,7 +532,7 @@ export const getTestProjectSyntheticsPolicy = (
version: 'WzEzMDksMV0=',
name: `4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-Test private location 0`,
namespace: 'default',
package: { name: 'synthetics', title: 'Elastic Synthetics', version: '0.12.0' },
package: { name: 'synthetics', title: 'Elastic Synthetics', version: '1.0.1' },
enabled: true,
policy_id: '46034710-0ba6-11ed-ba04-5f123b9faa8b',
inputs: [
@ -565,6 +579,7 @@ export const getTestProjectSyntheticsPolicy = (
'ssl.key_passphrase': { type: 'text' },
'ssl.verification_mode': { type: 'text' },
'ssl.supported_protocols': { type: 'yaml' },
location_id: { value: 'fleet_managed', type: 'text' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
@ -727,6 +742,7 @@ export const getTestProjectSyntheticsPolicy = (
'source.zip_url.ssl.supported_protocols': { type: 'yaml' },
'source.zip_url.proxy_url': { type: 'text' },
location_name: { value: 'Test private location 0', type: 'text' },
location_id: { value: 'fleet_managed', type: 'text' },
id: { value: id, type: 'text' },
config_id: { value: configId, type: 'text' },
run_once: { value: false, type: 'bool' },
@ -747,7 +763,7 @@ export const getTestProjectSyntheticsPolicy = (
enabled: true,
schedule: '@every 10m',
'run_from.geo.name': locationName,
'run_from.id': locationName,
'run_from.id': locationId,
timeout: null,
throttling: { download: 5, upload: 3, latency: 20 },
'source.project.content':

View file

@ -11,15 +11,31 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
import { KibanaSupertestProvider } from '../../../../../../test/api_integration/services/supertest';
export class PrivateLocationTestService {
private supertestAPI: ReturnType<typeof KibanaSupertestProvider>;
private supertest: ReturnType<typeof KibanaSupertestProvider>;
private readonly getService: FtrProviderContext['getService'];
constructor(getService: FtrProviderContext['getService']) {
this.supertestAPI = getService('supertest');
this.supertest = getService('supertest');
this.getService = getService;
}
async installSyntheticsPackage() {
await this.supertest.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
const response = await this.supertest
.get('/api/fleet/epm/packages/synthetics/1.0.1')
.set('kbn-xsrf', 'true')
.expect(200);
if (response.body.item.status !== 'installed') {
await this.supertest
.post('/api/fleet/epm/packages/synthetics/1.0.1')
.set('kbn-xsrf', 'true')
.send({ force: true })
.expect(200);
}
}
async addFleetPolicy(name: string) {
return this.supertestAPI
return this.supertest
.post('/api/fleet/agent_policies?sys_monitoring=true')
.set('kbn-xsrf', 'true')
.send({
@ -30,6 +46,7 @@ export class PrivateLocationTestService {
})
.expect(200);
}
async setTestLocations(testFleetPolicyIds: string[]) {
const server = this.getService('kibanaServer');

View file

@ -19,7 +19,6 @@ import { SavedObject } from '@kbn/core-saved-objects-server';
import { FtrProviderContext } from '../../ftr_provider_context';
import { getFixtureJson } from '../uptime/rest/helper/get_fixture_json';
import { PrivateLocationTestService } from './services/private_location_test_service';
import { getTestBrowserSyntheticsPolicy } from './sample_data/test_browser_policy';
import { comparePolicies, getTestSyntheticsPolicy } from './sample_data/test_policy';
export default function ({ getService }: FtrProviderContext) {
@ -42,12 +41,7 @@ export default function ({ getService }: FtrProviderContext) {
const params: Record<string, string> = {};
before(async () => {
await supertestAPI.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
await supertestAPI
.post('/api/fleet/epm/packages/synthetics/0.12.0')
.set('kbn-xsrf', 'true')
.send({ force: true })
.expect(200);
await testPrivateLocations.installSyntheticsPackage();
_browserMonitorJson = getFixtureJson('browser_monitor');
_httpMonitorJson = getFixtureJson('http_monitor');
@ -137,7 +131,12 @@ export default function ({ getService }: FtrProviderContext) {
comparePolicies(
packagePolicy,
getTestBrowserSyntheticsPolicy({ name: browserMonitorJson.name, id: newMonitorId })
getTestSyntheticsPolicy({
name: browserMonitorJson.name,
id: newMonitorId,
isBrowser: true,
location: { id: testFleetPolicyID },
})
);
});
@ -145,7 +144,7 @@ export default function ({ getService }: FtrProviderContext) {
const apiResponse = await supertestAPI
.post(SYNTHETICS_API_URLS.PARAMS)
.set('kbn-xsrf', 'true')
.send({ key: 'test', value: 'test' });
.send({ key: 'test', value: 'http://proxy.com' });
expect(apiResponse.status).eql(200);
});
@ -154,7 +153,7 @@ export default function ({ getService }: FtrProviderContext) {
const apiResponse = await supertestAPI
.get(SYNTHETICS_API_URLS.PARAMS)
.set('kbn-xsrf', 'true')
.send({ key: 'test', value: 'test' });
.send({ key: 'test', value: 'http://proxy.com' });
expect(apiResponse.status).eql(200);
@ -186,7 +185,13 @@ export default function ({ getService }: FtrProviderContext) {
comparePolicies(
packagePolicy,
getTestBrowserSyntheticsPolicy({ name: browserMonitorJson.name, id: newMonitorId, params })
getTestSyntheticsPolicy({
name: browserMonitorJson.name,
id: newMonitorId,
params,
isBrowser: true,
location: { id: testFleetPolicyID },
})
);
});
@ -231,14 +236,13 @@ export default function ({ getService }: FtrProviderContext) {
expect(packagePolicy.policy_id).eql(testFleetPolicyID);
const pPolicy = getTestSyntheticsPolicy(
httpMonitorJson.name,
newHttpMonitorId,
undefined,
undefined,
false,
'test'
);
const pPolicy = getTestSyntheticsPolicy({
name: httpMonitorJson.name,
id: newHttpMonitorId,
isTLSEnabled: false,
namespace: 'testnamespace',
location: { id: testFleetPolicyID },
});
comparePolicies(packagePolicy, pPolicy);
});
@ -289,7 +293,12 @@ export default function ({ getService }: FtrProviderContext) {
comparePolicies(
packagePolicy,
getTestBrowserSyntheticsPolicy({ name: browserMonitorJson.name, id: newMonitorId })
getTestSyntheticsPolicy({
name: browserMonitorJson.name,
id: newMonitorId,
isBrowser: true,
location: { id: testFleetPolicyID },
})
);
});
});