mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Synthetics] Remove excess tests and adjust deployment agnostic tests for additional coverage (#206508)
## Summary Remove overlapping Synthetics tests from the `api_integration` folder. Tests are kept in the original directory if one of the following is true A.) They haven't yet been moved to the deployment agnostic B.) They create custom users and roles (this provides some coverage for real stateful privileges, which the deployment agnostic directory mocks with api keys), C.) They deal directly with api key privileges D.) They would fail entirely in deployment agnostic (for example, params which fails in serverless, both MKI and local serverless). Additionally, some files in the `deployment_agnostic` folder were split in order to provide some level of coverage for public locations. Files which contain coverage for public locations are skipped in cloud and MKI, as they would fail there due to not having the mock location available. --------- Co-authored-by: Shahzad <shahzad31comp@gmail.com>
This commit is contained in:
parent
aaf73ff5f6
commit
93c2bd5175
29 changed files with 2613 additions and 7276 deletions
|
@ -5,22 +5,14 @@
|
|||
* 2.0.
|
||||
*/
|
||||
import expect from '@kbn/expect';
|
||||
import epct from 'expect';
|
||||
import moment from 'moment/moment';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { omit, omitBy } from 'lodash';
|
||||
import {
|
||||
ConfigKey,
|
||||
MonitorTypeEnum,
|
||||
HTTPFields,
|
||||
} from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { formatKibanaNamespace } from '@kbn/synthetics-plugin/common/formatters';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import { DEFAULT_FIELDS } from '@kbn/synthetics-plugin/common/constants/monitor_defaults';
|
||||
import { ALL_SPACES_ID } from '@kbn/security-plugin/common/constants';
|
||||
import { format as formatUrl } from 'url';
|
||||
|
||||
import supertest from 'supertest';
|
||||
import { HTTPFields } from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import { ALL_SPACES_ID } from '@kbn/security-plugin/common/constants';
|
||||
import { getServiceApiKeyPrivileges } from '@kbn/synthetics-plugin/server/synthetics_service/get_api_key';
|
||||
import { syntheticsMonitorType } from '@kbn/synthetics-plugin/common/types/saved_objects';
|
||||
import {
|
||||
|
@ -29,7 +21,6 @@ import {
|
|||
} from '@kbn/synthetics-plugin/server/routes/monitor_cruds/formatters/saved_object_to_monitor';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helper/get_fixture_json';
|
||||
import { SyntheticsMonitorTestService } from './services/synthetics_monitor_test_service';
|
||||
|
||||
export const addMonitorAPIHelper = async (supertestAPI: any, monitor: any, statusCode = 200) => {
|
||||
const result = await supertestAPI
|
||||
|
@ -75,23 +66,10 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
const supertestWithoutAuth = getService('supertestWithoutAuth');
|
||||
const security = getService('security');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
const monitorTestService = new SyntheticsMonitorTestService(getService);
|
||||
|
||||
let _httpMonitorJson: HTTPFields;
|
||||
let httpMonitorJson: HTTPFields;
|
||||
|
||||
const addMonitorAPI = async (monitor: any, statusCode = 200) => {
|
||||
return addMonitorAPIHelper(supertestAPI, monitor, statusCode);
|
||||
};
|
||||
|
||||
const deleteMonitor = async (
|
||||
monitorId?: string | string[],
|
||||
statusCode = 200,
|
||||
spaceId?: string
|
||||
) => {
|
||||
return monitorTestService.deleteMonitor(monitorId, statusCode, spaceId);
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
_httpMonitorJson = getFixtureJson('http_monitor');
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
|
@ -101,125 +79,6 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
httpMonitorJson = _httpMonitorJson;
|
||||
});
|
||||
|
||||
it('returns the newly added monitor', async () => {
|
||||
const newMonitor = httpMonitorJson;
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
expect(apiResponse).eql(omitMonitorKeys(newMonitor));
|
||||
});
|
||||
|
||||
it('returns bad request if payload is invalid for HTTP monitor', async () => {
|
||||
// Delete a required property to make payload invalid
|
||||
const newMonitor = { ...httpMonitorJson, 'check.request.headers': null };
|
||||
await addMonitorAPI(newMonitor, 400);
|
||||
});
|
||||
|
||||
it('returns bad request if monitor type is invalid', async () => {
|
||||
const newMonitor = { ...httpMonitorJson, type: 'invalid-data-steam' };
|
||||
|
||||
const apiResponse = await addMonitorAPI(newMonitor, 400);
|
||||
|
||||
expect(apiResponse.message).eql('Invalid value "invalid-data-steam" supplied to "type"');
|
||||
});
|
||||
const localLoc = {
|
||||
id: 'dev',
|
||||
label: 'Dev Service',
|
||||
geo: {
|
||||
lat: 0,
|
||||
lon: 0,
|
||||
},
|
||||
isServiceManaged: true,
|
||||
};
|
||||
|
||||
it('can create valid monitors without all defaults', async () => {
|
||||
// Delete a required property to make payload invalid
|
||||
const newMonitor = {
|
||||
name: 'Sample name',
|
||||
type: 'http',
|
||||
urls: 'https://elastic.co',
|
||||
locations: [localLoc],
|
||||
};
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
expect(apiResponse).eql(
|
||||
omitMonitorKeys({
|
||||
...DEFAULT_FIELDS[MonitorTypeEnum.HTTP],
|
||||
...newMonitor,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('can disable retries', async () => {
|
||||
const maxAttempts = 1;
|
||||
const newMonitor = {
|
||||
max_attempts: maxAttempts,
|
||||
urls: 'https://elastic.co',
|
||||
name: `Sample name ${uuidv4()}`,
|
||||
type: 'http',
|
||||
locations: [localLoc],
|
||||
};
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
epct(apiResponse).toEqual(epct.objectContaining({ retest_on_failure: false }));
|
||||
});
|
||||
|
||||
it('can enable retries with max attempts', async () => {
|
||||
const maxAttempts = 2;
|
||||
const newMonitor = {
|
||||
max_attempts: maxAttempts,
|
||||
urls: 'https://elastic.co',
|
||||
name: `Sample name ${uuidv4()}`,
|
||||
type: 'http',
|
||||
locations: [localLoc],
|
||||
};
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
epct(apiResponse).toEqual(epct.objectContaining({ retest_on_failure: true }));
|
||||
});
|
||||
|
||||
it('can enable retries', async () => {
|
||||
const newMonitor = {
|
||||
retest_on_failure: false,
|
||||
urls: 'https://elastic.co',
|
||||
name: `Sample name ${uuidv4()}`,
|
||||
type: 'http',
|
||||
locations: [localLoc],
|
||||
};
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
epct(apiResponse).toEqual(epct.objectContaining({ retest_on_failure: false }));
|
||||
});
|
||||
|
||||
it('cannot create a invalid monitor without a monitor type', async () => {
|
||||
// Delete a required property to make payload invalid
|
||||
const newMonitor = {
|
||||
name: 'Sample name',
|
||||
url: 'https://elastic.co',
|
||||
locations: [localLoc],
|
||||
};
|
||||
await addMonitorAPI(newMonitor, 400);
|
||||
});
|
||||
|
||||
it('omits 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: [localLoc],
|
||||
};
|
||||
const apiResponse = await addMonitorAPI(newMonitor, 400);
|
||||
expect(apiResponse.message).not.to.have.keys(
|
||||
'Invalid monitor key(s) for http type: unknownKey","attributes":{"details":"Invalid monitor key(s) for http type: unknownKey'
|
||||
);
|
||||
});
|
||||
|
||||
it('can create monitor with API key with proper permissions', async () => {
|
||||
const response: Record<string, any> = await supertestAPI
|
||||
.post('/internal/security/api_key')
|
||||
|
@ -376,75 +235,5 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
await security.role.delete(roleName);
|
||||
}
|
||||
});
|
||||
|
||||
it('sets namespace to Kibana space when not set to a custom namespace', async () => {
|
||||
const SPACE_ID = `test-space-${uuidv4()}`;
|
||||
const SPACE_NAME = `test-space-name ${uuidv4()}`;
|
||||
const EXPECTED_NAMESPACE = formatKibanaNamespace(SPACE_ID);
|
||||
const monitor = {
|
||||
...httpMonitorJson,
|
||||
[ConfigKey.NAMESPACE]: 'default',
|
||||
};
|
||||
let monitorId = '';
|
||||
|
||||
try {
|
||||
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
|
||||
|
||||
const apiResponse = await supertestAPI
|
||||
.post(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(monitor)
|
||||
.expect(200);
|
||||
monitorId = apiResponse.body.id;
|
||||
expect(apiResponse.body[ConfigKey.NAMESPACE]).eql(EXPECTED_NAMESPACE);
|
||||
} finally {
|
||||
await deleteMonitor(monitorId, 200, SPACE_ID);
|
||||
}
|
||||
});
|
||||
|
||||
it('preserves the passed namespace when preserve_namespace is passed', async () => {
|
||||
const SPACE_ID = `test-space-${uuidv4()}`;
|
||||
const SPACE_NAME = `test-space-name ${uuidv4()}`;
|
||||
const monitor = {
|
||||
...httpMonitorJson,
|
||||
[ConfigKey.NAMESPACE]: 'default',
|
||||
};
|
||||
let monitorId = '';
|
||||
|
||||
try {
|
||||
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
|
||||
const apiResponse = await supertestAPI
|
||||
.post(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
|
||||
.query({ preserve_namespace: true })
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(monitor)
|
||||
.expect(200);
|
||||
monitorId = apiResponse.body.id;
|
||||
expect(apiResponse.body[ConfigKey.NAMESPACE]).eql('default');
|
||||
} finally {
|
||||
await deleteMonitor(monitorId, 200, SPACE_ID);
|
||||
}
|
||||
});
|
||||
|
||||
it('sets namespace to custom namespace when set', async () => {
|
||||
const SPACE_ID = `test-space-${uuidv4()}`;
|
||||
const SPACE_NAME = `test-space-name ${uuidv4()}`;
|
||||
const monitor = httpMonitorJson;
|
||||
let monitorId = '';
|
||||
|
||||
try {
|
||||
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
|
||||
|
||||
const apiResponse = await supertestAPI
|
||||
.post(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(monitor)
|
||||
.expect(200);
|
||||
monitorId = apiResponse.body.id;
|
||||
expect(apiResponse.body[ConfigKey.NAMESPACE]).eql(monitor[ConfigKey.NAMESPACE]);
|
||||
} finally {
|
||||
await deleteMonitor(monitorId, 200, SPACE_ID);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
import moment from 'moment';
|
||||
import semver from 'semver';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import {
|
||||
ConfigKey,
|
||||
|
@ -22,11 +21,8 @@ import { getDevLocation } from '@kbn/synthetics-plugin/server/synthetics_service
|
|||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helper/get_fixture_json';
|
||||
import { comparePolicies, getTestSyntheticsPolicy } from './sample_data/test_policy';
|
||||
import {
|
||||
INSTALLED_VERSION,
|
||||
PrivateLocationTestService,
|
||||
} from './services/private_location_test_service';
|
||||
import { addMonitorAPIHelper, keyToOmitList, omitMonitorKeys } from './add_monitor';
|
||||
import { PrivateLocationTestService } from './services/private_location_test_service';
|
||||
import { keyToOmitList, omitMonitorKeys } from './add_monitor';
|
||||
import { SyntheticsMonitorTestService } from './services/synthetics_monitor_test_service';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
|
@ -38,7 +34,6 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
|
||||
let testFleetPolicyID: string;
|
||||
let pvtLoc: PrivateLocation;
|
||||
const testPolicyName = 'Fleet test server policy' + Date.now();
|
||||
|
||||
let _httpMonitorJson: HTTPFields;
|
||||
let httpMonitorJson: HTTPFields;
|
||||
|
@ -46,18 +41,6 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
const testPrivateLocations = new PrivateLocationTestService(getService);
|
||||
const security = getService('security');
|
||||
|
||||
const addMonitorAPI = async (monitor: any, statusCode = 200) => {
|
||||
return addMonitorAPIHelper(supertestAPI, monitor, statusCode);
|
||||
};
|
||||
|
||||
const deleteMonitor = async (
|
||||
monitorId?: string | string[],
|
||||
statusCode = 200,
|
||||
spaceId?: string
|
||||
) => {
|
||||
return monitorTestService.deleteMonitor(monitorId, statusCode, spaceId);
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
await testPrivateLocations.installSyntheticsPackage();
|
||||
|
@ -83,205 +66,6 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
expect(apiResponse.body.locations).eql(testResponse);
|
||||
});
|
||||
|
||||
it('does not add a monitor if there is an error in creating integration', async () => {
|
||||
const newMonitor = { ...httpMonitorJson };
|
||||
const invalidName = 'invalid name';
|
||||
|
||||
const location = {
|
||||
id: 'invalidLocation',
|
||||
label: 'Test private location 0',
|
||||
isServiceManaged: false,
|
||||
geo: {
|
||||
lat: 0,
|
||||
lon: 0,
|
||||
},
|
||||
};
|
||||
|
||||
newMonitor.name = invalidName;
|
||||
|
||||
const apiResponse = await supertestAPI
|
||||
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ ...newMonitor, locations: [location] });
|
||||
|
||||
expect(apiResponse.status).eql(400);
|
||||
|
||||
expect(apiResponse.body).eql({
|
||||
statusCode: 400,
|
||||
error: 'Bad Request',
|
||||
message: `Invalid locations specified. Private Location(s) 'invalidLocation' not found. Available private locations are 'Test private location 0'`,
|
||||
});
|
||||
|
||||
const apiGetResponse = await supertestAPI
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + `?query="${invalidName}"`)
|
||||
.expect(200);
|
||||
// verify that no monitor was added
|
||||
expect(apiGetResponse.body.monitors?.length).eql(0);
|
||||
});
|
||||
|
||||
let newMonitorId: string;
|
||||
|
||||
it('adds a monitor in private location', async () => {
|
||||
const newMonitor = httpMonitorJson;
|
||||
|
||||
newMonitor.locations.push(omit(pvtLoc, ['spaces']));
|
||||
|
||||
const { body, rawBody } = await addMonitorAPI(newMonitor);
|
||||
|
||||
expect(body).eql(omitMonitorKeys(newMonitor));
|
||||
newMonitorId = rawBody.id;
|
||||
});
|
||||
|
||||
it('added an integration for previously added monitor', async () => {
|
||||
const apiResponse = await supertestAPI.get(
|
||||
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
|
||||
);
|
||||
|
||||
const packagePolicy = apiResponse.body.items.find(
|
||||
(pkgPolicy: PackagePolicy) => pkgPolicy.id === newMonitorId + '-' + pvtLoc.id + '-default'
|
||||
);
|
||||
|
||||
expect(packagePolicy?.policy_id).eql(testFleetPolicyID);
|
||||
|
||||
comparePolicies(
|
||||
packagePolicy,
|
||||
getTestSyntheticsPolicy({
|
||||
name: httpMonitorJson.name,
|
||||
id: newMonitorId,
|
||||
location: { id: pvtLoc.id },
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
let testFleetPolicyID2: string;
|
||||
let pvtLoc2: PrivateLocation;
|
||||
|
||||
it('edits a monitor with additional private location', async () => {
|
||||
const resPolicy = await testPrivateLocations.addFleetPolicy(testPolicyName + 1);
|
||||
testFleetPolicyID2 = resPolicy.body.item.id;
|
||||
|
||||
pvtLoc2 = await testPrivateLocations.addPrivateLocation({
|
||||
policyId: testFleetPolicyID2,
|
||||
label: 'Test private location 1',
|
||||
});
|
||||
|
||||
httpMonitorJson.locations.push({
|
||||
id: pvtLoc2.id,
|
||||
label: pvtLoc2.label,
|
||||
isServiceManaged: false,
|
||||
agentPolicyId: pvtLoc2.agentPolicyId,
|
||||
geo: {
|
||||
lat: 0,
|
||||
lon: 0,
|
||||
},
|
||||
});
|
||||
|
||||
const apiResponse = await supertestAPI
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + newMonitorId)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(httpMonitorJson);
|
||||
|
||||
const { created_at: createdAt, updated_at: updatedAt } = apiResponse.body;
|
||||
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);
|
||||
|
||||
expect(omit(apiResponse.body, keyToOmitList)).eql(
|
||||
omitMonitorKeys({
|
||||
...omit(httpMonitorJson, ['urls']),
|
||||
url: httpMonitorJson.urls,
|
||||
updated_at: updatedAt,
|
||||
revision: 2,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('added an integration for second location in edit monitor', async () => {
|
||||
const apiResponsePolicy = await supertestAPI.get(
|
||||
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
|
||||
);
|
||||
|
||||
let packagePolicy = apiResponsePolicy.body.items.find(
|
||||
(pkgPolicy: PackagePolicy) => pkgPolicy.id === newMonitorId + '-' + pvtLoc.id + '-default'
|
||||
);
|
||||
|
||||
expect(packagePolicy.policy_id).eql(testFleetPolicyID);
|
||||
|
||||
comparePolicies(
|
||||
packagePolicy,
|
||||
getTestSyntheticsPolicy({
|
||||
name: httpMonitorJson.name,
|
||||
id: newMonitorId,
|
||||
location: { id: pvtLoc.id },
|
||||
})
|
||||
);
|
||||
|
||||
packagePolicy = apiResponsePolicy.body.items.find(
|
||||
(pkgPolicy: PackagePolicy) => pkgPolicy.id === newMonitorId + '-' + pvtLoc2.id + '-default'
|
||||
);
|
||||
|
||||
expect(packagePolicy.policy_id).eql(testFleetPolicyID2);
|
||||
comparePolicies(
|
||||
packagePolicy,
|
||||
getTestSyntheticsPolicy({
|
||||
name: httpMonitorJson.name,
|
||||
id: newMonitorId,
|
||||
location: {
|
||||
name: 'Test private location 1',
|
||||
id: pvtLoc2.id,
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('deletes integration for a removed location from monitor', async () => {
|
||||
httpMonitorJson.locations = httpMonitorJson.locations.filter(({ id }) => id !== pvtLoc2.id);
|
||||
|
||||
await supertestAPI
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + newMonitorId + '?internal=true')
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(httpMonitorJson)
|
||||
.expect(200);
|
||||
|
||||
const apiResponsePolicy = await supertestAPI.get(
|
||||
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
|
||||
);
|
||||
|
||||
let packagePolicy = apiResponsePolicy.body.items.find(
|
||||
(pkgPolicy: PackagePolicy) => pkgPolicy.id === newMonitorId + '-' + pvtLoc.id + '-default'
|
||||
);
|
||||
|
||||
expect(packagePolicy.policy_id).eql(testFleetPolicyID);
|
||||
|
||||
comparePolicies(
|
||||
packagePolicy,
|
||||
getTestSyntheticsPolicy({
|
||||
name: httpMonitorJson.name,
|
||||
id: newMonitorId,
|
||||
location: { id: pvtLoc.id },
|
||||
})
|
||||
);
|
||||
|
||||
packagePolicy = apiResponsePolicy.body.items.find(
|
||||
(pkgPolicy: PackagePolicy) => pkgPolicy.id === newMonitorId + '-' + pvtLoc2.id + '-default'
|
||||
);
|
||||
|
||||
expect(packagePolicy).eql(undefined);
|
||||
});
|
||||
|
||||
it('deletes integration for a deleted monitor', async () => {
|
||||
await deleteMonitor(newMonitorId);
|
||||
|
||||
const apiResponsePolicy = await supertestAPI.get(
|
||||
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
|
||||
);
|
||||
|
||||
const packagePolicy = apiResponsePolicy.body.items.find(
|
||||
(pkgPolicy: PackagePolicy) =>
|
||||
pkgPolicy.id === newMonitorId + '-' + testFleetPolicyID + '-default'
|
||||
);
|
||||
|
||||
expect(packagePolicy).eql(undefined);
|
||||
});
|
||||
|
||||
it('handles spaces', async () => {
|
||||
const { username, password, SPACE_ID, roleName } = await monitorTestService.addsNewSpace();
|
||||
|
||||
|
@ -345,146 +129,5 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
await security.role.delete(roleName);
|
||||
}
|
||||
});
|
||||
|
||||
it('handles is_tls_enabled true', async () => {
|
||||
let monitorId = '';
|
||||
|
||||
const monitor = {
|
||||
...httpMonitorJson,
|
||||
locations: [
|
||||
{
|
||||
id: pvtLoc.id,
|
||||
label: 'Test private location 0',
|
||||
isServiceManaged: false,
|
||||
},
|
||||
],
|
||||
[ConfigKey.METADATA]: {
|
||||
is_tls_enabled: true,
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
const apiResponse = await supertestAPI
|
||||
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(monitor)
|
||||
.expect(200);
|
||||
|
||||
monitorId = apiResponse.body.id;
|
||||
|
||||
const policyResponse = await supertestAPI.get(
|
||||
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
|
||||
);
|
||||
|
||||
const packagePolicy = policyResponse.body.items.find(
|
||||
(pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorId + '-' + pvtLoc.id + `-default`
|
||||
);
|
||||
comparePolicies(
|
||||
packagePolicy,
|
||||
getTestSyntheticsPolicy({
|
||||
name: monitor.name,
|
||||
id: monitorId,
|
||||
location: { id: pvtLoc.id },
|
||||
isTLSEnabled: true,
|
||||
})
|
||||
);
|
||||
} finally {
|
||||
await deleteMonitor(monitorId);
|
||||
}
|
||||
});
|
||||
|
||||
it('handles is_tls_enabled false', async () => {
|
||||
let monitorId = '';
|
||||
|
||||
const monitor = {
|
||||
...httpMonitorJson,
|
||||
locations: [
|
||||
{
|
||||
id: pvtLoc.id,
|
||||
label: 'Test private location 0',
|
||||
isServiceManaged: false,
|
||||
},
|
||||
],
|
||||
[ConfigKey.METADATA]: {
|
||||
is_tls_enabled: false,
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
const apiResponse = await supertestAPI
|
||||
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(monitor);
|
||||
|
||||
expect(apiResponse.status).eql(200, JSON.stringify(apiResponse.body));
|
||||
|
||||
monitorId = apiResponse.body.id;
|
||||
|
||||
const policyResponse = await supertestAPI.get(
|
||||
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
|
||||
);
|
||||
|
||||
const packagePolicy = policyResponse.body.items.find(
|
||||
(pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorId + '-' + pvtLoc.id + `-default`
|
||||
);
|
||||
comparePolicies(
|
||||
packagePolicy,
|
||||
getTestSyntheticsPolicy({
|
||||
name: monitor.name,
|
||||
id: monitorId,
|
||||
location: { id: pvtLoc.id },
|
||||
})
|
||||
);
|
||||
} finally {
|
||||
await deleteMonitor(monitorId);
|
||||
}
|
||||
});
|
||||
|
||||
it('handles auto upgrading policies', async () => {
|
||||
let monitorId = '';
|
||||
|
||||
const monitor = {
|
||||
...httpMonitorJson,
|
||||
name: `Test monitor ${uuidv4()}`,
|
||||
[ConfigKey.NAMESPACE]: 'default',
|
||||
locations: [
|
||||
{
|
||||
id: pvtLoc.id,
|
||||
label: 'Test private location 0',
|
||||
isServiceManaged: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
try {
|
||||
const apiResponse = await supertestAPI
|
||||
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(monitor)
|
||||
.expect(200);
|
||||
monitorId = apiResponse.body.id;
|
||||
|
||||
const policyResponse = await supertestAPI.get(
|
||||
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
|
||||
);
|
||||
|
||||
const packagePolicy = policyResponse.body.items.find(
|
||||
(pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorId + '-' + pvtLoc.id + `-default`
|
||||
);
|
||||
|
||||
expect(packagePolicy.package.version).eql(INSTALLED_VERSION);
|
||||
|
||||
await supertestAPI.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
|
||||
const policyResponseAfterUpgrade = await supertestAPI.get(
|
||||
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
|
||||
);
|
||||
const packagePolicyAfterUpgrade = policyResponseAfterUpgrade.body.items.find(
|
||||
(pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorId + '-' + pvtLoc.id + `-default`
|
||||
);
|
||||
expect(semver.gte(packagePolicyAfterUpgrade.package.version, INSTALLED_VERSION)).eql(true);
|
||||
} finally {
|
||||
await deleteMonitor(monitorId);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,128 +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 { v4 as uuidv4 } from 'uuid';
|
||||
import expect from '@kbn/expect';
|
||||
import { ProjectMonitorsRequest } from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helper/get_fixture_json';
|
||||
import { PrivateLocationTestService } from './services/private_location_test_service';
|
||||
import { SyntheticsMonitorTestService } from './services/synthetics_monitor_test_service';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
// FLAKY: https://github.com/elastic/kibana/issues/160277
|
||||
describe.skip('AddProjectMonitorsPrivateLocations', function () {
|
||||
this.tags('skipCloud');
|
||||
|
||||
const supertest = getService('supertest');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
|
||||
let projectMonitors: ProjectMonitorsRequest;
|
||||
|
||||
const monitorTestService = new SyntheticsMonitorTestService(getService);
|
||||
const testPrivateLocations = new PrivateLocationTestService(getService);
|
||||
|
||||
const setUniqueIds = (request: ProjectMonitorsRequest) => {
|
||||
return {
|
||||
...request,
|
||||
monitors: request.monitors.map((monitor) => ({ ...monitor, id: uuidv4() })),
|
||||
};
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_ENABLEMENT)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
await testPrivateLocations.installSyntheticsPackage();
|
||||
await testPrivateLocations.addPrivateLocation();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
projectMonitors = setUniqueIds({
|
||||
monitors: getFixtureJson('project_browser_monitor').monitors,
|
||||
});
|
||||
});
|
||||
|
||||
it('project monitors - returns a failed monitor when creating integration fails', async () => {
|
||||
const project = `test-project-${uuidv4()}`;
|
||||
|
||||
const secondMonitor = {
|
||||
...projectMonitors.monitors[0],
|
||||
id: 'test-id-2',
|
||||
privateLocations: ['Test private location 7'],
|
||||
};
|
||||
const testMonitors = [
|
||||
projectMonitors.monitors[0],
|
||||
{
|
||||
...secondMonitor,
|
||||
name: '!@#$%^&*()_++[\\-\\]- wow name',
|
||||
},
|
||||
];
|
||||
try {
|
||||
const { body, status } = await monitorTestService.addProjectMonitors(project, testMonitors);
|
||||
expect(status).eql(200);
|
||||
expect(body.createdMonitors.length).eql(1);
|
||||
expect(body.failedMonitors[0].reason).eql(
|
||||
"Couldn't save or update monitor because of an invalid configuration."
|
||||
);
|
||||
} finally {
|
||||
await Promise.all([
|
||||
testMonitors.map((monitor) => {
|
||||
return monitorTestService.deleteMonitorByJourney(projectMonitors, monitor.id, project);
|
||||
}),
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
it('project monitors - returns a failed monitor when editing integration fails', async () => {
|
||||
const project = `test-project-${uuidv4()}`;
|
||||
|
||||
const secondMonitor = {
|
||||
...projectMonitors.monitors[0],
|
||||
id: 'test-id-2',
|
||||
privateLocations: ['Test private location 0'],
|
||||
};
|
||||
const testMonitors = [projectMonitors.monitors[0], secondMonitor];
|
||||
const { body, status: status0 } = await monitorTestService.addProjectMonitors(
|
||||
project,
|
||||
testMonitors
|
||||
);
|
||||
expect(status0).eql(200);
|
||||
|
||||
expect(body.createdMonitors.length).eql(2);
|
||||
const { body: editedBody, status: editedStatus } =
|
||||
await monitorTestService.addProjectMonitors(project, testMonitors);
|
||||
expect(editedStatus).eql(200);
|
||||
|
||||
expect(editedBody.createdMonitors.length).eql(0);
|
||||
expect(editedBody.updatedMonitors.length).eql(2);
|
||||
|
||||
testMonitors[1].name = '!@#$%^&*()_++[\\-\\]- wow name';
|
||||
testMonitors[1].privateLocations = ['Test private location 8'];
|
||||
|
||||
const { body: editedBodyError, status } = await monitorTestService.addProjectMonitors(
|
||||
project,
|
||||
testMonitors
|
||||
);
|
||||
expect(status).eql(200);
|
||||
expect(editedBodyError.createdMonitors.length).eql(0);
|
||||
expect(editedBodyError.updatedMonitors.length).eql(1);
|
||||
expect(editedBodyError.failedMonitors.length).eql(1);
|
||||
expect(editedBodyError.failedMonitors[0].details).eql(
|
||||
`Invalid locations specified. Private Location(s) 'Test private location 8' not found. Available private locations are 'Test private location 0'`
|
||||
);
|
||||
expect(editedBodyError.failedMonitors[0].reason).eql(
|
||||
"Couldn't save or update monitor because of an invalid configuration."
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,230 +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 { v4 as uuidv4 } from 'uuid';
|
||||
import {
|
||||
EncryptedSyntheticsSavedMonitor,
|
||||
HTTPFields,
|
||||
MonitorFields,
|
||||
} from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import expect from '@kbn/expect';
|
||||
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common';
|
||||
import { syntheticsMonitorType } from '@kbn/synthetics-plugin/common/types/saved_objects';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helper/get_fixture_json';
|
||||
import { PrivateLocationTestService } from './services/private_location_test_service';
|
||||
import { SyntheticsMonitorTestService } from './services/synthetics_monitor_test_service';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
describe('DeleteMonitorRoute', function () {
|
||||
this.tags('skipCloud');
|
||||
|
||||
const supertest = getService('supertest');
|
||||
const supertestWithoutAuth = getService('supertestWithoutAuth');
|
||||
const security = getService('security');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
|
||||
const testPrivateLocations = new PrivateLocationTestService(getService);
|
||||
const monitorTestService = new SyntheticsMonitorTestService(getService);
|
||||
|
||||
let _httpMonitorJson: HTTPFields;
|
||||
let httpMonitorJson: HTTPFields;
|
||||
let testPolicyId = '';
|
||||
|
||||
const saveMonitor = async (
|
||||
monitor: MonitorFields
|
||||
): Promise<EncryptedSyntheticsSavedMonitor> => {
|
||||
const res = await supertest
|
||||
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(monitor);
|
||||
|
||||
expect(res.status).to.eql(200, JSON.stringify(res.body));
|
||||
|
||||
return res.body;
|
||||
};
|
||||
|
||||
const deleteMonitor = async (monitorId?: string | string[], statusCode = 200) => {
|
||||
return monitorTestService.deleteMonitor(monitorId, statusCode);
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
_httpMonitorJson = getFixtureJson('http_monitor');
|
||||
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
|
||||
await testPrivateLocations.installSyntheticsPackage();
|
||||
|
||||
const loc = await testPrivateLocations.addPrivateLocation();
|
||||
testPolicyId = loc.id;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
httpMonitorJson = _httpMonitorJson;
|
||||
});
|
||||
|
||||
it('deletes monitor by id', async () => {
|
||||
const { id: monitorId } = await saveMonitor(httpMonitorJson as MonitorFields);
|
||||
|
||||
const deleteResponse = await deleteMonitor(monitorId);
|
||||
|
||||
expect(deleteResponse.body).eql([{ id: monitorId, deleted: true }]);
|
||||
|
||||
// Hit get endpoint and expect 404 as well
|
||||
await supertest.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + monitorId).expect(404);
|
||||
});
|
||||
|
||||
it('deletes monitor by param id', async () => {
|
||||
const { id: monitorId } = await saveMonitor(httpMonitorJson as MonitorFields);
|
||||
|
||||
const deleteResponse = await monitorTestService.deleteMonitorByIdParam(monitorId, 200);
|
||||
|
||||
expect(deleteResponse.body).eql([{ id: monitorId, deleted: true }]);
|
||||
|
||||
// Hit get endpoint and expect 404 as well
|
||||
await supertest.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + monitorId).expect(404);
|
||||
});
|
||||
|
||||
it('throws error if both body and param are missing', async () => {
|
||||
const deleteResponse = await supertest
|
||||
.delete(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.send()
|
||||
.set('kbn-xsrf', 'true');
|
||||
expect(deleteResponse.status).to.eql(400);
|
||||
});
|
||||
|
||||
it('deletes multiple monitors by id', async () => {
|
||||
const { id: monitorId } = await saveMonitor(httpMonitorJson as MonitorFields);
|
||||
const { id: monitorId2 } = await saveMonitor({
|
||||
...httpMonitorJson,
|
||||
name: 'another -2',
|
||||
} as MonitorFields);
|
||||
|
||||
const deleteResponse = await deleteMonitor([monitorId2, monitorId]);
|
||||
|
||||
expect(
|
||||
deleteResponse.body.sort((a: { id: string }, b: { id: string }) => (a.id > b.id ? 1 : -1))
|
||||
).eql(
|
||||
[
|
||||
{ id: monitorId2, deleted: true },
|
||||
{ id: monitorId, deleted: true },
|
||||
].sort((a, b) => (a.id > b.id ? 1 : -1))
|
||||
);
|
||||
|
||||
// Hit get endpoint and expect 404 as well
|
||||
await supertest.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + monitorId).expect(404);
|
||||
});
|
||||
|
||||
it('deletes multiple monitors by bulk delete', async () => {
|
||||
const { id: monitorId } = await saveMonitor(httpMonitorJson as MonitorFields);
|
||||
const { id: monitorId2 } = await saveMonitor({
|
||||
...httpMonitorJson,
|
||||
name: 'another -2',
|
||||
} as MonitorFields);
|
||||
|
||||
const deleteResponse = await monitorTestService.deleteMonitorBulk(
|
||||
[monitorId2, monitorId],
|
||||
200
|
||||
);
|
||||
|
||||
expect(
|
||||
deleteResponse.body.result.sort((a: { id: string }, b: { id: string }) =>
|
||||
a.id > b.id ? 1 : -1
|
||||
)
|
||||
).eql(
|
||||
[
|
||||
{ id: monitorId2, deleted: true },
|
||||
{ id: monitorId, deleted: true },
|
||||
].sort((a, b) => (a.id > b.id ? 1 : -1))
|
||||
);
|
||||
|
||||
// Hit get endpoint and expect 404 as well
|
||||
await supertest.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + monitorId).expect(404);
|
||||
});
|
||||
|
||||
it('returns 404 if monitor id is not found', async () => {
|
||||
const invalidMonitorId = 'invalid-id';
|
||||
const expected404Message = `Monitor id ${invalidMonitorId} not found!`;
|
||||
|
||||
const deleteResponse = await deleteMonitor(invalidMonitorId);
|
||||
|
||||
expect(deleteResponse.status).eql(200);
|
||||
expect(deleteResponse.body).eql([
|
||||
{
|
||||
id: invalidMonitorId,
|
||||
deleted: false,
|
||||
error: expected404Message,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('validates empty monitor id', async () => {
|
||||
await deleteMonitor(undefined, 400);
|
||||
await deleteMonitor([], 400);
|
||||
});
|
||||
|
||||
it.skip('handles private location errors and does not delete the monitor if integration policy is unable to be deleted', async () => {
|
||||
const name = `Monitor with a private location ${uuidv4()}`;
|
||||
const newMonitor = {
|
||||
name,
|
||||
type: 'http',
|
||||
urls: 'https://elastic.co',
|
||||
locations: [
|
||||
{
|
||||
id: testPolicyId,
|
||||
label: 'Private Europe West',
|
||||
isServiceManaged: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const username = 'admin';
|
||||
const roleName = `synthetics_admin`;
|
||||
const password = `${username}-password`;
|
||||
let monitorId = '';
|
||||
|
||||
try {
|
||||
// use a user without fleet permissions to cause an error
|
||||
await security.role.create(roleName, {
|
||||
kibana: [
|
||||
{
|
||||
feature: {
|
||||
uptime: ['all'],
|
||||
},
|
||||
spaces: ['*'],
|
||||
},
|
||||
],
|
||||
});
|
||||
await security.user.create(username, {
|
||||
password,
|
||||
roles: [roleName],
|
||||
full_name: 'a kibana user',
|
||||
});
|
||||
const { id } = await saveMonitor(newMonitor as MonitorFields);
|
||||
monitorId = id;
|
||||
|
||||
// delete the integration policy to cause an error
|
||||
await kibanaServer.savedObjects.clean({ types: [PACKAGE_POLICY_SAVED_OBJECT_TYPE] });
|
||||
|
||||
await supertestWithoutAuth
|
||||
.delete(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + monitorId)
|
||||
.auth(username, password)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(500);
|
||||
|
||||
const response = await monitorTestService.getMonitor(monitorId);
|
||||
|
||||
// ensure monitor was not deleted
|
||||
expect(response.body.urls).eql(newMonitor.urls);
|
||||
} finally {
|
||||
await security.user.delete(username);
|
||||
await security.role.delete(roleName);
|
||||
await kibanaServer.savedObjects.clean({ types: [syntheticsMonitorType] });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,524 +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 { v4 as uuidv4 } from 'uuid';
|
||||
import { ConfigKey, ProjectMonitorsRequest } from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { REQUEST_TOO_LARGE_DELETE } from '@kbn/synthetics-plugin/server/routes/monitor_cruds/project_monitor/delete_monitor_project';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import { PackagePolicy } from '@kbn/fleet-plugin/common';
|
||||
import expect from '@kbn/expect';
|
||||
import { syntheticsMonitorType } from '@kbn/synthetics-plugin/common/types/saved_objects';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helper/get_fixture_json';
|
||||
import { PrivateLocationTestService } from './services/private_location_test_service';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
describe('DeleteProjectMonitors', function () {
|
||||
this.tags('skipCloud');
|
||||
|
||||
const supertest = getService('supertest');
|
||||
const supertestWithoutAuth = getService('supertestWithoutAuth');
|
||||
const security = getService('security');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
|
||||
let projectMonitors: ProjectMonitorsRequest;
|
||||
|
||||
let testPolicyId = '';
|
||||
let loc: any;
|
||||
const testPrivateLocations = new PrivateLocationTestService(getService);
|
||||
|
||||
const setUniqueIds = (request: ProjectMonitorsRequest) => {
|
||||
return {
|
||||
...request,
|
||||
monitors: request.monitors.map((monitor) => ({ ...monitor, id: uuidv4() })),
|
||||
};
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
await testPrivateLocations.installSyntheticsPackage();
|
||||
loc = await testPrivateLocations.addPrivateLocation();
|
||||
testPolicyId = loc.agentPolicyId;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
projectMonitors = setUniqueIds(getFixtureJson('project_browser_monitor'));
|
||||
});
|
||||
|
||||
it('only allows 500 requests at a time', async () => {
|
||||
const project = 'test-brower-suite';
|
||||
const monitors = [];
|
||||
for (let i = 0; i < 550; i++) {
|
||||
monitors.push({
|
||||
...projectMonitors.monitors[0],
|
||||
id: `test-id-${i}`,
|
||||
name: `test-name-${i}`,
|
||||
});
|
||||
}
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
|
||||
try {
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitors.slice(0, 250) })
|
||||
.expect(200);
|
||||
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitors.slice(250, 251) })
|
||||
.expect(200);
|
||||
|
||||
const savedObjectsResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${project}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true');
|
||||
const { total } = savedObjectsResponse.body;
|
||||
expect(total).to.eql(251);
|
||||
|
||||
const response = await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete })
|
||||
.expect(400);
|
||||
const { message } = response.body;
|
||||
expect(message).to.eql(REQUEST_TOO_LARGE_DELETE);
|
||||
} finally {
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(0, 250) })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(250, 251) })
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('project monitors - handles browser monitors', async () => {
|
||||
const monitorToDelete = 'second-monitor-id';
|
||||
const monitors = [
|
||||
projectMonitors.monitors[0],
|
||||
{
|
||||
...projectMonitors.monitors[0],
|
||||
id: monitorToDelete,
|
||||
},
|
||||
];
|
||||
const project = 'test-brower-suite';
|
||||
|
||||
try {
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors })
|
||||
.expect(200);
|
||||
|
||||
const savedObjectsResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${project}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
const { total } = savedObjectsResponse.body;
|
||||
expect(total).to.eql(2);
|
||||
const monitorsToDelete = [monitorToDelete];
|
||||
|
||||
const response = await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete })
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.deleted_monitors).to.eql(monitorsToDelete);
|
||||
|
||||
const responseAfterDeletion = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${project}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
const { total: totalAfterDeletion } = responseAfterDeletion.body;
|
||||
expect(totalAfterDeletion).to.eql(1);
|
||||
} finally {
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete })
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('does not delete monitors from a different project', async () => {
|
||||
const monitors = [...projectMonitors.monitors];
|
||||
const project = 'test-brower-suite';
|
||||
const secondProject = 'second-project';
|
||||
|
||||
try {
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors })
|
||||
.expect(200);
|
||||
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace(
|
||||
'{projectName}',
|
||||
secondProject
|
||||
)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors })
|
||||
.expect(200);
|
||||
|
||||
const savedObjectsResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${project}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
const secondProjectSavedObjectResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${secondProject}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
const { total } = savedObjectsResponse.body;
|
||||
const { total: secondProjectTotal } = secondProjectSavedObjectResponse.body;
|
||||
expect(total).to.eql(monitors.length);
|
||||
expect(secondProjectTotal).to.eql(monitors.length);
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
|
||||
const response = await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete })
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.deleted_monitors).to.eql(monitorsToDelete);
|
||||
|
||||
const responseAfterDeletion = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${project}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
const secondResponseAfterDeletion = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${secondProject}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
const { total: totalAfterDeletion } = responseAfterDeletion.body;
|
||||
const { total: secondProjectTotalAfterDeletion } = secondResponseAfterDeletion.body;
|
||||
expect(totalAfterDeletion).to.eql(0);
|
||||
expect(secondProjectTotalAfterDeletion).to.eql(monitors.length);
|
||||
} finally {
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace(
|
||||
'{projectName}',
|
||||
secondProject
|
||||
)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete })
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('does not delete monitors from the same project in a different space project', async () => {
|
||||
const monitors = [...projectMonitors.monitors];
|
||||
const project = 'test-brower-suite';
|
||||
const SPACE_ID = `test-space-${uuidv4()}`;
|
||||
const SPACE_NAME = `test-space-name ${uuidv4()}`;
|
||||
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
|
||||
|
||||
try {
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors })
|
||||
.expect(200);
|
||||
|
||||
await supertest
|
||||
.put(
|
||||
`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace(
|
||||
'{projectName}',
|
||||
project
|
||||
)}`
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors })
|
||||
.expect(200);
|
||||
|
||||
const savedObjectsResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${project}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
const secondSpaceProjectSavedObjectResponse = await supertest
|
||||
.get(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${project}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
const { total } = savedObjectsResponse.body;
|
||||
const { total: secondSpaceTotal } = secondSpaceProjectSavedObjectResponse.body;
|
||||
|
||||
expect(total).to.eql(monitors.length);
|
||||
expect(secondSpaceTotal).to.eql(monitors.length);
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
|
||||
const response = await supertest
|
||||
.delete(
|
||||
`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace(
|
||||
'{projectName}',
|
||||
project
|
||||
)}`
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete })
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.deleted_monitors).to.eql(monitorsToDelete);
|
||||
|
||||
const responseAfterDeletion = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${project}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
const secondSpaceResponseAfterDeletion = await supertest
|
||||
.get(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${project}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
const { total: totalAfterDeletion } = responseAfterDeletion.body;
|
||||
const { total: secondProjectTotalAfterDeletion } = secondSpaceResponseAfterDeletion.body;
|
||||
expect(totalAfterDeletion).to.eql(monitors.length);
|
||||
expect(secondProjectTotalAfterDeletion).to.eql(0);
|
||||
} finally {
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
|
||||
await supertest
|
||||
.delete(
|
||||
`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace(
|
||||
'{projectName}',
|
||||
project
|
||||
)}`
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete })
|
||||
.expect(200);
|
||||
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete })
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('deletes integration policies when project monitors are deleted', async () => {
|
||||
const monitors = [
|
||||
{ ...projectMonitors.monitors[0], privateLocations: ['Test private location 0'] },
|
||||
];
|
||||
const project = 'test-brower-suite';
|
||||
|
||||
try {
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors })
|
||||
.expect(200);
|
||||
|
||||
const savedObjectsResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${project}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
const { total } = savedObjectsResponse.body;
|
||||
expect(total).to.eql(monitors.length);
|
||||
const apiResponsePolicy = await supertest.get(
|
||||
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
|
||||
);
|
||||
|
||||
const packagePolicy = apiResponsePolicy.body.items.find(
|
||||
(pkgPolicy: PackagePolicy) =>
|
||||
pkgPolicy.id ===
|
||||
savedObjectsResponse.body.monitors[0][ConfigKey.CUSTOM_HEARTBEAT_ID] + '-' + loc.id
|
||||
);
|
||||
expect(packagePolicy.policy_id).to.be(testPolicyId);
|
||||
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
|
||||
const response = await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete })
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.deleted_monitors).to.eql(monitorsToDelete);
|
||||
|
||||
const responseAfterDeletion = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${project}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
const { total: totalAfterDeletion } = responseAfterDeletion.body;
|
||||
expect(totalAfterDeletion).to.eql(0);
|
||||
const apiResponsePolicy2 = await supertest.get(
|
||||
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
|
||||
);
|
||||
|
||||
const packagePolicy2 = apiResponsePolicy2.body.items.find(
|
||||
(pkgPolicy: PackagePolicy) =>
|
||||
pkgPolicy.id ===
|
||||
savedObjectsResponse.body.monitors[0][ConfigKey.CUSTOM_HEARTBEAT_ID] + '-' + loc.id
|
||||
);
|
||||
expect(packagePolicy2).to.be(undefined);
|
||||
} finally {
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete })
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('returns 403 when a user without fleet permissions attempts to delete a project monitor with a private location', async () => {
|
||||
const project = 'test-brower-suite';
|
||||
const secondMonitor = {
|
||||
...projectMonitors.monitors[0],
|
||||
id: 'test-id-2',
|
||||
privateLocations: ['Test private location 0'],
|
||||
};
|
||||
const testMonitors = [projectMonitors.monitors[0], secondMonitor];
|
||||
const monitorsToDelete = testMonitors.map((monitor) => monitor.id);
|
||||
const username = 'admin';
|
||||
const roleName = 'uptime read only';
|
||||
const password = `${username} - password`;
|
||||
try {
|
||||
await security.role.create(roleName, {
|
||||
kibana: [
|
||||
{
|
||||
feature: {
|
||||
uptime: ['all'],
|
||||
},
|
||||
spaces: ['*'],
|
||||
},
|
||||
],
|
||||
});
|
||||
await security.user.create(username, {
|
||||
password,
|
||||
roles: [roleName],
|
||||
full_name: 'a kibana user',
|
||||
});
|
||||
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: testMonitors })
|
||||
.expect(200);
|
||||
|
||||
const savedObjectsResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.project_id: "${project}"`,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
const { total } = savedObjectsResponse.body;
|
||||
expect(total).to.eql(2);
|
||||
|
||||
await supertestWithoutAuth
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.auth(username, password)
|
||||
.send({ monitors: monitorsToDelete })
|
||||
.expect(200);
|
||||
} finally {
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete })
|
||||
.expect(200);
|
||||
await security.user.delete(username);
|
||||
await security.role.delete(roleName);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
|
@ -6,21 +6,16 @@
|
|||
*/
|
||||
import moment from 'moment';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { omit } from 'lodash';
|
||||
import {
|
||||
ConfigKey,
|
||||
EncryptedSyntheticsSavedMonitor,
|
||||
HTTPFields,
|
||||
MonitorFields,
|
||||
} from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import expect from '@kbn/expect';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helper/get_fixture_json';
|
||||
import { omitResponseTimestamps, omitEmptyValues } from './helper/monitor';
|
||||
import { PrivateLocationTestService } from './services/private_location_test_service';
|
||||
import { SyntheticsMonitorTestService } from './services/synthetics_monitor_test_service';
|
||||
import { LOCAL_LOCATION } from './get_filters';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
describe('EditMonitorAPI', function () {
|
||||
|
@ -34,8 +29,6 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
const testPrivateLocations = new PrivateLocationTestService(getService);
|
||||
const monitorTestService = new SyntheticsMonitorTestService(getService);
|
||||
|
||||
let _httpMonitorJson: HTTPFields;
|
||||
let httpMonitorJson: HTTPFields;
|
||||
let testPolicyId = '';
|
||||
|
||||
const saveMonitor = async (monitor: MonitorFields, spaceId?: string) => {
|
||||
|
@ -56,23 +49,8 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
return rest as EncryptedSyntheticsSavedMonitor;
|
||||
};
|
||||
|
||||
const editMonitor = async (modifiedMonitor: MonitorFields, monitorId: string) => {
|
||||
const res = await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + monitorId + '?internal=true')
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(modifiedMonitor);
|
||||
|
||||
expect(res.status).eql(200, JSON.stringify(res.body));
|
||||
|
||||
const { created_at: createdAt, updated_at: updatedAt } = res.body;
|
||||
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);
|
||||
|
||||
return omit(res.body, ['created_at', 'updated_at']);
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
_httpMonitorJson = getFixtureJson('http_monitor');
|
||||
await supertest.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
|
||||
await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_ENABLEMENT)
|
||||
|
@ -87,213 +65,6 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
httpMonitorJson = { ..._httpMonitorJson };
|
||||
});
|
||||
|
||||
it('edits the monitor', async () => {
|
||||
const newMonitor = httpMonitorJson;
|
||||
|
||||
const savedMonitor = await saveMonitor(newMonitor as MonitorFields);
|
||||
const monitorId = savedMonitor[ConfigKey.CONFIG_ID];
|
||||
|
||||
expect(omitResponseTimestamps(savedMonitor)).eql(
|
||||
omitEmptyValues({
|
||||
...newMonitor,
|
||||
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
|
||||
[ConfigKey.CONFIG_ID]: monitorId,
|
||||
})
|
||||
);
|
||||
|
||||
const updates: Partial<HTTPFields> = {
|
||||
[ConfigKey.URLS]: 'https://modified-host.com',
|
||||
[ConfigKey.NAME]: 'Modified name',
|
||||
[ConfigKey.LOCATIONS]: [LOCAL_LOCATION],
|
||||
[ConfigKey.REQUEST_HEADERS_CHECK]: {
|
||||
sampleHeader2: 'sampleValue2',
|
||||
},
|
||||
[ConfigKey.METADATA]: {
|
||||
script_source: {
|
||||
is_generated_script: false,
|
||||
file_name: 'test-file.name',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const modifiedMonitor = {
|
||||
...savedMonitor,
|
||||
...updates,
|
||||
[ConfigKey.METADATA]: {
|
||||
...newMonitor[ConfigKey.METADATA],
|
||||
...updates[ConfigKey.METADATA],
|
||||
},
|
||||
} as any;
|
||||
|
||||
const editResponse = await editMonitor(modifiedMonitor, monitorId);
|
||||
|
||||
expect(editResponse).eql(
|
||||
omitEmptyValues({
|
||||
...modifiedMonitor,
|
||||
revision: 2,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('strips unknown keys from monitor edits', async () => {
|
||||
const newMonitor = { ...httpMonitorJson, name: 'yet another' };
|
||||
|
||||
const savedMonitor = await saveMonitor(newMonitor as MonitorFields);
|
||||
const monitorId = savedMonitor[ConfigKey.CONFIG_ID];
|
||||
|
||||
const { created_at: createdAt, updated_at: updatedAt } = savedMonitor;
|
||||
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);
|
||||
|
||||
expect(omitResponseTimestamps(savedMonitor)).eql(
|
||||
omitEmptyValues({
|
||||
...newMonitor,
|
||||
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
|
||||
[ConfigKey.CONFIG_ID]: monitorId,
|
||||
})
|
||||
);
|
||||
|
||||
const updates: Partial<HTTPFields> = {
|
||||
[ConfigKey.URLS]: 'https://modified-host.com',
|
||||
[ConfigKey.NAME]: 'Modified name like that',
|
||||
[ConfigKey.LOCATIONS]: [LOCAL_LOCATION],
|
||||
[ConfigKey.REQUEST_HEADERS_CHECK]: {
|
||||
sampleHeader2: 'sampleValue2',
|
||||
},
|
||||
[ConfigKey.METADATA]: {
|
||||
script_source: {
|
||||
is_generated_script: false,
|
||||
file_name: 'test-file.name',
|
||||
},
|
||||
},
|
||||
unknownkey: 'unknownvalue',
|
||||
} as Partial<HTTPFields>;
|
||||
|
||||
const modifiedMonitor = omit(
|
||||
{
|
||||
...updates,
|
||||
[ConfigKey.METADATA]: {
|
||||
...newMonitor[ConfigKey.METADATA],
|
||||
...updates[ConfigKey.METADATA],
|
||||
},
|
||||
},
|
||||
['unknownkey']
|
||||
);
|
||||
|
||||
const editResponse = await editMonitor(modifiedMonitor as MonitorFields, monitorId);
|
||||
|
||||
expect(editResponse).eql(
|
||||
omitEmptyValues({
|
||||
...savedMonitor,
|
||||
...modifiedMonitor,
|
||||
revision: 2,
|
||||
})
|
||||
);
|
||||
expect(editResponse).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!`;
|
||||
|
||||
const editResponse = await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + invalidMonitorId)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(httpMonitorJson)
|
||||
.expect(404);
|
||||
|
||||
expect(editResponse.body.message).eql(expected404Message);
|
||||
});
|
||||
|
||||
it('returns bad request if payload is invalid for HTTP monitor', async () => {
|
||||
const { id: monitorId, ...savedMonitor } = await saveMonitor(
|
||||
httpMonitorJson as MonitorFields
|
||||
);
|
||||
|
||||
// Delete a required property to make payload invalid
|
||||
const toUpdate = { ...savedMonitor, 'check.request.headers': null };
|
||||
|
||||
const apiResponse = await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + monitorId)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(toUpdate);
|
||||
|
||||
expect(apiResponse.status).eql(400);
|
||||
});
|
||||
|
||||
it('returns bad request if monitor type is invalid', async () => {
|
||||
const { id: monitorId, ...savedMonitor } = await saveMonitor({
|
||||
...httpMonitorJson,
|
||||
name: 'test monitor - 11',
|
||||
} as MonitorFields);
|
||||
|
||||
const toUpdate = { ...savedMonitor, type: 'invalid-data-steam' };
|
||||
|
||||
const apiResponse = await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + monitorId)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(toUpdate);
|
||||
|
||||
expect(apiResponse.status).eql(400);
|
||||
expect(apiResponse.body.message).eql(
|
||||
'Monitor type cannot be changed from http to invalid-data-steam.'
|
||||
);
|
||||
});
|
||||
|
||||
it('sets config hash to empty string on edits', async () => {
|
||||
const newMonitor = httpMonitorJson;
|
||||
const configHash = 'djrhefje';
|
||||
|
||||
const savedMonitor = await saveMonitor({
|
||||
...(newMonitor as MonitorFields),
|
||||
[ConfigKey.CONFIG_HASH]: configHash,
|
||||
name: 'test monitor - 12',
|
||||
});
|
||||
const monitorId = savedMonitor[ConfigKey.CONFIG_ID];
|
||||
const { created_at: createdAt, updated_at: updatedAt } = savedMonitor;
|
||||
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);
|
||||
|
||||
expect(savedMonitor).eql(
|
||||
omitEmptyValues({
|
||||
...newMonitor,
|
||||
[ConfigKey.CONFIG_ID]: monitorId,
|
||||
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
|
||||
name: 'test monitor - 12',
|
||||
hash: configHash,
|
||||
})
|
||||
);
|
||||
|
||||
const updates: Partial<HTTPFields> = {
|
||||
[ConfigKey.URLS]: 'https://modified-host.com',
|
||||
name: 'test monitor - 12',
|
||||
} as Partial<HTTPFields>;
|
||||
|
||||
const modifiedMonitor = {
|
||||
...newMonitor,
|
||||
...updates,
|
||||
[ConfigKey.METADATA]: {
|
||||
...newMonitor[ConfigKey.METADATA],
|
||||
...updates[ConfigKey.METADATA],
|
||||
},
|
||||
};
|
||||
|
||||
const editResponse = await editMonitor(modifiedMonitor as MonitorFields, monitorId);
|
||||
|
||||
expect(editResponse).eql(
|
||||
omitEmptyValues({
|
||||
...modifiedMonitor,
|
||||
[ConfigKey.CONFIG_ID]: monitorId,
|
||||
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
|
||||
[ConfigKey.CONFIG_HASH]: '',
|
||||
revision: 2,
|
||||
})
|
||||
);
|
||||
expect(editResponse).not.to.have.keys('unknownkey');
|
||||
});
|
||||
|
||||
it.skip('handles private location errors and does not update the monitor if integration policy is unable to be updated', async () => {
|
||||
const name = 'Monitor with private location';
|
||||
const newMonitor = {
|
||||
|
@ -365,61 +136,5 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('handles spaces', async () => {
|
||||
const name = 'Monitor with private location';
|
||||
const newMonitor = {
|
||||
name,
|
||||
type: 'http',
|
||||
urls: 'https://elastic.co',
|
||||
locations: [LOCAL_LOCATION],
|
||||
};
|
||||
|
||||
const SPACE_ID = `test-space-${uuidv4()}`;
|
||||
const SPACE_NAME = `test-space-name ${uuidv4()}`;
|
||||
|
||||
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
|
||||
|
||||
const savedMonitor = await saveMonitor(newMonitor as MonitorFields, SPACE_ID);
|
||||
|
||||
const monitorId = savedMonitor[ConfigKey.CONFIG_ID];
|
||||
const toUpdate = {
|
||||
...savedMonitor,
|
||||
urls: 'https://google.com',
|
||||
};
|
||||
await supertest
|
||||
.put(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}/${monitorId}`)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(toUpdate)
|
||||
.expect(200);
|
||||
|
||||
const updatedResponse = await monitorTestService.getMonitor(monitorId, {
|
||||
space: SPACE_ID,
|
||||
internal: true,
|
||||
});
|
||||
|
||||
// ensure monitor was updated
|
||||
expect(updatedResponse.body.urls).eql(toUpdate.urls);
|
||||
|
||||
// update a second time, ensures AAD was not corrupted
|
||||
const toUpdate2 = {
|
||||
...savedMonitor,
|
||||
urls: 'https://google.com',
|
||||
};
|
||||
|
||||
await supertest
|
||||
.put(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}/${monitorId}`)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(toUpdate2)
|
||||
.expect(200);
|
||||
|
||||
const updatedResponse2 = await monitorTestService.getMonitor(monitorId, {
|
||||
space: SPACE_ID,
|
||||
internal: true,
|
||||
});
|
||||
|
||||
// ensure monitor was updated
|
||||
expect(updatedResponse2.body.urls).eql(toUpdate2.urls);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,296 +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 expect from '@kbn/expect';
|
||||
import { omit } from 'lodash';
|
||||
import { HTTPFields } from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import { DYNAMIC_SETTINGS_DEFAULTS } from '@kbn/synthetics-plugin/common/constants/settings_defaults';
|
||||
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helper/get_fixture_json';
|
||||
import { addMonitorAPIHelper, omitMonitorKeys } from './add_monitor';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
describe('EnableDefaultAlerting', function () {
|
||||
this.tags('skipCloud');
|
||||
|
||||
const supertest = getService('supertest');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
const retry = getService('retry');
|
||||
|
||||
let _httpMonitorJson: HTTPFields;
|
||||
let httpMonitorJson: HTTPFields;
|
||||
|
||||
const addMonitorAPI = async (monitor: any, statusCode = 200) => {
|
||||
return addMonitorAPIHelper(supertest, monitor, statusCode);
|
||||
};
|
||||
|
||||
after(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
});
|
||||
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
|
||||
_httpMonitorJson = getFixtureJson('http_monitor');
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
httpMonitorJson = _httpMonitorJson;
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
await supertest
|
||||
.put(SYNTHETICS_API_URLS.DYNAMIC_SETTINGS)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(DYNAMIC_SETTINGS_DEFAULTS)
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it('returns the created alerted when called', async () => {
|
||||
const apiResponse = await supertest
|
||||
.post(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
const omitFields = [
|
||||
'id',
|
||||
'updatedAt',
|
||||
'createdAt',
|
||||
'scheduledTaskId',
|
||||
'executionStatus',
|
||||
'monitoring',
|
||||
'nextRun',
|
||||
'lastRun',
|
||||
'snoozeSchedule',
|
||||
'viewInAppRelativeUrl',
|
||||
];
|
||||
|
||||
const statusRule = apiResponse.body.statusRule;
|
||||
const tlsRule = apiResponse.body.tlsRule;
|
||||
|
||||
expect(omit(statusRule, omitFields)).eql(omit(defaultAlertRules.statusRule, omitFields));
|
||||
expect(omit(tlsRule, omitFields)).eql(omit(defaultAlertRules.tlsRule, omitFields));
|
||||
});
|
||||
|
||||
it('enables alert when new monitor is added', async () => {
|
||||
const newMonitor = httpMonitorJson;
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
expect(apiResponse).eql(omitMonitorKeys({ ...newMonitor, spaceId: 'default' }));
|
||||
|
||||
await retry.tryForTime(30 * 1000, async () => {
|
||||
const res = await supertest
|
||||
.get(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
|
||||
expect(res.body.statusRule.ruleTypeId).eql('xpack.synthetics.alerts.monitorStatus');
|
||||
expect(res.body.tlsRule.ruleTypeId).eql('xpack.synthetics.alerts.tls');
|
||||
});
|
||||
});
|
||||
|
||||
it('deletes (and recreates) the default rule when settings are updated', async () => {
|
||||
const newMonitor = httpMonitorJson;
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
expect(apiResponse).eql(omitMonitorKeys(newMonitor));
|
||||
|
||||
await retry.tryForTime(30 * 1000, async () => {
|
||||
const res = await supertest
|
||||
.get(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
|
||||
expect(res.body.statusRule.ruleTypeId).eql('xpack.synthetics.alerts.monitorStatus');
|
||||
expect(res.body.tlsRule.ruleTypeId).eql('xpack.synthetics.alerts.tls');
|
||||
});
|
||||
const settings = await supertest
|
||||
.put(SYNTHETICS_API_URLS.DYNAMIC_SETTINGS)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
defaultStatusRuleEnabled: false,
|
||||
defaultTLSRuleEnabled: false,
|
||||
});
|
||||
|
||||
expect(settings.body.defaultStatusRuleEnabled).eql(false);
|
||||
expect(settings.body.defaultTLSRuleEnabled).eql(false);
|
||||
|
||||
await supertest
|
||||
.put(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
await retry.tryForTime(30 * 1000, async () => {
|
||||
const res = await supertest
|
||||
.get(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
|
||||
expect(res.body.statusRule).eql(null);
|
||||
expect(res.body.tlsRule).eql(null);
|
||||
});
|
||||
|
||||
const settings2 = await supertest
|
||||
.put(SYNTHETICS_API_URLS.DYNAMIC_SETTINGS)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
defaultStatusRuleEnabled: true,
|
||||
defaultTLSRuleEnabled: true,
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
expect(settings2.body.defaultStatusRuleEnabled).eql(true);
|
||||
expect(settings2.body.defaultTLSRuleEnabled).eql(true);
|
||||
|
||||
await supertest
|
||||
.put(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
await retry.tryForTime(30 * 1000, async () => {
|
||||
const res = await supertest
|
||||
.get(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
|
||||
expect(res.body.statusRule.ruleTypeId).eql('xpack.synthetics.alerts.monitorStatus');
|
||||
expect(res.body.tlsRule.ruleTypeId).eql('xpack.synthetics.alerts.tls');
|
||||
});
|
||||
});
|
||||
|
||||
it('doesnt throw errors when rule has already been deleted', async () => {
|
||||
const newMonitor = httpMonitorJson;
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
expect(apiResponse).eql(omitMonitorKeys(newMonitor));
|
||||
|
||||
await retry.tryForTime(30 * 1000, async () => {
|
||||
const res = await supertest
|
||||
.get(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING)
|
||||
.set('kbn-xsrf', 'true');
|
||||
|
||||
expect(res.body.statusRule.ruleTypeId).eql('xpack.synthetics.alerts.monitorStatus');
|
||||
expect(res.body.tlsRule.ruleTypeId).eql('xpack.synthetics.alerts.tls');
|
||||
});
|
||||
|
||||
const settings = await supertest
|
||||
.put(SYNTHETICS_API_URLS.DYNAMIC_SETTINGS)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
defaultStatusRuleEnabled: false,
|
||||
defaultTLSRuleEnabled: false,
|
||||
});
|
||||
|
||||
expect(settings.body.defaultStatusRuleEnabled).eql(false);
|
||||
expect(settings.body.defaultTLSRuleEnabled).eql(false);
|
||||
|
||||
await supertest
|
||||
.put(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send();
|
||||
|
||||
await retry.tryForTime(30 * 1000, async () => {
|
||||
const res = await supertest
|
||||
.get(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
|
||||
expect(res.body.statusRule).eql(null);
|
||||
expect(res.body.tlsRule).eql(null);
|
||||
});
|
||||
|
||||
// call api again with the same settings, make sure its 200
|
||||
await supertest
|
||||
.put(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
await retry.tryForTime(30 * 1000, async () => {
|
||||
const res = await supertest
|
||||
.get(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
|
||||
expect(res.body.statusRule).eql(null);
|
||||
expect(res.body.tlsRule).eql(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const defaultAlertRules = {
|
||||
statusRule: {
|
||||
id: '574e82f0-1672-11ee-8e7d-c985c0ef6c2e',
|
||||
notifyWhen: null,
|
||||
consumer: 'uptime',
|
||||
alertTypeId: 'xpack.synthetics.alerts.monitorStatus',
|
||||
tags: ['SYNTHETICS_DEFAULT_ALERT'],
|
||||
name: 'Synthetics status internal rule',
|
||||
enabled: true,
|
||||
throttle: null,
|
||||
apiKeyOwner: 'elastic',
|
||||
apiKeyCreatedByUser: false,
|
||||
createdBy: 'elastic',
|
||||
updatedBy: 'elastic',
|
||||
muteAll: false,
|
||||
mutedInstanceIds: [],
|
||||
revision: 0,
|
||||
running: false,
|
||||
schedule: { interval: '1m' },
|
||||
actions: [],
|
||||
params: {},
|
||||
snoozeSchedule: [],
|
||||
updatedAt: '2023-06-29T11:44:44.488Z',
|
||||
createdAt: '2023-06-29T11:44:44.488Z',
|
||||
scheduledTaskId: '574e82f0-1672-11ee-8e7d-c985c0ef6c2e',
|
||||
executionStatus: {
|
||||
status: 'ok',
|
||||
lastExecutionDate: '2023-06-29T11:47:55.331Z',
|
||||
lastDuration: 64,
|
||||
},
|
||||
ruleTypeId: 'xpack.synthetics.alerts.monitorStatus',
|
||||
viewInAppRelativeUrl: '/app/observability/alerts/rules/574e82f0-1672-11ee-8e7d-c985c0ef6c2e',
|
||||
},
|
||||
tlsRule: {
|
||||
id: '574eaa00-1672-11ee-8e7d-c985c0ef6c2e',
|
||||
notifyWhen: null,
|
||||
consumer: 'uptime',
|
||||
alertTypeId: 'xpack.synthetics.alerts.tls',
|
||||
tags: ['SYNTHETICS_DEFAULT_ALERT'],
|
||||
name: 'Synthetics internal TLS rule',
|
||||
enabled: true,
|
||||
throttle: null,
|
||||
apiKeyOwner: 'elastic',
|
||||
apiKeyCreatedByUser: false,
|
||||
createdBy: 'elastic',
|
||||
updatedBy: 'elastic',
|
||||
muteAll: false,
|
||||
mutedInstanceIds: [],
|
||||
revision: 0,
|
||||
running: false,
|
||||
schedule: { interval: '1m' },
|
||||
actions: [],
|
||||
params: {},
|
||||
snoozeSchedule: [],
|
||||
updatedAt: '2023-06-29T11:44:44.489Z',
|
||||
createdAt: '2023-06-29T11:44:44.489Z',
|
||||
scheduledTaskId: '574eaa00-1672-11ee-8e7d-c985c0ef6c2e',
|
||||
executionStatus: {
|
||||
status: 'ok',
|
||||
lastExecutionDate: '2023-06-29T11:44:46.214Z',
|
||||
lastDuration: 193,
|
||||
},
|
||||
ruleTypeId: 'xpack.synthetics.alerts.tls',
|
||||
viewInAppRelativeUrl: '/app/observability/alerts/rules/574e82f0-1672-11ee-8e7d-c985c0ef6c2e',
|
||||
},
|
||||
};
|
|
@ -1,78 +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 { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import expect from '@kbn/expect';
|
||||
import { syntheticsMonitorType } from '@kbn/synthetics-plugin/common/types/saved_objects';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
|
||||
export const LOCAL_LOCATION = {
|
||||
id: 'dev',
|
||||
label: 'Dev Service',
|
||||
geo: {
|
||||
lat: 0,
|
||||
lon: 0,
|
||||
},
|
||||
isServiceManaged: true,
|
||||
};
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
describe('getMonitorFilters', function () {
|
||||
this.tags('skipCloud');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
|
||||
const supertest = getService('supertest');
|
||||
|
||||
after(async () => {
|
||||
await kibanaServer.savedObjects.clean({ types: [syntheticsMonitorType] });
|
||||
});
|
||||
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.clean({ types: [syntheticsMonitorType] });
|
||||
});
|
||||
|
||||
it('get list of filters', async () => {
|
||||
const apiResponse = await supertest.get(SYNTHETICS_API_URLS.FILTERS).expect(200);
|
||||
|
||||
expect(apiResponse.body).eql({
|
||||
monitorTypes: [],
|
||||
tags: [],
|
||||
locations: [],
|
||||
projects: [],
|
||||
schedules: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('get list of filters with monitorTypes', async () => {
|
||||
const newMonitor = {
|
||||
name: 'Sample name',
|
||||
type: 'http',
|
||||
urls: 'https://elastic.co',
|
||||
tags: ['apm', 'synthetics'],
|
||||
locations: [LOCAL_LOCATION],
|
||||
};
|
||||
|
||||
await supertest
|
||||
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(newMonitor)
|
||||
.expect(200);
|
||||
|
||||
const apiResponse = await supertest.get(SYNTHETICS_API_URLS.FILTERS).expect(200);
|
||||
|
||||
expect(apiResponse.body).eql({
|
||||
monitorTypes: [{ label: 'http', count: 1 }],
|
||||
tags: [
|
||||
{ label: 'apm', count: 1 },
|
||||
{ label: 'synthetics', count: 1 },
|
||||
],
|
||||
locations: [{ label: 'dev', count: 1 }],
|
||||
projects: [],
|
||||
schedules: [{ label: '3', count: 1 }],
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,297 +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 { omit } from 'lodash';
|
||||
import moment from 'moment';
|
||||
import {
|
||||
ConfigKey,
|
||||
EncryptedSyntheticsSavedMonitor,
|
||||
MonitorFields,
|
||||
} from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import expect from '@kbn/expect';
|
||||
import { secretKeys } from '@kbn/synthetics-plugin/common/constants/monitor_management';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { SyntheticsMonitorTestService } from './services/synthetics_monitor_test_service';
|
||||
import { omitMonitorKeys } from './add_monitor';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helper/get_fixture_json';
|
||||
import { LOCAL_LOCATION } from './get_filters';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
describe('getSyntheticsMonitors', function () {
|
||||
this.tags('skipCloud');
|
||||
|
||||
const supertest = getService('supertest');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
const retry = getService('retry');
|
||||
const monitorTestService = new SyntheticsMonitorTestService(getService);
|
||||
|
||||
let _monitors: MonitorFields[];
|
||||
let monitors: MonitorFields[];
|
||||
|
||||
const saveMonitor = async (monitor: MonitorFields, spaceId?: string) => {
|
||||
let url = SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '?internal=true';
|
||||
if (spaceId) {
|
||||
url = '/s/' + spaceId + url;
|
||||
}
|
||||
const res = await supertest.post(url).set('kbn-xsrf', 'true').send(monitor);
|
||||
|
||||
expect(res.status).eql(200, JSON.stringify(res.body));
|
||||
|
||||
return res.body as EncryptedSyntheticsSavedMonitor;
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_ENABLEMENT)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
|
||||
_monitors = [
|
||||
getFixtureJson('icmp_monitor'),
|
||||
getFixtureJson('tcp_monitor'),
|
||||
getFixtureJson('http_monitor'),
|
||||
getFixtureJson('browser_monitor'),
|
||||
];
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
monitors = _monitors;
|
||||
});
|
||||
|
||||
describe('get many monitors', () => {
|
||||
it('without params', async () => {
|
||||
const [mon1, mon2] = await Promise.all(monitors.map((mon) => saveMonitor(mon)));
|
||||
|
||||
const apiResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '?perPage=1000&internal=true') // 1000 to sort of load all saved monitors
|
||||
.expect(200);
|
||||
|
||||
const found: MonitorFields[] = apiResponse.body.monitors.filter(({ id }: MonitorFields) =>
|
||||
[mon1.id, mon2.id].includes(id)
|
||||
);
|
||||
found.sort(({ id: a }) => (a === mon2.id ? 1 : a === mon1.id ? -1 : 0));
|
||||
const foundMonitors = found.map(
|
||||
(fields) => fields as unknown as EncryptedSyntheticsSavedMonitor
|
||||
);
|
||||
|
||||
const expected = [mon1, mon2];
|
||||
|
||||
/**
|
||||
* These dates are dynamically generated by the server, so we can't
|
||||
* compare them directly. Instead, we'll just check that they're valid.
|
||||
*/
|
||||
foundMonitors.forEach(({ updated_at: updatedAt, created_at: createdAt }) => {
|
||||
expect(moment(createdAt).isValid()).to.be(true);
|
||||
expect(moment(updatedAt).isValid()).to.be(true);
|
||||
});
|
||||
|
||||
expect(foundMonitors.map((fm) => omit(fm, 'updated_at', 'created_at', 'spaceId'))).eql(
|
||||
expected.map((expectedMon) =>
|
||||
omit(expectedMon, ['updated_at', 'created_at', ...secretKeys])
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('with page params', async () => {
|
||||
const allMonitors = [...monitors, ...monitors];
|
||||
for (const mon of allMonitors) {
|
||||
await saveMonitor({ ...mon, name: mon.name + Date.now() });
|
||||
}
|
||||
|
||||
await retry.try(async () => {
|
||||
const firstPageResp = await supertest
|
||||
.get(`${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}?page=1&perPage=2`)
|
||||
.expect(200);
|
||||
const secondPageResp = await supertest
|
||||
.get(`${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}?page=2&perPage=3`)
|
||||
.expect(200);
|
||||
|
||||
expect(firstPageResp.body.total).greaterThan(6);
|
||||
expect(firstPageResp.body.monitors.length).eql(2);
|
||||
expect(secondPageResp.body.monitors.length).eql(3);
|
||||
|
||||
expect(firstPageResp.body.monitors[0].id).not.eql(secondPageResp.body.monitors[0].id);
|
||||
});
|
||||
});
|
||||
|
||||
it('with single monitorQueryId filter', async () => {
|
||||
const [_, { id: id2 }] = await Promise.all(
|
||||
monitors.map((mon) => ({ ...mon, name: mon.name + '2' })).map((mon) => saveMonitor(mon))
|
||||
);
|
||||
|
||||
const resp = await supertest
|
||||
.get(
|
||||
`${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}?page=1&perPage=10&monitorQueryIds=${id2}`
|
||||
)
|
||||
.expect(200);
|
||||
|
||||
const resultMonitorIds = resp.body.monitors.map(({ id }: Partial<MonitorFields>) => id);
|
||||
expect(resultMonitorIds.length).eql(1);
|
||||
expect(resultMonitorIds).eql([id2]);
|
||||
});
|
||||
|
||||
it('with multiple monitorQueryId filter', async () => {
|
||||
const [_, { id: id2 }, { id: id3 }] = await Promise.all(
|
||||
monitors.map((mon) => ({ ...mon, name: mon.name + '3' })).map((monT) => saveMonitor(monT))
|
||||
);
|
||||
|
||||
const resp = await supertest
|
||||
.get(
|
||||
`${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}?page=1&perPage=10&sortField=name.keyword&sortOrder=asc&monitorQueryIds=${id2}&monitorQueryIds=${id3}`
|
||||
)
|
||||
.expect(200);
|
||||
|
||||
const resultMonitorIds = resp.body.monitors.map(({ id }: Partial<MonitorFields>) => id);
|
||||
|
||||
expect(resultMonitorIds.length).eql(2);
|
||||
expect(resultMonitorIds).eql([id2, id3]);
|
||||
});
|
||||
|
||||
it('monitorQueryId respects custom_heartbeat_id while filtering', async () => {
|
||||
const customHeartbeatId0 = 'custom-heartbeat-id-test-01';
|
||||
const customHeartbeatId1 = 'custom-heartbeat-id-test-02';
|
||||
await Promise.all(
|
||||
[
|
||||
{
|
||||
...monitors[0],
|
||||
[ConfigKey.CUSTOM_HEARTBEAT_ID]: customHeartbeatId0,
|
||||
[ConfigKey.NAME]: `NAME-${customHeartbeatId0}`,
|
||||
},
|
||||
{
|
||||
...monitors[1],
|
||||
[ConfigKey.CUSTOM_HEARTBEAT_ID]: customHeartbeatId1,
|
||||
[ConfigKey.NAME]: `NAME-${customHeartbeatId1}`,
|
||||
},
|
||||
].map((monT) => saveMonitor(monT))
|
||||
);
|
||||
|
||||
const resp = await supertest
|
||||
.get(
|
||||
`${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}?page=1&perPage=10&sortField=name.keyword&sortOrder=asc&monitorQueryIds=${customHeartbeatId0}&monitorQueryIds=${customHeartbeatId1}`
|
||||
)
|
||||
.expect(200);
|
||||
|
||||
const resultMonitorIds = resp.body.monitors
|
||||
.map(({ id }: Partial<MonitorFields>) => id)
|
||||
.filter((id: string, index: number, arr: string[]) => arr.indexOf(id) === index); // Filter only unique
|
||||
expect(resultMonitorIds.length).eql(2);
|
||||
expect(resultMonitorIds).eql([customHeartbeatId0, customHeartbeatId1]);
|
||||
});
|
||||
|
||||
it('gets monitors from all spaces', async () => {
|
||||
const SPACE_ID = `test-space-${uuidv4()}`;
|
||||
const SPACE_NAME = `test-space-name ${uuidv4()}`;
|
||||
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
|
||||
|
||||
const allMonitors = [...monitors, ...monitors];
|
||||
for (const mon of allMonitors) {
|
||||
await saveMonitor({ ...mon, name: mon.name + Date.now() }, SPACE_ID);
|
||||
}
|
||||
|
||||
const firstPageResp = await supertest
|
||||
.get(`${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}?page=1&perPage=1000`)
|
||||
.expect(200);
|
||||
const defaultSpaceMons = firstPageResp.body.monitors.filter(
|
||||
({ spaceId }: { spaceId: string }) => spaceId === 'default'
|
||||
);
|
||||
const testSpaceMons = firstPageResp.body.monitors.filter(
|
||||
({ spaceId }: { spaceId: string }) => spaceId === SPACE_ID
|
||||
);
|
||||
|
||||
expect(defaultSpaceMons.length).to.eql(22);
|
||||
expect(testSpaceMons.length).to.eql(0);
|
||||
|
||||
const res = await supertest
|
||||
.get(
|
||||
`${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}?page=1&perPage=1000&showFromAllSpaces=true`
|
||||
)
|
||||
.expect(200);
|
||||
|
||||
const defaultSpaceMons1 = res.body.monitors.filter(
|
||||
({ spaceId }: { spaceId: string }) => spaceId === 'default'
|
||||
);
|
||||
const testSpaceMons1 = res.body.monitors.filter(
|
||||
({ spaceId }: { spaceId: string }) => spaceId === SPACE_ID
|
||||
);
|
||||
|
||||
expect(defaultSpaceMons1.length).to.eql(22);
|
||||
expect(testSpaceMons1.length).to.eql(8);
|
||||
});
|
||||
});
|
||||
|
||||
describe('get one monitor', () => {
|
||||
it('should get by id', async () => {
|
||||
const [{ id: id1 }] = await Promise.all(
|
||||
monitors.map((mon) => ({ ...mon, name: mon.name + '4' })).map((monT) => saveMonitor(monT))
|
||||
);
|
||||
|
||||
const apiResponse = await monitorTestService.getMonitor(id1);
|
||||
|
||||
expect(apiResponse.body).eql(
|
||||
omitMonitorKeys({
|
||||
...monitors[0],
|
||||
[ConfigKey.MONITOR_QUERY_ID]: apiResponse.body.id,
|
||||
[ConfigKey.CONFIG_ID]: apiResponse.body.id,
|
||||
revision: 1,
|
||||
locations: [LOCAL_LOCATION],
|
||||
name: 'Test HTTP Monitor 044',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should get by id with ui query param', async () => {
|
||||
const [{ id: id1 }] = await Promise.all(
|
||||
monitors.map((mon) => ({ ...mon, name: mon.name + '5' })).map((monT) => saveMonitor(monT))
|
||||
);
|
||||
|
||||
const apiResponse = await monitorTestService.getMonitor(id1, { internal: true });
|
||||
|
||||
expect(apiResponse.body).eql(
|
||||
omit(
|
||||
{
|
||||
...monitors[0],
|
||||
form_monitor_type: 'icmp',
|
||||
revision: 1,
|
||||
locations: [LOCAL_LOCATION],
|
||||
name: 'Test HTTP Monitor 045',
|
||||
hosts: '192.33.22.111:3333',
|
||||
hash: '',
|
||||
journey_id: '',
|
||||
max_attempts: 2,
|
||||
labels: {},
|
||||
},
|
||||
['config_id', 'id', 'form_monitor_type']
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('returns 404 if monitor id is not found', async () => {
|
||||
const invalidMonitorId = 'invalid-id';
|
||||
const expected404Message = `Monitor id ${invalidMonitorId} not found!`;
|
||||
|
||||
const getResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.GET_SYNTHETICS_MONITOR.replace('{monitorId}', invalidMonitorId))
|
||||
.set('kbn-xsrf', 'true');
|
||||
|
||||
expect(getResponse.status).eql(404);
|
||||
expect(getResponse.body.message).eql(expected404Message);
|
||||
});
|
||||
|
||||
it('validates param length', async () => {
|
||||
const veryLargeMonId = new Array(1050).fill('1').join('');
|
||||
|
||||
await supertest
|
||||
.get(SYNTHETICS_API_URLS.GET_SYNTHETICS_MONITOR.replace('{monitorId}', veryLargeMonId))
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(400);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,673 +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 { v4 as uuidv4 } from 'uuid';
|
||||
import type SuperTest from 'supertest';
|
||||
import {
|
||||
LegacyProjectMonitorsRequest,
|
||||
ProjectMonitor,
|
||||
ProjectMonitorMetaData,
|
||||
} from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import expect from '@kbn/expect';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helper/get_fixture_json';
|
||||
import { PrivateLocationTestService } from './services/private_location_test_service';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
describe('GetProjectMonitors', function () {
|
||||
this.tags('skipCloud');
|
||||
|
||||
const supertest = getService('supertest');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
|
||||
let projectMonitors: LegacyProjectMonitorsRequest;
|
||||
let httpProjectMonitors: LegacyProjectMonitorsRequest;
|
||||
let tcpProjectMonitors: LegacyProjectMonitorsRequest;
|
||||
let icmpProjectMonitors: LegacyProjectMonitorsRequest;
|
||||
|
||||
const testPrivateLocations = new PrivateLocationTestService(getService);
|
||||
|
||||
const setUniqueIds = (request: LegacyProjectMonitorsRequest) => {
|
||||
return {
|
||||
...request,
|
||||
monitors: request.monitors.map((monitor) => ({ ...monitor, id: uuidv4() })),
|
||||
};
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
await testPrivateLocations.installSyntheticsPackage();
|
||||
|
||||
await testPrivateLocations.addPrivateLocation();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
projectMonitors = setUniqueIds(getFixtureJson('project_browser_monitor'));
|
||||
httpProjectMonitors = setUniqueIds(getFixtureJson('project_http_monitor'));
|
||||
tcpProjectMonitors = setUniqueIds(getFixtureJson('project_tcp_monitor'));
|
||||
icmpProjectMonitors = setUniqueIds(getFixtureJson('project_icmp_monitor'));
|
||||
});
|
||||
|
||||
it('project monitors - fetches all monitors - browser', async () => {
|
||||
const monitors = [];
|
||||
const project = 'test-brower-suite';
|
||||
for (let i = 0; i < 600; i++) {
|
||||
monitors.push({
|
||||
...projectMonitors.monitors[0],
|
||||
id: `test browser id ${i}`,
|
||||
name: `test name ${i}`,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(0, 250),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(250, 500),
|
||||
})
|
||||
.expect(200);
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(500, 600),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const firstPageResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT.replace('{projectName}', project))
|
||||
.query({
|
||||
per_page: 500,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
const { monitors: firstPageMonitors, total, after_key: afterKey } = firstPageResponse.body;
|
||||
expect(firstPageMonitors.length).to.eql(500);
|
||||
expect(total).to.eql(600);
|
||||
expect(afterKey).to.eql('test browser id 548');
|
||||
|
||||
const secondPageResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT.replace('{projectName}', project))
|
||||
.set('kbn-xsrf', 'true')
|
||||
.query({
|
||||
search_after: afterKey,
|
||||
})
|
||||
.send()
|
||||
.expect(200);
|
||||
const { monitors: secondPageMonitors } = secondPageResponse.body;
|
||||
expect(secondPageMonitors.length).to.eql(100);
|
||||
checkFields([...firstPageMonitors, ...secondPageMonitors], monitors);
|
||||
} finally {
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(0, 250) })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(250, 500) })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(500, 600) })
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('project monitors - fetches all monitors - http', async () => {
|
||||
const monitors = [];
|
||||
const project = 'test-http-suite';
|
||||
for (let i = 0; i < 600; i++) {
|
||||
monitors.push({
|
||||
...httpProjectMonitors.monitors[1],
|
||||
id: `test http id ${i}`,
|
||||
name: `test name ${i}`,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(0, 250),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(250, 500),
|
||||
})
|
||||
.expect(200);
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(500, 600),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const firstPageResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT.replace('{projectName}', project))
|
||||
.query({
|
||||
per_page: 500,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
const {
|
||||
monitors: firstPageProjectMonitors,
|
||||
after_key: afterKey,
|
||||
total,
|
||||
} = firstPageResponse.body;
|
||||
expect(firstPageProjectMonitors.length).to.eql(500);
|
||||
expect(total).to.eql(600);
|
||||
expect(afterKey).to.eql('test http id 548');
|
||||
|
||||
const secondPageResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT.replace('{projectName}', project))
|
||||
.set('kbn-xsrf', 'true')
|
||||
.query({
|
||||
search_after: afterKey,
|
||||
})
|
||||
.send()
|
||||
.expect(200);
|
||||
const { monitors: secondPageProjectMonitors } = secondPageResponse.body;
|
||||
expect(secondPageProjectMonitors.length).to.eql(100);
|
||||
checkFields([...firstPageProjectMonitors, ...secondPageProjectMonitors], monitors);
|
||||
} finally {
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(0, 250) })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(250, 500) })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(500, 600) })
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('project monitors - fetches all monitors - tcp', async () => {
|
||||
const monitors = [];
|
||||
const project = 'test-tcp-suite';
|
||||
for (let i = 0; i < 600; i++) {
|
||||
monitors.push({
|
||||
...tcpProjectMonitors.monitors[0],
|
||||
id: `test tcp id ${i}`,
|
||||
name: `test name ${i}`,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(0, 250),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(250, 500),
|
||||
})
|
||||
.expect(200);
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(500, 600),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const firstPageResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT.replace('{projectName}', project))
|
||||
.query({
|
||||
per_page: 500,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
const {
|
||||
monitors: firstPageProjectMonitors,
|
||||
after_key: afterKey,
|
||||
total,
|
||||
} = firstPageResponse.body;
|
||||
expect(firstPageProjectMonitors.length).to.eql(500);
|
||||
expect(total).to.eql(600);
|
||||
expect(afterKey).to.eql('test tcp id 548');
|
||||
|
||||
const secondPageResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT.replace('{projectName}', project))
|
||||
.set('kbn-xsrf', 'true')
|
||||
.query({
|
||||
search_after: afterKey,
|
||||
})
|
||||
.send()
|
||||
.expect(200);
|
||||
const { monitors: secondPageProjectMonitors } = secondPageResponse.body;
|
||||
expect(secondPageProjectMonitors.length).to.eql(100);
|
||||
checkFields([...firstPageProjectMonitors, ...secondPageProjectMonitors], monitors);
|
||||
} finally {
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(0, 250) })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(250, 500) })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(500, 600) })
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('project monitors - fetches all monitors - icmp', async () => {
|
||||
const monitors = [];
|
||||
const project = 'test-icmp-suite';
|
||||
for (let i = 0; i < 600; i++) {
|
||||
monitors.push({
|
||||
...icmpProjectMonitors.monitors[0],
|
||||
id: `test icmp id ${i}`,
|
||||
name: `test name ${i}`,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(0, 250),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(250, 500),
|
||||
})
|
||||
.expect(200);
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(500, 600),
|
||||
})
|
||||
.expect(200);
|
||||
const firstPageResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT.replace('{projectName}', project))
|
||||
.query({
|
||||
per_page: 500,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
const {
|
||||
monitors: firstPageProjectMonitors,
|
||||
after_key: afterKey,
|
||||
total,
|
||||
} = firstPageResponse.body;
|
||||
expect(firstPageProjectMonitors.length).to.eql(500);
|
||||
expect(total).to.eql(600);
|
||||
expect(afterKey).to.eql('test icmp id 548');
|
||||
|
||||
const secondPageResponse = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT.replace('{projectName}', project))
|
||||
.set('kbn-xsrf', 'true')
|
||||
.query({
|
||||
search_after: afterKey,
|
||||
})
|
||||
.send()
|
||||
.expect(200);
|
||||
const { monitors: secondPageProjectMonitors } = secondPageResponse.body;
|
||||
expect(secondPageProjectMonitors.length).to.eql(100);
|
||||
|
||||
checkFields([...firstPageProjectMonitors, ...secondPageProjectMonitors], monitors);
|
||||
} finally {
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(0, 250) })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(250, 500) })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(500, 600) })
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('project monitors - handles url ecoded project names', async () => {
|
||||
const monitors = [];
|
||||
const projectName = 'Test project';
|
||||
for (let i = 0; i < 600; i++) {
|
||||
monitors.push({
|
||||
...icmpProjectMonitors.monitors[0],
|
||||
id: `test url id ${i}`,
|
||||
name: `test name ${i}`,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace(
|
||||
'{projectName}',
|
||||
projectName
|
||||
)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(0, 250),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace(
|
||||
'{projectName}',
|
||||
projectName
|
||||
)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(250, 500),
|
||||
})
|
||||
.expect(200);
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace(
|
||||
'{projectName}',
|
||||
projectName
|
||||
)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(500, 600),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const firstPageResponse = await supertest
|
||||
.get(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT.replace(
|
||||
'{projectName}',
|
||||
encodeURI(projectName)
|
||||
)
|
||||
)
|
||||
.query({
|
||||
per_page: 500,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
const {
|
||||
monitors: firstPageProjectMonitors,
|
||||
after_key: afterKey,
|
||||
total,
|
||||
} = firstPageResponse.body;
|
||||
expect(firstPageProjectMonitors.length).to.eql(500);
|
||||
expect(total).to.eql(600);
|
||||
expect(afterKey).to.eql('test url id 548');
|
||||
|
||||
const secondPageResponse = await supertest
|
||||
.get(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT.replace(
|
||||
'{projectName}',
|
||||
encodeURI(projectName)
|
||||
)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.query({
|
||||
search_after: afterKey,
|
||||
})
|
||||
.send()
|
||||
.expect(200);
|
||||
const { monitors: secondPageProjectMonitors } = secondPageResponse.body;
|
||||
expect(secondPageProjectMonitors.length).to.eql(100);
|
||||
|
||||
checkFields([...firstPageProjectMonitors, ...secondPageProjectMonitors], monitors);
|
||||
} finally {
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace(
|
||||
'{projectName}',
|
||||
encodeURI(projectName)
|
||||
)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(0, 250) })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace(
|
||||
'{projectName}',
|
||||
encodeURI(projectName)
|
||||
)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(250, 500) })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace(
|
||||
'{projectName}',
|
||||
encodeURI(projectName)
|
||||
)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(500, 600) })
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('project monitors - handles per_page parameter', async () => {
|
||||
const monitors = [];
|
||||
const project = 'test-suite';
|
||||
const perPage = 250;
|
||||
for (let i = 0; i < 600; i++) {
|
||||
monitors.push({
|
||||
...icmpProjectMonitors.monitors[0],
|
||||
id: `test-id-${i}`,
|
||||
name: `test-name-${i}`,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(0, 250),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(250, 500),
|
||||
})
|
||||
.expect(200);
|
||||
await supertest
|
||||
.put(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
monitors: monitors.slice(500, 600),
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
let count = Number.MAX_VALUE;
|
||||
let afterId;
|
||||
const fullResponse: ProjectMonitorMetaData[] = [];
|
||||
let page = 1;
|
||||
while (count >= 250) {
|
||||
const response: SuperTest.Response = await supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT.replace('{projectName}', project))
|
||||
.set('kbn-xsrf', 'true')
|
||||
.query({
|
||||
per_page: perPage,
|
||||
search_after: afterId,
|
||||
})
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
const { monitors: monitorsResponse, after_key: afterKey, total } = response.body;
|
||||
expect(total).to.eql(600);
|
||||
count = monitorsResponse.length;
|
||||
fullResponse.push(...monitorsResponse);
|
||||
if (page < 3) {
|
||||
expect(count).to.eql(perPage);
|
||||
} else {
|
||||
expect(count).to.eql(100);
|
||||
}
|
||||
page++;
|
||||
|
||||
afterId = afterKey;
|
||||
}
|
||||
// expect(fullResponse.length).to.eql(600);
|
||||
// checkFields(fullResponse, monitors);
|
||||
} finally {
|
||||
const monitorsToDelete = monitors.map((monitor) => monitor.id);
|
||||
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(0, 250) })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(250, 500) })
|
||||
.expect(200);
|
||||
await supertest
|
||||
.delete(
|
||||
SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_DELETE.replace('{projectName}', project)
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({ monitors: monitorsToDelete.slice(500, 600) })
|
||||
.expect(200);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const checkFields = (monitorMetaData: ProjectMonitorMetaData[], monitors: ProjectMonitor[]) => {
|
||||
monitors.forEach((monitor) => {
|
||||
const configIsCorrect = monitorMetaData.some((ndjson: Record<string, unknown>) => {
|
||||
return ndjson.journey_id === monitor.id && ndjson.hash === monitor.hash;
|
||||
});
|
||||
expect(configIsCorrect).to.eql(true);
|
||||
});
|
||||
};
|
|
@ -17,25 +17,13 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
|
|||
});
|
||||
|
||||
loadTestFile(require.resolve('./synthetics_api_security'));
|
||||
loadTestFile(require.resolve('./edit_monitor_public_api'));
|
||||
loadTestFile(require.resolve('./add_monitor_public_api'));
|
||||
loadTestFile(require.resolve('./synthetics_enablement'));
|
||||
loadTestFile(require.resolve('./get_filters'));
|
||||
loadTestFile(require.resolve('./enable_default_alerting'));
|
||||
loadTestFile(require.resolve('./get_monitor'));
|
||||
loadTestFile(require.resolve('./add_monitor'));
|
||||
loadTestFile(require.resolve('./add_monitor_project'));
|
||||
loadTestFile(require.resolve('./get_monitor_project'));
|
||||
loadTestFile(require.resolve('./add_monitor_private_location'));
|
||||
loadTestFile(require.resolve('./edit_monitor'));
|
||||
loadTestFile(require.resolve('./delete_monitor'));
|
||||
loadTestFile(require.resolve('./delete_monitor_project'));
|
||||
loadTestFile(require.resolve('./sync_global_params'));
|
||||
loadTestFile(require.resolve('./add_edit_params'));
|
||||
loadTestFile(require.resolve('./add_monitor_project_private_location'));
|
||||
loadTestFile(require.resolve('./inspect_monitor'));
|
||||
loadTestFile(require.resolve('./test_now_monitor'));
|
||||
loadTestFile(require.resolve('./suggestions'));
|
||||
loadTestFile(require.resolve('./private_location_apis'));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,238 +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 { MonitorFields } from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import expect from '@kbn/expect';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helper/get_fixture_json';
|
||||
import { SyntheticsMonitorTestService } from './services/synthetics_monitor_test_service';
|
||||
import { PrivateLocationTestService } from './services/private_location_test_service';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
describe('inspectSyntheticsMonitor', function () {
|
||||
this.tags('skipCloud');
|
||||
|
||||
const supertest = getService('supertest');
|
||||
|
||||
const monitorTestService = new SyntheticsMonitorTestService(getService);
|
||||
const testPrivateLocations = new PrivateLocationTestService(getService);
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
|
||||
let _monitors: MonitorFields[];
|
||||
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
await kibanaServer.savedObjects.clean({ types: ['synthetics-param'] });
|
||||
await testPrivateLocations.installSyntheticsPackage();
|
||||
await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_ENABLEMENT)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
_monitors = [getFixtureJson('http_monitor'), getFixtureJson('inspect_browser_monitor')];
|
||||
});
|
||||
|
||||
it('inspect http monitor', async () => {
|
||||
const apiResponse = await monitorTestService.inspectMonitor({
|
||||
..._monitors[0],
|
||||
locations: [
|
||||
{
|
||||
id: 'dev',
|
||||
label: 'Dev Service',
|
||||
isServiceManaged: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(apiResponse).eql({
|
||||
result: {
|
||||
publicConfigs: [
|
||||
{
|
||||
monitors: [
|
||||
{
|
||||
type: 'http',
|
||||
schedule: '@every 5m',
|
||||
enabled: true,
|
||||
data_stream: { namespace: 'testnamespace' },
|
||||
streams: [
|
||||
{
|
||||
data_stream: { dataset: 'http', type: 'synthetics' },
|
||||
type: 'http',
|
||||
enabled: true,
|
||||
schedule: '@every 5m',
|
||||
tags: ['tag1', 'tag2'],
|
||||
timeout: '180s',
|
||||
name: 'test-monitor-name',
|
||||
namespace: 'testnamespace',
|
||||
origin: 'ui',
|
||||
urls: 'https://nextjs-test-synthetics.vercel.app/api/users',
|
||||
max_redirects: '3',
|
||||
max_attempts: 2,
|
||||
password: 'test',
|
||||
proxy_url: 'http://proxy.com',
|
||||
'response.include_body': 'never',
|
||||
'response.include_headers': true,
|
||||
'check.response.status': ['200', '201'],
|
||||
'check.request.body': 'testValue',
|
||||
'check.request.headers': { sampleHeader: 'sampleHeaderValue' },
|
||||
username: 'test-username',
|
||||
mode: 'any',
|
||||
'response.include_body_max_bytes': '1024',
|
||||
ipv4: true,
|
||||
ipv6: true,
|
||||
fields: {
|
||||
meta: { space_id: 'default' },
|
||||
},
|
||||
fields_under_root: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
output: { hosts: [] },
|
||||
license_level: 'trial',
|
||||
},
|
||||
],
|
||||
privateConfig: null,
|
||||
},
|
||||
decodedCode: '',
|
||||
});
|
||||
});
|
||||
|
||||
it('inspect project browser monitor', async () => {
|
||||
const apiResponse = await monitorTestService.inspectMonitor({
|
||||
..._monitors[1],
|
||||
params: JSON.stringify({
|
||||
username: 'elastic',
|
||||
password: 'changeme',
|
||||
}),
|
||||
locations: [
|
||||
{
|
||||
id: 'dev',
|
||||
label: 'Dev Service',
|
||||
isServiceManaged: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(apiResponse).eql({
|
||||
result: {
|
||||
publicConfigs: [
|
||||
{
|
||||
monitors: [
|
||||
{
|
||||
type: 'browser',
|
||||
schedule: '@every 10m',
|
||||
enabled: true,
|
||||
data_stream: { namespace: 'default' },
|
||||
streams: [
|
||||
{
|
||||
data_stream: { dataset: 'browser', type: 'synthetics' },
|
||||
type: 'browser',
|
||||
enabled: true,
|
||||
schedule: '@every 10m',
|
||||
name: 'check if title is present',
|
||||
namespace: 'default',
|
||||
origin: 'project',
|
||||
params: {
|
||||
username: '"********"',
|
||||
password: '"********"',
|
||||
},
|
||||
playwright_options: { headless: true, chromiumSandbox: false },
|
||||
'source.project.content':
|
||||
'UEsDBBQACAAIAON5qVQAAAAAAAAAAAAAAAAfAAAAZXhhbXBsZXMvdG9kb3MvYmFzaWMuam91cm5leS50c22Q0WrDMAxF3/sVF7MHB0LMXlc6RvcN+wDPVWNviW0sdUsp/fe5SSiD7UFCWFfHujIGlpnkybwxFTZfoY/E3hsaLEtwhs9RPNWKDU12zAOxkXRIbN4tB9d9pFOJdO6EN2HMqQguWN9asFBuQVMmJ7jiWNII9fIXrbabdUYr58l9IhwhQQZCYORCTFFUC31Btj21NRc7Mq4Nds+4bDD/pNVgT9F52Jyr2Fa+g75LAPttg8yErk+S9ELpTmVotlVwnfNCuh2lepl3+JflUmSBJ3uggt1v9INW/lHNLKze9dJe1J3QJK8pSvWkm6aTtCet5puq+x63+AFQSwcIAPQ3VfcAAACcAQAAUEsBAi0DFAAIAAgA43mpVAD0N1X3AAAAnAEAAB8AAAAAAAAAAAAgAKSBAAAAAGV4YW1wbGVzL3RvZG9zL2Jhc2ljLmpvdXJuZXkudHNQSwUGAAAAAAEAAQBNAAAARAEAAAAA',
|
||||
screenshots: 'on',
|
||||
'filter_journeys.match': 'check if title is present',
|
||||
ignore_https_errors: false,
|
||||
throttling: { download: 5, upload: 3, latency: 20 },
|
||||
original_space: 'default',
|
||||
fields: {
|
||||
meta: { space_id: 'default' },
|
||||
'monitor.project.name': 'test-project-cb47c83a-45e7-416a-9301-cb476b5bff01',
|
||||
'monitor.project.id': 'test-project-cb47c83a-45e7-416a-9301-cb476b5bff01',
|
||||
},
|
||||
fields_under_root: true,
|
||||
max_attempts: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
license_level: 'trial',
|
||||
output: { hosts: [] },
|
||||
},
|
||||
],
|
||||
privateConfig: null,
|
||||
},
|
||||
decodedCode:
|
||||
'// asset:/Users/vigneshh/elastic/synthetics/examples/todos/basic.journey.ts\nimport { journey, step, expect } from "@elastic/synthetics";\njourney("check if title is present", ({ page, params }) => {\n step("launch app", async () => {\n await page.goto(params.url);\n });\n step("assert title", async () => {\n const header = await page.$("h1");\n expect(await header.textContent()).toBe("todos");\n });\n});\n',
|
||||
});
|
||||
});
|
||||
|
||||
it('inspect http monitor in private location', async () => {
|
||||
const location = await testPrivateLocations.addPrivateLocation();
|
||||
const apiResponse = await monitorTestService.inspectMonitor({
|
||||
..._monitors[0],
|
||||
locations: [
|
||||
{
|
||||
id: location.id,
|
||||
label: location.label,
|
||||
isServiceManaged: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const privateConfig = apiResponse.result.privateConfig!;
|
||||
|
||||
const enabledStream = privateConfig.inputs
|
||||
.find((input) => input.enabled)
|
||||
?.streams.find((stream) => stream.enabled);
|
||||
|
||||
const compiledStream = enabledStream?.compiled_stream;
|
||||
|
||||
delete compiledStream.id;
|
||||
delete compiledStream.processors[0].add_fields.fields.config_id;
|
||||
|
||||
expect(enabledStream?.compiled_stream).eql({
|
||||
__ui: { is_tls_enabled: false },
|
||||
type: 'http',
|
||||
name: 'test-monitor-name',
|
||||
origin: 'ui',
|
||||
'run_from.id': location.id,
|
||||
'run_from.geo.name': 'Test private location 0',
|
||||
enabled: true,
|
||||
urls: 'https://nextjs-test-synthetics.vercel.app/api/users',
|
||||
schedule: '@every 5m',
|
||||
timeout: '180s',
|
||||
max_redirects: 3,
|
||||
max_attempts: 2,
|
||||
proxy_url: 'http://proxy.com',
|
||||
tags: ['tag1', 'tag2'],
|
||||
username: 'test-username',
|
||||
password: 'test',
|
||||
'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'],
|
||||
mode: 'any',
|
||||
ipv4: true,
|
||||
ipv6: true,
|
||||
processors: [
|
||||
{
|
||||
add_fields: {
|
||||
target: '',
|
||||
fields: {
|
||||
meta: { space_id: 'default' },
|
||||
'monitor.fleet_managed': true,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,291 +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 { v4 as uuidv4 } from 'uuid';
|
||||
import expect from 'expect';
|
||||
import {
|
||||
MonitorFields,
|
||||
EncryptedSyntheticsSavedMonitor,
|
||||
ProjectMonitorsRequest,
|
||||
} from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { syntheticsMonitorType } from '@kbn/synthetics-plugin/common/types/saved_objects';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helper/get_fixture_json';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
describe('SyntheticsSuggestions', function () {
|
||||
this.tags('skipCloud');
|
||||
|
||||
const supertest = getService('supertest');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
const security = getService('security');
|
||||
|
||||
const username = 'admin';
|
||||
const roleName = `synthetics_admin`;
|
||||
const password = `${username}-password`;
|
||||
const SPACE_ID = `test-space-${uuidv4()}`;
|
||||
const SPACE_NAME = `test-space-name ${uuidv4()}`;
|
||||
|
||||
let projectMonitors: ProjectMonitorsRequest;
|
||||
let _monitors: MonitorFields[];
|
||||
let monitors: MonitorFields[];
|
||||
|
||||
const setUniqueIds = (request: ProjectMonitorsRequest) => {
|
||||
return {
|
||||
...request,
|
||||
monitors: request.monitors.map((monitor) => ({ ...monitor, id: uuidv4() })),
|
||||
};
|
||||
};
|
||||
|
||||
const deleteMonitor = async (id: string) => {
|
||||
try {
|
||||
await supertest
|
||||
.delete(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}/${id}`)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
const saveMonitor = async (monitor: MonitorFields) => {
|
||||
const res = await supertest
|
||||
.post(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(monitor);
|
||||
|
||||
return res.body as EncryptedSyntheticsSavedMonitor;
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.clean({ types: [syntheticsMonitorType] });
|
||||
await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_ENABLEMENT)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
|
||||
await security.role.create(roleName, {
|
||||
kibana: [
|
||||
{
|
||||
feature: {
|
||||
uptime: ['all'],
|
||||
},
|
||||
spaces: ['*'],
|
||||
},
|
||||
],
|
||||
});
|
||||
await security.user.create(username, {
|
||||
password,
|
||||
roles: [roleName],
|
||||
full_name: 'a kibana user',
|
||||
});
|
||||
const { body } = await supertest
|
||||
.get(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
await Promise.all([
|
||||
(body.monitors as EncryptedSyntheticsSavedMonitor[]).map((monitor) => {
|
||||
return deleteMonitor(monitor.id);
|
||||
}),
|
||||
]);
|
||||
|
||||
_monitors = [getFixtureJson('http_monitor')];
|
||||
projectMonitors = setUniqueIds({
|
||||
monitors: getFixtureJson('project_icmp_monitor')
|
||||
.monitors.slice(0, 2)
|
||||
.map((monitor: any) => ({ ...monitor, privateLocations: [] })),
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
monitors = [];
|
||||
for (let i = 0; i < 20; i++) {
|
||||
monitors.push({
|
||||
..._monitors[0],
|
||||
name: `${_monitors[0].name} ${i}`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await kibanaServer.spaces.delete(SPACE_ID);
|
||||
await security.user.delete(username);
|
||||
await security.role.delete(roleName);
|
||||
});
|
||||
|
||||
it('returns the suggestions', async () => {
|
||||
let savedMonitors: EncryptedSyntheticsSavedMonitor[] = [];
|
||||
try {
|
||||
savedMonitors = await Promise.all(monitors.map(saveMonitor));
|
||||
const project = `test-project-${uuidv4()}`;
|
||||
await supertest
|
||||
.put(
|
||||
`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace(
|
||||
'{projectName}',
|
||||
project
|
||||
)}`
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(projectMonitors)
|
||||
.expect(200);
|
||||
const apiResponse = await supertest.get(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SUGGESTIONS}`);
|
||||
expect(apiResponse.body).toEqual({
|
||||
locations: [
|
||||
{
|
||||
count: 22,
|
||||
label: 'Dev Service',
|
||||
value: 'dev',
|
||||
},
|
||||
],
|
||||
monitorIds: expect.arrayContaining([
|
||||
...monitors.map((monitor) => ({
|
||||
count: 1,
|
||||
label: monitor.name,
|
||||
value: expect.any(String),
|
||||
})),
|
||||
...projectMonitors.monitors.slice(0, 2).map((monitor) => ({
|
||||
count: 1,
|
||||
label: monitor.name,
|
||||
value: expect.any(String),
|
||||
})),
|
||||
]),
|
||||
monitorTypes: [
|
||||
{
|
||||
count: 20,
|
||||
label: 'http',
|
||||
value: 'http',
|
||||
},
|
||||
{
|
||||
count: 2,
|
||||
label: 'icmp',
|
||||
value: 'icmp',
|
||||
},
|
||||
],
|
||||
projects: [
|
||||
{
|
||||
count: 2,
|
||||
label: project,
|
||||
value: project,
|
||||
},
|
||||
],
|
||||
tags: expect.arrayContaining([
|
||||
{
|
||||
count: 21,
|
||||
label: 'tag1',
|
||||
value: 'tag1',
|
||||
},
|
||||
{
|
||||
count: 21,
|
||||
label: 'tag2',
|
||||
value: 'tag2',
|
||||
},
|
||||
{
|
||||
count: 1,
|
||||
label: 'org:google',
|
||||
value: 'org:google',
|
||||
},
|
||||
{
|
||||
count: 1,
|
||||
label: 'service:smtp',
|
||||
value: 'service:smtp',
|
||||
},
|
||||
]),
|
||||
});
|
||||
} finally {
|
||||
await Promise.all(
|
||||
savedMonitors.map((monitor) => {
|
||||
return deleteMonitor(monitor.id);
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('handles query params for projects', async () => {
|
||||
let savedMonitors: EncryptedSyntheticsSavedMonitor[] = [];
|
||||
try {
|
||||
savedMonitors = await Promise.all(monitors.map(saveMonitor));
|
||||
const project = `test-project-${uuidv4()}`;
|
||||
await supertest
|
||||
.put(
|
||||
`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace(
|
||||
'{projectName}',
|
||||
project
|
||||
)}`
|
||||
)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(projectMonitors)
|
||||
.expect(200);
|
||||
|
||||
const apiResponse = await supertest
|
||||
.get(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SUGGESTIONS}`)
|
||||
.query({
|
||||
projects: [project],
|
||||
});
|
||||
|
||||
expect(apiResponse.body).toEqual({
|
||||
locations: [
|
||||
{
|
||||
count: 2,
|
||||
label: 'Dev Service',
|
||||
value: 'dev',
|
||||
},
|
||||
],
|
||||
monitorIds: expect.arrayContaining(
|
||||
projectMonitors.monitors.map((monitor) => ({
|
||||
count: 1,
|
||||
label: monitor.name,
|
||||
value: expect.any(String),
|
||||
}))
|
||||
),
|
||||
monitorTypes: [
|
||||
{
|
||||
count: 2,
|
||||
label: 'icmp',
|
||||
value: 'icmp',
|
||||
},
|
||||
],
|
||||
projects: [
|
||||
{
|
||||
count: 2,
|
||||
label: project,
|
||||
value: project,
|
||||
},
|
||||
],
|
||||
tags: expect.arrayContaining([
|
||||
{
|
||||
count: 1,
|
||||
label: 'tag1',
|
||||
value: 'tag1',
|
||||
},
|
||||
{
|
||||
count: 1,
|
||||
label: 'tag2',
|
||||
value: 'tag2',
|
||||
},
|
||||
{
|
||||
count: 1,
|
||||
label: 'org:google',
|
||||
value: 'org:google',
|
||||
},
|
||||
{
|
||||
count: 1,
|
||||
label: 'service:smtp',
|
||||
value: 'service:smtp',
|
||||
},
|
||||
]),
|
||||
});
|
||||
} finally {
|
||||
await Promise.all(
|
||||
savedMonitors.map((monitor) => {
|
||||
return deleteMonitor(monitor.id);
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
|
@ -21,7 +21,16 @@ import { getFixtureJson } from './helper/get_fixture_json';
|
|||
import { PrivateLocationTestService } from './services/private_location_test_service';
|
||||
import { comparePolicies, getTestSyntheticsPolicy } from './sample_data/test_policy';
|
||||
import { addMonitorAPIHelper, omitMonitorKeys } from './add_monitor';
|
||||
import { LOCAL_LOCATION } from './get_filters';
|
||||
|
||||
export const LOCAL_LOCATION = {
|
||||
id: 'dev',
|
||||
label: 'Dev Service',
|
||||
geo: {
|
||||
lat: 0,
|
||||
lon: 0,
|
||||
},
|
||||
isServiceManaged: true,
|
||||
};
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
describe('SyncGlobalParams', function () {
|
||||
|
|
|
@ -1,83 +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 { MonitorFields } from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import expect from '@kbn/expect';
|
||||
import { omit } from 'lodash';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helper/get_fixture_json';
|
||||
import { SyntheticsMonitorTestService } from './services/synthetics_monitor_test_service';
|
||||
import { LOCAL_LOCATION } from './get_filters';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
describe('RunTestManually', function () {
|
||||
this.tags('skipCloud');
|
||||
|
||||
const supertest = getService('supertest');
|
||||
const supertestWithoutAuth = getService('supertestWithoutAuth');
|
||||
|
||||
const monitorTestService = new SyntheticsMonitorTestService(getService);
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
|
||||
let newMonitor: MonitorFields;
|
||||
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_ENABLEMENT)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
newMonitor = getFixtureJson('http_monitor');
|
||||
});
|
||||
|
||||
it('runs test manually', async () => {
|
||||
const resp = await monitorTestService.addMonitor(newMonitor);
|
||||
|
||||
const res = await supertest
|
||||
.post(SYNTHETICS_API_URLS.TRIGGER_MONITOR + `/${resp.id}`)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
|
||||
const result = res.body;
|
||||
expect(typeof result.testRunId).to.eql('string');
|
||||
expect(typeof result.configId).to.eql('string');
|
||||
expect(result.schedule).to.eql({ number: '5', unit: 'm' });
|
||||
expect(result.locations).to.eql([LOCAL_LOCATION]);
|
||||
|
||||
expect(omit(result.monitor, ['id', 'config_id'])).to.eql(
|
||||
omit(newMonitor, ['id', 'config_id'])
|
||||
);
|
||||
});
|
||||
|
||||
it('works in non default space', async () => {
|
||||
const { username, SPACE_ID, password } = await monitorTestService.addsNewSpace();
|
||||
|
||||
const resp = await supertestWithoutAuth
|
||||
.post(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
|
||||
.auth(username, password)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(newMonitor)
|
||||
.expect(200);
|
||||
|
||||
const res = await supertest
|
||||
.post(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.TRIGGER_MONITOR}/${resp.body.id}`)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
|
||||
const result = res.body;
|
||||
expect(typeof result.testRunId).to.eql('string');
|
||||
expect(typeof result.configId).to.eql('string');
|
||||
expect(result.schedule).to.eql({ number: '5', unit: 'm' });
|
||||
expect(result.locations).to.eql([LOCAL_LOCATION]);
|
||||
|
||||
expect(omit(result.monitor, ['id', 'config_id'])).to.eql(
|
||||
omit(newMonitor, ['id', 'config_id'])
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -6,19 +6,16 @@
|
|||
*/
|
||||
import expect from '@kbn/expect';
|
||||
import { RoleCredentials, SamlAuthProviderType } from '@kbn/ftr-common-functional-services';
|
||||
import epct from 'expect';
|
||||
import moment from 'moment/moment';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { omit, omitBy } from 'lodash';
|
||||
import {
|
||||
ConfigKey,
|
||||
MonitorTypeEnum,
|
||||
HTTPFields,
|
||||
PrivateLocation,
|
||||
} from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { formatKibanaNamespace } from '@kbn/synthetics-plugin/common/formatters';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import { DEFAULT_FIELDS } from '@kbn/synthetics-plugin/common/constants/monitor_defaults';
|
||||
import {
|
||||
removeMonitorEmptyValues,
|
||||
transformPublicKeys,
|
||||
|
@ -73,6 +70,7 @@ export const omitMonitorKeys = (monitor: any) => {
|
|||
|
||||
export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
||||
describe('AddNewMonitorsUI', function () {
|
||||
this.tags(['skipCloud', 'skipMKI']);
|
||||
const supertestAPI = getService('supertestWithoutAuth');
|
||||
const samlAuth = getService('samlAuth');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
|
@ -118,108 +116,6 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
expect(apiResponse).eql(omitMonitorKeys(newMonitor));
|
||||
});
|
||||
|
||||
it('returns bad request if payload is invalid for HTTP monitor', async () => {
|
||||
// Delete a required property to make payload invalid
|
||||
const newMonitor = { ...httpMonitorJson, 'check.request.headers': null };
|
||||
await addMonitorAPI(newMonitor, 400);
|
||||
});
|
||||
|
||||
it('returns bad request if monitor type is invalid', async () => {
|
||||
const newMonitor = { ...httpMonitorJson, type: 'invalid-data-steam' };
|
||||
|
||||
const apiResponse = await addMonitorAPI(newMonitor, 400);
|
||||
|
||||
expect(apiResponse.message).eql('Invalid value "invalid-data-steam" supplied to "type"');
|
||||
});
|
||||
|
||||
it('can create valid monitors without all defaults', async () => {
|
||||
// Delete a required property to make payload invalid
|
||||
const newMonitor = {
|
||||
name: 'Sample name',
|
||||
type: 'http',
|
||||
urls: 'https://elastic.co',
|
||||
locations: [privateLocation],
|
||||
};
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
expect(apiResponse).eql(
|
||||
omitMonitorKeys({
|
||||
...DEFAULT_FIELDS[MonitorTypeEnum.HTTP],
|
||||
...newMonitor,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('can disable retries', async () => {
|
||||
const maxAttempts = 1;
|
||||
const newMonitor = {
|
||||
max_attempts: maxAttempts,
|
||||
urls: 'https://elastic.co',
|
||||
name: `Sample name ${uuidv4()}`,
|
||||
type: 'http',
|
||||
locations: [privateLocation],
|
||||
};
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
epct(apiResponse).toEqual(epct.objectContaining({ retest_on_failure: false }));
|
||||
});
|
||||
|
||||
it('can enable retries with max attempts', async () => {
|
||||
const maxAttempts = 2;
|
||||
const newMonitor = {
|
||||
max_attempts: maxAttempts,
|
||||
urls: 'https://elastic.co',
|
||||
name: `Sample name ${uuidv4()}`,
|
||||
type: 'http',
|
||||
locations: [privateLocation],
|
||||
};
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
epct(apiResponse).toEqual(epct.objectContaining({ retest_on_failure: true }));
|
||||
});
|
||||
|
||||
it('can enable retries', async () => {
|
||||
const newMonitor = {
|
||||
retest_on_failure: false,
|
||||
urls: 'https://elastic.co',
|
||||
name: `Sample name ${uuidv4()}`,
|
||||
type: 'http',
|
||||
locations: [privateLocation],
|
||||
};
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
epct(apiResponse).toEqual(epct.objectContaining({ retest_on_failure: false }));
|
||||
});
|
||||
|
||||
it('cannot create a invalid monitor without a monitor type', async () => {
|
||||
// Delete a required property to make payload invalid
|
||||
const newMonitor = {
|
||||
name: 'Sample name',
|
||||
url: 'https://elastic.co',
|
||||
locations: [privateLocation],
|
||||
};
|
||||
await addMonitorAPI(newMonitor, 400);
|
||||
});
|
||||
|
||||
it('omits 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: [privateLocation],
|
||||
};
|
||||
const apiResponse = await addMonitorAPI(newMonitor, 400);
|
||||
expect(apiResponse.message).not.to.have.keys(
|
||||
'Invalid monitor key(s) for http type: unknownKey","attributes":{"details":"Invalid monitor key(s) for http type: unknownKey'
|
||||
);
|
||||
});
|
||||
|
||||
it('sets namespace to Kibana space when not set to a custom namespace', async () => {
|
||||
const SPACE_ID = `test-space-${uuidv4()}`;
|
||||
const SPACE_NAME = `test-space-name ${uuidv4()}`;
|
||||
|
@ -247,58 +143,5 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
await deleteMonitor(monitorId, 200, SPACE_ID);
|
||||
}
|
||||
});
|
||||
|
||||
it('preserves the passed namespace when preserve_namespace is passed', async () => {
|
||||
const SPACE_ID = `test-space-${uuidv4()}`;
|
||||
const SPACE_NAME = `test-space-name ${uuidv4()}`;
|
||||
privateLocation = await privateLocationsService.addTestPrivateLocation(SPACE_ID);
|
||||
const monitor = {
|
||||
...httpMonitorJson,
|
||||
[ConfigKey.NAMESPACE]: 'default',
|
||||
locations: [privateLocation],
|
||||
};
|
||||
let monitorId = '';
|
||||
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
|
||||
|
||||
try {
|
||||
const apiResponse = await supertestAPI
|
||||
.post(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
|
||||
.query({ preserve_namespace: true })
|
||||
.set(editorRoleAuthc.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.send(monitor)
|
||||
.expect(200);
|
||||
monitorId = apiResponse.body.id;
|
||||
expect(apiResponse.body[ConfigKey.NAMESPACE]).eql('default');
|
||||
} finally {
|
||||
await deleteMonitor(monitorId, 200, SPACE_ID);
|
||||
}
|
||||
});
|
||||
|
||||
it('sets namespace to custom namespace when set', async () => {
|
||||
const SPACE_ID = `test-space-${uuidv4()}`;
|
||||
const SPACE_NAME = `test-space-name ${uuidv4()}`;
|
||||
privateLocation = await privateLocationsService.addTestPrivateLocation(SPACE_ID);
|
||||
const monitor = {
|
||||
...httpMonitorJson,
|
||||
locations: [privateLocation],
|
||||
};
|
||||
let monitorId = '';
|
||||
|
||||
try {
|
||||
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
|
||||
|
||||
const apiResponse = await supertestAPI
|
||||
.post(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
|
||||
.set(editorRoleAuthc.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.send(monitor)
|
||||
.expect(200);
|
||||
monitorId = apiResponse.body.id;
|
||||
expect(apiResponse.body[ConfigKey.NAMESPACE]).eql(monitor[ConfigKey.NAMESPACE]);
|
||||
} finally {
|
||||
await deleteMonitor(monitorId, 200, SPACE_ID);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,8 +14,10 @@ import {
|
|||
HTTPFields,
|
||||
PrivateLocation,
|
||||
ServiceLocation,
|
||||
MonitorTypeEnum,
|
||||
} from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import { DEFAULT_FIELDS } from '@kbn/synthetics-plugin/common/constants/monitor_defaults';
|
||||
import { omit } from 'lodash';
|
||||
import { PackagePolicy } from '@kbn/fleet-plugin/common';
|
||||
import expect from '@kbn/expect';
|
||||
|
@ -489,7 +491,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
...httpMonitorJson,
|
||||
name: `Test monitor ${uuidv4()}`,
|
||||
[ConfigKey.NAMESPACE]: 'default',
|
||||
locations: [privateLocation],
|
||||
private_locations: [privateLocation.id],
|
||||
};
|
||||
|
||||
try {
|
||||
|
@ -497,8 +499,10 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.set(editorUser.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.send(monitor)
|
||||
.expect(200);
|
||||
.send(monitor);
|
||||
|
||||
expect(apiResponse.status).eql(200, JSON.stringify(apiResponse.body));
|
||||
|
||||
monitorId = apiResponse.body.id;
|
||||
|
||||
const policyResponse = await supertestWithAuth.get(
|
||||
|
@ -526,5 +530,160 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
await deleteMonitor(monitorId);
|
||||
}
|
||||
});
|
||||
|
||||
it('returns bad request if payload is invalid for HTTP monitor', async () => {
|
||||
// Delete a required property to make payload invalid
|
||||
const newMonitor = { ...httpMonitorJson, 'check.request.headers': null };
|
||||
await addMonitorAPI(newMonitor, 400);
|
||||
});
|
||||
|
||||
it('returns bad request if monitor type is invalid', async () => {
|
||||
const newMonitor = { ...httpMonitorJson, type: 'invalid-data-steam' };
|
||||
|
||||
const apiResponse = await addMonitorAPI(newMonitor, 400);
|
||||
|
||||
expect(apiResponse.message).eql('Invalid value "invalid-data-steam" supplied to "type"');
|
||||
});
|
||||
|
||||
it('can create valid monitors without all defaults', async () => {
|
||||
// Delete a required property to make payload invalid
|
||||
const newMonitor = {
|
||||
name: 'Sample name',
|
||||
type: 'http',
|
||||
urls: 'https://elastic.co',
|
||||
locations: [privateLocations[0]],
|
||||
};
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
expect(apiResponse).eql(
|
||||
omitMonitorKeys({
|
||||
...DEFAULT_FIELDS[MonitorTypeEnum.HTTP],
|
||||
...newMonitor,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('can disable retries', async () => {
|
||||
const maxAttempts = 1;
|
||||
const newMonitor = {
|
||||
max_attempts: maxAttempts,
|
||||
urls: 'https://elastic.co',
|
||||
name: `Sample name ${uuidv4()}`,
|
||||
type: 'http',
|
||||
locations: [privateLocations[0]],
|
||||
};
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
rawExpect(apiResponse).toEqual(rawExpect.objectContaining({ retest_on_failure: false }));
|
||||
});
|
||||
|
||||
it('can enable retries with max attempts', async () => {
|
||||
const maxAttempts = 2;
|
||||
const newMonitor = {
|
||||
max_attempts: maxAttempts,
|
||||
urls: 'https://elastic.co',
|
||||
name: `Sample name ${uuidv4()}`,
|
||||
type: 'http',
|
||||
locations: [privateLocations[0]],
|
||||
};
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
rawExpect(apiResponse).toEqual(rawExpect.objectContaining({ retest_on_failure: true }));
|
||||
});
|
||||
|
||||
it('can enable retries', async () => {
|
||||
const newMonitor = {
|
||||
retest_on_failure: false,
|
||||
urls: 'https://elastic.co',
|
||||
name: `Sample name ${uuidv4()}`,
|
||||
type: 'http',
|
||||
locations: [privateLocations[0]],
|
||||
};
|
||||
|
||||
const { body: apiResponse } = await addMonitorAPI(newMonitor);
|
||||
|
||||
rawExpect(apiResponse).toEqual(rawExpect.objectContaining({ retest_on_failure: false }));
|
||||
});
|
||||
|
||||
it('cannot create a invalid monitor without a monitor type', async () => {
|
||||
// Delete a required property to make payload invalid
|
||||
const newMonitor = {
|
||||
name: 'Sample name',
|
||||
url: 'https://elastic.co',
|
||||
locations: [privateLocations[0]],
|
||||
};
|
||||
await addMonitorAPI(newMonitor, 400);
|
||||
});
|
||||
|
||||
it('omits 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: [privateLocations[0]],
|
||||
};
|
||||
const apiResponse = await addMonitorAPI(newMonitor, 400);
|
||||
expect(apiResponse.message).not.to.have.keys(
|
||||
'Invalid monitor key(s) for http type: unknownKey","attributes":{"details":"Invalid monitor key(s) for http type: unknownKey'
|
||||
);
|
||||
});
|
||||
|
||||
it('preserves the passed namespace when preserve_namespace is passed', async () => {
|
||||
const SPACE_ID = `test-space-${uuidv4()}`;
|
||||
const SPACE_NAME = `test-space-name ${uuidv4()}`;
|
||||
const privateLocation = await testPrivateLocations.addTestPrivateLocation(SPACE_ID);
|
||||
const monitor = {
|
||||
...httpMonitorJson,
|
||||
[ConfigKey.NAMESPACE]: 'default',
|
||||
locations: [privateLocation],
|
||||
};
|
||||
let monitorId = '';
|
||||
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
|
||||
|
||||
try {
|
||||
const apiResponse = await supertestWithoutAuth
|
||||
.post(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
|
||||
.query({ preserve_namespace: true })
|
||||
.set(editorUser.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.send(monitor)
|
||||
.expect(200);
|
||||
monitorId = apiResponse.body.id;
|
||||
expect(apiResponse.body[ConfigKey.NAMESPACE]).eql('default');
|
||||
} finally {
|
||||
await deleteMonitor(monitorId, 200, SPACE_ID);
|
||||
}
|
||||
});
|
||||
|
||||
it('sets namespace to custom namespace when set', async () => {
|
||||
const SPACE_ID = `test-space-${uuidv4()}`;
|
||||
const SPACE_NAME = `test-space-name ${uuidv4()}`;
|
||||
const privateLocation = await testPrivateLocations.addTestPrivateLocation(SPACE_ID);
|
||||
const monitor = {
|
||||
...httpMonitorJson,
|
||||
locations: [privateLocation],
|
||||
};
|
||||
let monitorId = '';
|
||||
|
||||
try {
|
||||
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
|
||||
|
||||
const apiResponse = await supertestWithoutAuth
|
||||
.post(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
|
||||
.set(editorUser.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.send(monitor)
|
||||
.expect(200);
|
||||
monitorId = apiResponse.body.id;
|
||||
expect(apiResponse.body[ConfigKey.NAMESPACE]).eql(monitor[ConfigKey.NAMESPACE]);
|
||||
} finally {
|
||||
await deleteMonitor(monitorId, 200, SPACE_ID);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -5,24 +5,20 @@
|
|||
* 2.0.
|
||||
*/
|
||||
import expect from '@kbn/expect';
|
||||
import rawExpect from 'expect';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { RoleCredentials } from '@kbn/ftr-common-functional-services';
|
||||
import { PrivateLocation } from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { DEFAULT_FIELDS } from '@kbn/synthetics-plugin/common/constants/monitor_defaults';
|
||||
import { LOCATION_REQUIRED_ERROR } from '@kbn/synthetics-plugin/server/routes/monitor_cruds/monitor_validation';
|
||||
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';
|
||||
import { addMonitorAPIHelper, omitMonitorKeys } from './create_monitor';
|
||||
import { PrivateLocationTestService } from '../../../services/synthetics_private_location';
|
||||
import { LOCAL_PUBLIC_LOCATION } from './helpers/location';
|
||||
|
||||
export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
||||
describe('AddNewMonitorsPublicAPI', function () {
|
||||
describe('AddNewMonitorsPublicAPI - Public locations', function () {
|
||||
this.tags(['skipCloud', 'skipMKI']);
|
||||
const supertestAPI = getService('supertestWithoutAuth');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
const samlAuth = getService('samlAuth');
|
||||
let editorUser: RoleCredentials;
|
||||
let privateLocation: PrivateLocation;
|
||||
const privateLocationTestService = new PrivateLocationTestService(getService);
|
||||
|
||||
async function addMonitorAPI(monitor: any, statusCode: number = 200) {
|
||||
return await addMonitorAPIHelper(supertestAPI, monitor, statusCode, editorUser, samlAuth);
|
||||
|
@ -31,73 +27,21 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
before(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
editorUser = await samlAuth.createM2mApiKeyWithRoleScope('editor');
|
||||
privateLocation = await privateLocationTestService.addTestPrivateLocation();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
});
|
||||
|
||||
it('should return error for empty monitor', async function () {
|
||||
const { message } = await addMonitorAPI({}, 400);
|
||||
expect(message).eql('Invalid value "undefined" supplied to "type"');
|
||||
});
|
||||
|
||||
it('return error if no location specified', async () => {
|
||||
const { message } = await addMonitorAPI({ type: 'http' }, 400);
|
||||
expect(message).eql(LOCATION_REQUIRED_ERROR);
|
||||
});
|
||||
|
||||
it('return error if invalid location specified', async () => {
|
||||
const { message } = await addMonitorAPI({ type: 'http', locations: ['mars'] }, 400);
|
||||
rawExpect(message).toContain(
|
||||
"Invalid locations specified. Elastic managed Location(s) 'mars' not found."
|
||||
);
|
||||
});
|
||||
|
||||
it('return error if invalid private location specified', async () => {
|
||||
const { message } = await addMonitorAPI(
|
||||
{
|
||||
type: 'http',
|
||||
locations: ['mars'],
|
||||
privateLocations: ['moon'],
|
||||
},
|
||||
400
|
||||
);
|
||||
expect(message).eql('Invalid monitor key(s) for http type: privateLocations');
|
||||
|
||||
const result = await addMonitorAPI(
|
||||
{
|
||||
type: 'http',
|
||||
locations: ['mars'],
|
||||
private_locations: ['moon'],
|
||||
},
|
||||
400
|
||||
);
|
||||
rawExpect(result.message).toContain("Private Location(s) 'moon' not found.");
|
||||
});
|
||||
|
||||
it('return error for origin project', async () => {
|
||||
const { message } = await addMonitorAPI(
|
||||
{
|
||||
type: 'http',
|
||||
locations: ['dev'],
|
||||
url: 'https://www.google.com',
|
||||
origin: 'project',
|
||||
},
|
||||
400
|
||||
);
|
||||
expect(message).eql('Unsupported origin type project, only ui type is supported via API.');
|
||||
});
|
||||
|
||||
describe('HTTP Monitor', () => {
|
||||
const defaultFields = DEFAULT_FIELDS.http;
|
||||
|
||||
it('return error empty http', async () => {
|
||||
const { message, attributes } = await addMonitorAPI(
|
||||
{
|
||||
type: 'http',
|
||||
locations: [],
|
||||
private_locations: [privateLocation.id],
|
||||
locations: [LOCAL_PUBLIC_LOCATION.id],
|
||||
private_locations: [],
|
||||
},
|
||||
400
|
||||
);
|
||||
|
@ -113,7 +57,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
it('base http monitor', async () => {
|
||||
const monitor = {
|
||||
type: 'http',
|
||||
private_locations: [privateLocation.id],
|
||||
locations: [LOCAL_PUBLIC_LOCATION.id],
|
||||
url: 'https://www.google.com',
|
||||
};
|
||||
const { body: result } = await addMonitorAPI(monitor);
|
||||
|
@ -122,7 +66,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [privateLocation],
|
||||
locations: [LOCAL_PUBLIC_LOCATION],
|
||||
name: 'https://www.google.com',
|
||||
})
|
||||
);
|
||||
|
@ -132,7 +76,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
const name = `test name ${uuidv4()}`;
|
||||
const monitor = {
|
||||
type: 'http',
|
||||
private_locations: [privateLocation.id],
|
||||
locations: [LOCAL_PUBLIC_LOCATION.id],
|
||||
url: 'https://www.google.com',
|
||||
name,
|
||||
retest_on_failure: true,
|
||||
|
@ -143,7 +87,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [privateLocation],
|
||||
locations: [LOCAL_PUBLIC_LOCATION],
|
||||
name,
|
||||
retest_on_failure: true,
|
||||
})
|
||||
|
@ -154,7 +98,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
const name = `test name ${uuidv4()}`;
|
||||
const monitor = {
|
||||
type: 'http',
|
||||
private_locations: [privateLocation.id],
|
||||
locations: [LOCAL_PUBLIC_LOCATION.id],
|
||||
url: 'https://www.google.com',
|
||||
name,
|
||||
retest_on_failure: false,
|
||||
|
@ -165,7 +109,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [privateLocation],
|
||||
locations: [LOCAL_PUBLIC_LOCATION],
|
||||
name,
|
||||
max_attempts: 1,
|
||||
retest_on_failure: undefined, // this key is not part of the SO and should not be defined
|
||||
|
@ -180,7 +124,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
it('base tcp monitor', async () => {
|
||||
const monitor = {
|
||||
type: 'tcp',
|
||||
private_locations: [privateLocation.id],
|
||||
locations: [LOCAL_PUBLIC_LOCATION.id],
|
||||
host: 'https://www.google.com/',
|
||||
};
|
||||
const { body: result } = await addMonitorAPI(monitor);
|
||||
|
@ -189,7 +133,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [privateLocation],
|
||||
locations: [LOCAL_PUBLIC_LOCATION],
|
||||
name: 'https://www.google.com/',
|
||||
})
|
||||
);
|
||||
|
@ -202,7 +146,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
it('base icmp monitor', async () => {
|
||||
const monitor = {
|
||||
type: 'icmp',
|
||||
private_locations: [privateLocation.id],
|
||||
locations: [LOCAL_PUBLIC_LOCATION.id],
|
||||
host: 'https://8.8.8.8',
|
||||
};
|
||||
const { body: result } = await addMonitorAPI(monitor);
|
||||
|
@ -211,7 +155,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [privateLocation],
|
||||
locations: [LOCAL_PUBLIC_LOCATION],
|
||||
name: 'https://8.8.8.8',
|
||||
})
|
||||
);
|
||||
|
@ -224,7 +168,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
it('empty browser monitor', async () => {
|
||||
const monitor = {
|
||||
type: 'browser',
|
||||
private_locations: [privateLocation.id],
|
||||
locations: [LOCAL_PUBLIC_LOCATION.id],
|
||||
name: 'simple journey',
|
||||
};
|
||||
const result = await addMonitorAPI(monitor, 400);
|
||||
|
@ -243,7 +187,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
it('base browser monitor', async () => {
|
||||
const monitor = {
|
||||
type: 'browser',
|
||||
private_locations: [privateLocation.id],
|
||||
locations: [LOCAL_PUBLIC_LOCATION.id],
|
||||
name: 'simple journey',
|
||||
'source.inline.script': 'step("simple journey", async () => {});',
|
||||
};
|
||||
|
@ -253,7 +197,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [privateLocation],
|
||||
locations: [LOCAL_PUBLIC_LOCATION],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -261,7 +205,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
it('base browser monitor with inline_script', async () => {
|
||||
const monitor = {
|
||||
type: 'browser',
|
||||
private_locations: [privateLocation.id],
|
||||
locations: [LOCAL_PUBLIC_LOCATION.id],
|
||||
name: 'simple journey inline_script',
|
||||
inline_script: 'step("simple journey", async () => {});',
|
||||
};
|
||||
|
@ -271,7 +215,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [privateLocation],
|
||||
locations: [LOCAL_PUBLIC_LOCATION],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
|
|
@ -5,26 +5,33 @@
|
|||
* 2.0.
|
||||
*/
|
||||
import expect from '@kbn/expect';
|
||||
import rawExpect from 'expect';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { RoleCredentials } from '@kbn/ftr-common-functional-services';
|
||||
import { PrivateLocation } from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { DEFAULT_FIELDS } from '@kbn/synthetics-plugin/common/constants/monitor_defaults';
|
||||
import { LOCATION_REQUIRED_ERROR } from '@kbn/synthetics-plugin/server/routes/monitor_cruds/monitor_validation';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { addMonitorAPIHelper, omitMonitorKeys } from './add_monitor';
|
||||
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';
|
||||
import { addMonitorAPIHelper, omitMonitorKeys } from './create_monitor';
|
||||
import { PrivateLocationTestService } from '../../../services/synthetics_private_location';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
describe('AddNewMonitorsPublicAPI', function () {
|
||||
this.tags('skipCloud');
|
||||
|
||||
const supertestAPI = getService('supertest');
|
||||
export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
||||
describe('AddNewMonitorsPublicAPI - Private locations', function () {
|
||||
const supertestAPI = getService('supertestWithoutAuth');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
const samlAuth = getService('samlAuth');
|
||||
let editorUser: RoleCredentials;
|
||||
let privateLocation: PrivateLocation;
|
||||
const privateLocationTestService = new PrivateLocationTestService(getService);
|
||||
|
||||
async function addMonitorAPI(monitor: any, statusCode: number = 200) {
|
||||
return await addMonitorAPIHelper(supertestAPI, monitor, statusCode);
|
||||
return await addMonitorAPIHelper(supertestAPI, monitor, statusCode, editorUser, samlAuth);
|
||||
}
|
||||
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
editorUser = await samlAuth.createM2mApiKeyWithRoleScope('editor');
|
||||
privateLocation = await privateLocationTestService.addTestPrivateLocation();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
@ -43,8 +50,8 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
|
||||
it('return error if invalid location specified', async () => {
|
||||
const { message } = await addMonitorAPI({ type: 'http', locations: ['mars'] }, 400);
|
||||
expect(message).eql(
|
||||
"Invalid locations specified. Elastic managed Location(s) 'mars' not found. Available locations are 'dev|dev2'"
|
||||
rawExpect(message).toContain(
|
||||
"Invalid locations specified. Elastic managed Location(s) 'mars' not found."
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -67,21 +74,9 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
},
|
||||
400
|
||||
);
|
||||
expect(result.message).eql(
|
||||
"Invalid locations specified. Elastic managed Location(s) 'mars' not found. Available locations are 'dev|dev2' Private Location(s) 'moon' not found. No private location available to use."
|
||||
);
|
||||
rawExpect(result.message).toContain("Private Location(s) 'moon' not found.");
|
||||
});
|
||||
|
||||
const localLoc = {
|
||||
id: 'dev',
|
||||
label: 'Dev Service',
|
||||
geo: {
|
||||
lat: 0,
|
||||
lon: 0,
|
||||
},
|
||||
isServiceManaged: true,
|
||||
};
|
||||
|
||||
it('return error for origin project', async () => {
|
||||
const { message } = await addMonitorAPI(
|
||||
{
|
||||
|
@ -101,7 +96,8 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
const { message, attributes } = await addMonitorAPI(
|
||||
{
|
||||
type: 'http',
|
||||
locations: ['dev'],
|
||||
locations: [],
|
||||
private_locations: [privateLocation.id],
|
||||
},
|
||||
400
|
||||
);
|
||||
|
@ -117,7 +113,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
it('base http monitor', async () => {
|
||||
const monitor = {
|
||||
type: 'http',
|
||||
locations: ['dev'],
|
||||
private_locations: [privateLocation.id],
|
||||
url: 'https://www.google.com',
|
||||
};
|
||||
const { body: result } = await addMonitorAPI(monitor);
|
||||
|
@ -126,7 +122,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [localLoc],
|
||||
locations: [privateLocation],
|
||||
name: 'https://www.google.com',
|
||||
})
|
||||
);
|
||||
|
@ -136,7 +132,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
const name = `test name ${uuidv4()}`;
|
||||
const monitor = {
|
||||
type: 'http',
|
||||
locations: ['dev'],
|
||||
private_locations: [privateLocation.id],
|
||||
url: 'https://www.google.com',
|
||||
name,
|
||||
retest_on_failure: true,
|
||||
|
@ -147,7 +143,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [localLoc],
|
||||
locations: [privateLocation],
|
||||
name,
|
||||
retest_on_failure: true,
|
||||
})
|
||||
|
@ -158,7 +154,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
const name = `test name ${uuidv4()}`;
|
||||
const monitor = {
|
||||
type: 'http',
|
||||
locations: ['dev'],
|
||||
private_locations: [privateLocation.id],
|
||||
url: 'https://www.google.com',
|
||||
name,
|
||||
retest_on_failure: false,
|
||||
|
@ -169,7 +165,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [localLoc],
|
||||
locations: [privateLocation],
|
||||
name,
|
||||
max_attempts: 1,
|
||||
retest_on_failure: undefined, // this key is not part of the SO and should not be defined
|
||||
|
@ -184,7 +180,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
it('base tcp monitor', async () => {
|
||||
const monitor = {
|
||||
type: 'tcp',
|
||||
locations: ['dev'],
|
||||
private_locations: [privateLocation.id],
|
||||
host: 'https://www.google.com/',
|
||||
};
|
||||
const { body: result } = await addMonitorAPI(monitor);
|
||||
|
@ -193,7 +189,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [localLoc],
|
||||
locations: [privateLocation],
|
||||
name: 'https://www.google.com/',
|
||||
})
|
||||
);
|
||||
|
@ -206,7 +202,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
it('base icmp monitor', async () => {
|
||||
const monitor = {
|
||||
type: 'icmp',
|
||||
locations: ['dev'],
|
||||
private_locations: [privateLocation.id],
|
||||
host: 'https://8.8.8.8',
|
||||
};
|
||||
const { body: result } = await addMonitorAPI(monitor);
|
||||
|
@ -215,7 +211,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [localLoc],
|
||||
locations: [privateLocation],
|
||||
name: 'https://8.8.8.8',
|
||||
})
|
||||
);
|
||||
|
@ -228,7 +224,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
it('empty browser monitor', async () => {
|
||||
const monitor = {
|
||||
type: 'browser',
|
||||
locations: ['dev'],
|
||||
private_locations: [privateLocation.id],
|
||||
name: 'simple journey',
|
||||
};
|
||||
const result = await addMonitorAPI(monitor, 400);
|
||||
|
@ -247,7 +243,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
it('base browser monitor', async () => {
|
||||
const monitor = {
|
||||
type: 'browser',
|
||||
locations: ['dev'],
|
||||
private_locations: [privateLocation.id],
|
||||
name: 'simple journey',
|
||||
'source.inline.script': 'step("simple journey", async () => {});',
|
||||
};
|
||||
|
@ -257,7 +253,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [localLoc],
|
||||
locations: [privateLocation],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -265,7 +261,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
it('base browser monitor with inline_script', async () => {
|
||||
const monitor = {
|
||||
type: 'browser',
|
||||
locations: ['dev'],
|
||||
private_locations: [privateLocation.id],
|
||||
name: 'simple journey inline_script',
|
||||
inline_script: 'step("simple journey", async () => {});',
|
||||
};
|
||||
|
@ -275,7 +271,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [localLoc],
|
||||
locations: [privateLocation],
|
||||
})
|
||||
);
|
||||
});
|
|
@ -12,7 +12,6 @@ import {
|
|||
EncryptedSyntheticsSavedMonitor,
|
||||
HTTPFields,
|
||||
MonitorFields,
|
||||
PrivateLocation,
|
||||
} from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { RoleCredentials } from '@kbn/ftr-common-functional-services';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
|
@ -20,24 +19,21 @@ import expect from '@kbn/expect';
|
|||
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helpers/get_fixture_json';
|
||||
import { omitResponseTimestamps, omitEmptyValues } from './helpers/monitor';
|
||||
import { PrivateLocationTestService } from '../../../services/synthetics_private_location';
|
||||
import { SyntheticsMonitorTestService } from '../../../services/synthetics_monitor';
|
||||
import { LOCAL_PUBLIC_LOCATION } from './helpers/location';
|
||||
|
||||
export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
||||
describe('EditMonitorAPI', function () {
|
||||
describe('EditMonitorAPI - Public Location', function () {
|
||||
this.tags(['skipCloud', 'skipMKI']);
|
||||
const supertestWithAuth = getService('supertest');
|
||||
const supertest = getService('supertestWithoutAuth');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
const samlAuth = getService('samlAuth');
|
||||
|
||||
const testPrivateLocations = new PrivateLocationTestService(getService);
|
||||
const monitorTestService = new SyntheticsMonitorTestService(getService);
|
||||
|
||||
let _httpMonitorJson: HTTPFields;
|
||||
let httpMonitorJson: HTTPFields;
|
||||
let testPolicyId = '';
|
||||
let editorUser: RoleCredentials;
|
||||
let privateLocations: PrivateLocation[];
|
||||
|
||||
const saveMonitor = async (monitor: MonitorFields, spaceId?: string) => {
|
||||
const apiURL = spaceId
|
||||
|
@ -82,24 +78,15 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
.set(samlAuth.getInternalRequestHeader())
|
||||
.expect(200);
|
||||
|
||||
const testPolicyName = 'Fleet test server policy' + Date.now();
|
||||
const apiResponse = await testPrivateLocations.addFleetPolicy(testPolicyName);
|
||||
testPolicyId = apiResponse.body.item.id;
|
||||
privateLocations = await testPrivateLocations.setTestLocations([testPolicyId]);
|
||||
_httpMonitorJson = getFixtureJson('http_monitor');
|
||||
httpMonitorJson = getFixtureJson('http_monitor');
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
httpMonitorJson = { ..._httpMonitorJson, locations: [privateLocations[0]] };
|
||||
});
|
||||
|
||||
it('edits the monitor', async () => {
|
||||
const newMonitor = httpMonitorJson;
|
||||
|
||||
const savedMonitor = await saveMonitor(newMonitor as MonitorFields);
|
||||
const monitorId = savedMonitor[ConfigKey.CONFIG_ID];
|
||||
|
||||
|
@ -114,7 +101,6 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
const updates: Partial<HTTPFields> = {
|
||||
[ConfigKey.URLS]: 'https://modified-host.com',
|
||||
[ConfigKey.NAME]: 'Modified name',
|
||||
[ConfigKey.LOCATIONS]: [privateLocations[0]],
|
||||
[ConfigKey.REQUEST_HEADERS_CHECK]: {
|
||||
sampleHeader2: 'sampleValue2',
|
||||
},
|
||||
|
@ -165,7 +151,6 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
const updates: Partial<HTTPFields> = {
|
||||
[ConfigKey.URLS]: 'https://modified-host.com',
|
||||
[ConfigKey.NAME]: 'Modified name like that',
|
||||
[ConfigKey.LOCATIONS]: [privateLocations[0]],
|
||||
[ConfigKey.REQUEST_HEADERS_CHECK]: {
|
||||
sampleHeader2: 'sampleValue2',
|
||||
},
|
||||
|
@ -311,14 +296,11 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
|
||||
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
|
||||
|
||||
const spaceScopedPrivateLocation = await testPrivateLocations.addTestPrivateLocation(
|
||||
SPACE_ID
|
||||
);
|
||||
const newMonitor = {
|
||||
name,
|
||||
type: 'http',
|
||||
urls: 'https://elastic.co',
|
||||
locations: [spaceScopedPrivateLocation],
|
||||
locations: [LOCAL_PUBLIC_LOCATION],
|
||||
};
|
||||
|
||||
const savedMonitor = await saveMonitor(newMonitor as MonitorFields, SPACE_ID);
|
||||
|
|
|
@ -0,0 +1,370 @@
|
|||
/*
|
||||
* 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 moment from 'moment';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { omit } from 'lodash';
|
||||
import {
|
||||
ConfigKey,
|
||||
EncryptedSyntheticsSavedMonitor,
|
||||
HTTPFields,
|
||||
MonitorFields,
|
||||
PrivateLocation,
|
||||
} from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { RoleCredentials } from '@kbn/ftr-common-functional-services';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import expect from '@kbn/expect';
|
||||
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helpers/get_fixture_json';
|
||||
import { omitResponseTimestamps, omitEmptyValues } from './helpers/monitor';
|
||||
import { PrivateLocationTestService } from '../../../services/synthetics_private_location';
|
||||
import { SyntheticsMonitorTestService } from '../../../services/synthetics_monitor';
|
||||
|
||||
export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
||||
describe('EditMonitorAPI - Private Location', function () {
|
||||
const supertestWithAuth = getService('supertest');
|
||||
const supertest = getService('supertestWithoutAuth');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
const samlAuth = getService('samlAuth');
|
||||
|
||||
const testPrivateLocations = new PrivateLocationTestService(getService);
|
||||
const monitorTestService = new SyntheticsMonitorTestService(getService);
|
||||
|
||||
let _httpMonitorJson: HTTPFields;
|
||||
let httpMonitorJson: HTTPFields;
|
||||
let testPolicyId = '';
|
||||
let editorUser: RoleCredentials;
|
||||
let privateLocations: PrivateLocation[];
|
||||
|
||||
const saveMonitor = async (monitor: MonitorFields, spaceId?: string) => {
|
||||
const apiURL = spaceId
|
||||
? `/s/${spaceId}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`
|
||||
: SYNTHETICS_API_URLS.SYNTHETICS_MONITORS;
|
||||
const res = await supertest
|
||||
.post(apiURL + '?internal=true')
|
||||
.set(editorUser.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.send(monitor)
|
||||
.expect(200);
|
||||
|
||||
const { url, created_at: createdAt, updated_at: updatedAt, ...rest } = res.body;
|
||||
|
||||
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);
|
||||
|
||||
return rest as EncryptedSyntheticsSavedMonitor;
|
||||
};
|
||||
|
||||
const editMonitor = async (modifiedMonitor: MonitorFields, monitorId: string) => {
|
||||
const res = await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + monitorId + '?internal=true')
|
||||
.set(editorUser.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.send(modifiedMonitor);
|
||||
|
||||
expect(res.status).eql(200, JSON.stringify(res.body));
|
||||
|
||||
const { created_at: createdAt, updated_at: updatedAt } = res.body;
|
||||
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);
|
||||
|
||||
return omit(res.body, ['created_at', 'updated_at']);
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
await supertestWithAuth.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
|
||||
editorUser = await samlAuth.createM2mApiKeyWithRoleScope('editor');
|
||||
await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_ENABLEMENT)
|
||||
.set(editorUser.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.expect(200);
|
||||
|
||||
const testPolicyName = 'Fleet test server policy' + Date.now();
|
||||
const apiResponse = await testPrivateLocations.addFleetPolicy(testPolicyName);
|
||||
testPolicyId = apiResponse.body.item.id;
|
||||
privateLocations = await testPrivateLocations.setTestLocations([testPolicyId]);
|
||||
_httpMonitorJson = getFixtureJson('http_monitor');
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
httpMonitorJson = { ..._httpMonitorJson, locations: [privateLocations[0]] };
|
||||
});
|
||||
|
||||
it('edits the monitor', async () => {
|
||||
const newMonitor = httpMonitorJson;
|
||||
|
||||
const savedMonitor = await saveMonitor(newMonitor as MonitorFields);
|
||||
const monitorId = savedMonitor[ConfigKey.CONFIG_ID];
|
||||
|
||||
expect(omitResponseTimestamps(savedMonitor)).eql(
|
||||
omitEmptyValues({
|
||||
...newMonitor,
|
||||
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
|
||||
[ConfigKey.CONFIG_ID]: monitorId,
|
||||
})
|
||||
);
|
||||
|
||||
const updates: Partial<HTTPFields> = {
|
||||
[ConfigKey.URLS]: 'https://modified-host.com',
|
||||
[ConfigKey.NAME]: 'Modified name',
|
||||
[ConfigKey.LOCATIONS]: [privateLocations[0]],
|
||||
[ConfigKey.REQUEST_HEADERS_CHECK]: {
|
||||
sampleHeader2: 'sampleValue2',
|
||||
},
|
||||
[ConfigKey.METADATA]: {
|
||||
script_source: {
|
||||
is_generated_script: false,
|
||||
file_name: 'test-file.name',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const modifiedMonitor = {
|
||||
...savedMonitor,
|
||||
...updates,
|
||||
[ConfigKey.METADATA]: {
|
||||
...newMonitor[ConfigKey.METADATA],
|
||||
...updates[ConfigKey.METADATA],
|
||||
},
|
||||
} as any;
|
||||
|
||||
const editResponse = await editMonitor(modifiedMonitor, monitorId);
|
||||
|
||||
expect(editResponse).eql(
|
||||
omitEmptyValues({
|
||||
...modifiedMonitor,
|
||||
revision: 2,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('strips unknown keys from monitor edits', async () => {
|
||||
const newMonitor = { ...httpMonitorJson, name: 'yet another' };
|
||||
|
||||
const savedMonitor = await saveMonitor(newMonitor as MonitorFields);
|
||||
const monitorId = savedMonitor[ConfigKey.CONFIG_ID];
|
||||
|
||||
const { created_at: createdAt, updated_at: updatedAt } = savedMonitor;
|
||||
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);
|
||||
|
||||
expect(omitResponseTimestamps(savedMonitor)).eql(
|
||||
omitEmptyValues({
|
||||
...newMonitor,
|
||||
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
|
||||
[ConfigKey.CONFIG_ID]: monitorId,
|
||||
})
|
||||
);
|
||||
|
||||
const updates: Partial<HTTPFields> = {
|
||||
[ConfigKey.URLS]: 'https://modified-host.com',
|
||||
[ConfigKey.NAME]: 'Modified name like that',
|
||||
[ConfigKey.LOCATIONS]: [privateLocations[0]],
|
||||
[ConfigKey.REQUEST_HEADERS_CHECK]: {
|
||||
sampleHeader2: 'sampleValue2',
|
||||
},
|
||||
[ConfigKey.METADATA]: {
|
||||
script_source: {
|
||||
is_generated_script: false,
|
||||
file_name: 'test-file.name',
|
||||
},
|
||||
},
|
||||
unknownkey: 'unknownvalue',
|
||||
} as Partial<HTTPFields>;
|
||||
|
||||
const modifiedMonitor = omit(
|
||||
{
|
||||
...updates,
|
||||
[ConfigKey.METADATA]: {
|
||||
...newMonitor[ConfigKey.METADATA],
|
||||
...updates[ConfigKey.METADATA],
|
||||
},
|
||||
},
|
||||
['unknownkey']
|
||||
);
|
||||
|
||||
const editResponse = await editMonitor(modifiedMonitor as MonitorFields, monitorId);
|
||||
|
||||
expect(editResponse).eql(
|
||||
omitEmptyValues({
|
||||
...savedMonitor,
|
||||
...modifiedMonitor,
|
||||
revision: 2,
|
||||
})
|
||||
);
|
||||
expect(editResponse).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!`;
|
||||
|
||||
const editResponse = await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + invalidMonitorId)
|
||||
.set(editorUser.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.send(httpMonitorJson)
|
||||
.expect(404);
|
||||
|
||||
expect(editResponse.body.message).eql(expected404Message);
|
||||
});
|
||||
|
||||
it('returns bad request if payload is invalid for HTTP monitor', async () => {
|
||||
const { id: monitorId, ...savedMonitor } = await saveMonitor(
|
||||
httpMonitorJson as MonitorFields
|
||||
);
|
||||
|
||||
// Delete a required property to make payload invalid
|
||||
const toUpdate = { ...savedMonitor, 'check.request.headers': null };
|
||||
|
||||
const apiResponse = await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + monitorId)
|
||||
.set(editorUser.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.send(toUpdate);
|
||||
|
||||
expect(apiResponse.status).eql(400);
|
||||
});
|
||||
|
||||
it('returns bad request if monitor type is invalid', async () => {
|
||||
const { id: monitorId, ...savedMonitor } = await saveMonitor({
|
||||
...httpMonitorJson,
|
||||
name: 'test monitor - 11',
|
||||
} as MonitorFields);
|
||||
|
||||
const toUpdate = { ...savedMonitor, type: 'invalid-data-steam' };
|
||||
|
||||
const apiResponse = await supertest
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + monitorId)
|
||||
.set(editorUser.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.send(toUpdate);
|
||||
|
||||
expect(apiResponse.status).eql(400);
|
||||
expect(apiResponse.body.message).eql(
|
||||
'Monitor type cannot be changed from http to invalid-data-steam.'
|
||||
);
|
||||
});
|
||||
|
||||
it('sets config hash to empty string on edits', async () => {
|
||||
const newMonitor = httpMonitorJson;
|
||||
const configHash = 'djrhefje';
|
||||
|
||||
const savedMonitor = await saveMonitor({
|
||||
...(newMonitor as MonitorFields),
|
||||
[ConfigKey.CONFIG_HASH]: configHash,
|
||||
name: 'test monitor - 12',
|
||||
});
|
||||
const monitorId = savedMonitor[ConfigKey.CONFIG_ID];
|
||||
const { created_at: createdAt, updated_at: updatedAt } = savedMonitor;
|
||||
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);
|
||||
|
||||
expect(savedMonitor).eql(
|
||||
omitEmptyValues({
|
||||
...newMonitor,
|
||||
[ConfigKey.CONFIG_ID]: monitorId,
|
||||
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
|
||||
name: 'test monitor - 12',
|
||||
hash: configHash,
|
||||
})
|
||||
);
|
||||
|
||||
const updates: Partial<HTTPFields> = {
|
||||
[ConfigKey.URLS]: 'https://modified-host.com',
|
||||
name: 'test monitor - 12',
|
||||
} as Partial<HTTPFields>;
|
||||
|
||||
const modifiedMonitor = {
|
||||
...newMonitor,
|
||||
...updates,
|
||||
[ConfigKey.METADATA]: {
|
||||
...newMonitor[ConfigKey.METADATA],
|
||||
...updates[ConfigKey.METADATA],
|
||||
},
|
||||
};
|
||||
|
||||
const editResponse = await editMonitor(modifiedMonitor as MonitorFields, monitorId);
|
||||
|
||||
expect(editResponse).eql(
|
||||
omitEmptyValues({
|
||||
...modifiedMonitor,
|
||||
[ConfigKey.CONFIG_ID]: monitorId,
|
||||
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
|
||||
[ConfigKey.CONFIG_HASH]: '',
|
||||
revision: 2,
|
||||
})
|
||||
);
|
||||
expect(editResponse).not.to.have.keys('unknownkey');
|
||||
});
|
||||
|
||||
it('handles spaces', async () => {
|
||||
const name = 'Monitor with private location';
|
||||
|
||||
const SPACE_ID = `test-space-${uuidv4()}`;
|
||||
const SPACE_NAME = `test-space-name ${uuidv4()}`;
|
||||
|
||||
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
|
||||
|
||||
const spaceScopedPrivateLocation = await testPrivateLocations.addTestPrivateLocation(
|
||||
SPACE_ID
|
||||
);
|
||||
const newMonitor = {
|
||||
name,
|
||||
type: 'http',
|
||||
urls: 'https://elastic.co',
|
||||
locations: [spaceScopedPrivateLocation],
|
||||
};
|
||||
|
||||
const savedMonitor = await saveMonitor(newMonitor as MonitorFields, SPACE_ID);
|
||||
|
||||
const monitorId = savedMonitor[ConfigKey.CONFIG_ID];
|
||||
const toUpdate = {
|
||||
...savedMonitor,
|
||||
urls: 'https://google.com',
|
||||
};
|
||||
await supertest
|
||||
.put(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}/${monitorId}`)
|
||||
.set(editorUser.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.send(toUpdate)
|
||||
.expect(200);
|
||||
|
||||
const updatedResponse = await monitorTestService.getMonitor(monitorId, {
|
||||
space: SPACE_ID,
|
||||
internal: true,
|
||||
user: editorUser,
|
||||
});
|
||||
|
||||
// ensure monitor was updated
|
||||
expect(updatedResponse.body.urls).eql(toUpdate.urls);
|
||||
|
||||
// update a second time, ensures AAD was not corrupted
|
||||
const toUpdate2 = {
|
||||
...savedMonitor,
|
||||
urls: 'https://google.com',
|
||||
};
|
||||
|
||||
await supertest
|
||||
.put(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}/${monitorId}`)
|
||||
.set(editorUser.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.send(toUpdate2)
|
||||
.expect(200);
|
||||
|
||||
const updatedResponse2 = await monitorTestService.getMonitor(monitorId, {
|
||||
space: SPACE_ID,
|
||||
internal: true,
|
||||
user: editorUser,
|
||||
});
|
||||
|
||||
// ensure monitor was updated
|
||||
expect(updatedResponse2.body.urls).eql(toUpdate2.urls);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -5,28 +5,25 @@
|
|||
* 2.0.
|
||||
*/
|
||||
import expect from '@kbn/expect';
|
||||
import rawExpect from 'expect';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { omit } from 'lodash';
|
||||
import moment from 'moment';
|
||||
import { RoleCredentials } from '@kbn/ftr-common-functional-services';
|
||||
import { DEFAULT_FIELDS } from '@kbn/synthetics-plugin/common/constants/monitor_defaults';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import moment from 'moment';
|
||||
import { PrivateLocation } from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { LOCATION_REQUIRED_ERROR } from '@kbn/synthetics-plugin/server/routes/monitor_cruds/monitor_validation';
|
||||
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';
|
||||
import { addMonitorAPIHelper, omitMonitorKeys } from './create_monitor';
|
||||
import { PrivateLocationTestService } from '../../../services/synthetics_private_location';
|
||||
import { LOCAL_PUBLIC_LOCATION } from './helpers/location';
|
||||
|
||||
export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
||||
describe('EditMonitorsPublicAPI', function () {
|
||||
describe('EditMonitorsPublicAPI - Public location', function () {
|
||||
this.tags(['skipCloud', 'skipMKI']);
|
||||
const supertestAPI = getService('supertestWithoutAuth');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
const samlAuth = getService('samlAuth');
|
||||
const testPrivateLocations = new PrivateLocationTestService(getService);
|
||||
let editorUser: RoleCredentials;
|
||||
let privateLocation1: PrivateLocation;
|
||||
let privateLocation2: PrivateLocation;
|
||||
|
||||
async function addMonitorAPI(monitor: any, statusCode: number = 200) {
|
||||
return await addMonitorAPIHelper(supertestAPI, monitor, statusCode, editorUser, samlAuth);
|
||||
|
@ -75,8 +72,6 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
editorUser = await samlAuth.createM2mApiKeyWithRoleScope('editor');
|
||||
await testPrivateLocations.installSyntheticsPackage();
|
||||
privateLocation1 = await testPrivateLocations.addTestPrivateLocation();
|
||||
privateLocation2 = await testPrivateLocations.addTestPrivateLocation();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
@ -89,7 +84,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
it('adds test monitor', async () => {
|
||||
const monitor = {
|
||||
type: 'http',
|
||||
private_locations: [privateLocation1.id],
|
||||
locations: [LOCAL_PUBLIC_LOCATION.id],
|
||||
url: 'https://www.google.com',
|
||||
};
|
||||
const { body: result, rawBody } = await addMonitorAPI(monitor);
|
||||
|
@ -99,93 +94,12 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [privateLocation1],
|
||||
locations: [LOCAL_PUBLIC_LOCATION],
|
||||
name: 'https://www.google.com',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should return error for empty monitor', async function () {
|
||||
const errMessage = 'Monitor must be a non-empty object';
|
||||
const testCases = [{}, null, undefined, false, [], ''];
|
||||
for (const testCase of testCases) {
|
||||
const { message } = await editMonitorAPI(monitorId, testCase, 400);
|
||||
expect(message).eql(errMessage);
|
||||
}
|
||||
});
|
||||
|
||||
it('return error if type is being changed', async () => {
|
||||
const { message } = await editMonitorAPI(monitorId, { type: 'tcp' }, 400);
|
||||
expect(message).eql('Monitor type cannot be changed from http to tcp.');
|
||||
});
|
||||
|
||||
it('return error if monitor not found', async () => {
|
||||
const { message } = await editMonitorAPI('invalid-monitor-id', { type: 'tcp' }, 404);
|
||||
expect(message).eql('Monitor id invalid-monitor-id not found!');
|
||||
});
|
||||
|
||||
it('return error if invalid location specified', async () => {
|
||||
const { message } = await editMonitorAPI(
|
||||
monitorId,
|
||||
{ type: 'http', locations: ['mars'] },
|
||||
400
|
||||
);
|
||||
rawExpect(message).toContain(
|
||||
"Invalid locations specified. Elastic managed Location(s) 'mars' not found."
|
||||
);
|
||||
});
|
||||
|
||||
it('return error if invalid private location specified', async () => {
|
||||
const { message } = await editMonitorAPI(
|
||||
monitorId,
|
||||
{
|
||||
type: 'http',
|
||||
locations: ['mars'],
|
||||
privateLocations: ['moon'],
|
||||
},
|
||||
400
|
||||
);
|
||||
expect(message).eql('Invalid monitor key(s) for http type: privateLocations');
|
||||
|
||||
const result = await editMonitorAPI(
|
||||
monitorId,
|
||||
{
|
||||
type: 'http',
|
||||
locations: ['mars'],
|
||||
private_locations: ['moon'],
|
||||
},
|
||||
400
|
||||
);
|
||||
rawExpect(result.message).toContain("Private Location(s) 'moon' not found.");
|
||||
});
|
||||
|
||||
it('throws an error if empty locations', async () => {
|
||||
const monitor = {
|
||||
locations: [],
|
||||
private_locations: [],
|
||||
};
|
||||
const { message } = await editMonitorAPI(monitorId, monitor, 400);
|
||||
|
||||
expect(message).eql(LOCATION_REQUIRED_ERROR);
|
||||
});
|
||||
|
||||
it('cannot change origin type', async () => {
|
||||
const monitor = {
|
||||
origin: 'project',
|
||||
};
|
||||
const result = await editMonitorAPI(monitorId, monitor, 400);
|
||||
|
||||
expect(result).eql({
|
||||
statusCode: 400,
|
||||
error: 'Bad Request',
|
||||
message: 'Unsupported origin type project, only ui type is supported via API.',
|
||||
attributes: {
|
||||
details: 'Unsupported origin type project, only ui type is supported via API.',
|
||||
payload: { origin: 'project' },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const updates: any = {};
|
||||
|
||||
it('can change name of monitor', async () => {
|
||||
|
@ -200,7 +114,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
...defaultFields,
|
||||
...monitor,
|
||||
...updates,
|
||||
locations: [privateLocation1],
|
||||
locations: [LOCAL_PUBLIC_LOCATION],
|
||||
revision: 2,
|
||||
url: 'https://www.google.com',
|
||||
})
|
||||
|
@ -212,7 +126,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
const monitor = {
|
||||
name,
|
||||
type: 'http',
|
||||
private_locations: [privateLocation1.id],
|
||||
locations: [LOCAL_PUBLIC_LOCATION.id],
|
||||
url: 'https://www.google.com',
|
||||
};
|
||||
// create one monitor with one name
|
||||
|
@ -228,7 +142,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [privateLocation1],
|
||||
locations: [LOCAL_PUBLIC_LOCATION],
|
||||
name: 'test name',
|
||||
})
|
||||
);
|
||||
|
@ -251,9 +165,9 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
});
|
||||
});
|
||||
|
||||
it('can add a second private location to existing monitor', async () => {
|
||||
it('can add a second public location to existing monitor', async () => {
|
||||
const monitor = {
|
||||
private_locations: [privateLocation1.id, privateLocation2.id],
|
||||
locations: [LOCAL_PUBLIC_LOCATION.id, 'dev2'],
|
||||
};
|
||||
|
||||
const { body: result } = await editMonitorAPI(monitorId, monitor);
|
||||
|
@ -264,14 +178,17 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
...updates,
|
||||
revision: 3,
|
||||
url: 'https://www.google.com',
|
||||
locations: [privateLocation1, privateLocation2],
|
||||
locations: [
|
||||
LOCAL_PUBLIC_LOCATION,
|
||||
{ ...LOCAL_PUBLIC_LOCATION, id: 'dev2', label: 'Dev Service 2' },
|
||||
],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('can remove private location from existing monitor', async () => {
|
||||
it('can remove public location from existing monitor', async () => {
|
||||
const monitor = {
|
||||
private_locations: [privateLocation2.id],
|
||||
locations: ['dev2'],
|
||||
};
|
||||
|
||||
const { body: result } = await editMonitorAPI(monitorId, monitor);
|
||||
|
@ -282,20 +199,9 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
|||
...updates,
|
||||
revision: 4,
|
||||
url: 'https://www.google.com',
|
||||
locations: [privateLocation2],
|
||||
locations: [{ ...LOCAL_PUBLIC_LOCATION, id: 'dev2', label: 'Dev Service 2' }],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('can not remove all locations', async () => {
|
||||
const monitor = {
|
||||
locations: [],
|
||||
private_locations: [],
|
||||
};
|
||||
|
||||
const { message } = await editMonitorAPI(monitorId, monitor, 400);
|
||||
|
||||
expect(message).eql(LOCATION_REQUIRED_ERROR);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,63 +5,78 @@
|
|||
* 2.0.
|
||||
*/
|
||||
import expect from '@kbn/expect';
|
||||
import rawExpect from 'expect';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { omit } from 'lodash';
|
||||
|
||||
import { RoleCredentials } from '@kbn/ftr-common-functional-services';
|
||||
import { DEFAULT_FIELDS } from '@kbn/synthetics-plugin/common/constants/monitor_defaults';
|
||||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
import moment from 'moment';
|
||||
import { PrivateLocation } from '@kbn/synthetics-plugin/common/runtime_types';
|
||||
import { LOCATION_REQUIRED_ERROR } from '@kbn/synthetics-plugin/server/routes/monitor_cruds/monitor_validation';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { addMonitorAPIHelper, omitMonitorKeys } from './add_monitor';
|
||||
import { PrivateLocationTestService } from './services/private_location_test_service';
|
||||
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';
|
||||
import { addMonitorAPIHelper, omitMonitorKeys } from './create_monitor';
|
||||
import { PrivateLocationTestService } from '../../../services/synthetics_private_location';
|
||||
|
||||
export const editMonitorAPIHelper = async (
|
||||
supertestAPI: any,
|
||||
monitorId: string,
|
||||
monitor: any,
|
||||
statusCode = 200
|
||||
) => {
|
||||
const result = await supertestAPI
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + `/${monitorId}`)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(monitor);
|
||||
|
||||
expect(result.status).eql(statusCode, JSON.stringify(result.body));
|
||||
|
||||
if (statusCode === 200) {
|
||||
const { created_at: createdAt, updated_at: updatedAt, id, config_id: configId } = result.body;
|
||||
expect(id).not.empty();
|
||||
expect(configId).not.empty();
|
||||
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);
|
||||
return {
|
||||
rawBody: result.body,
|
||||
body: {
|
||||
...omit(result.body, ['created_at', 'updated_at', 'id', 'config_id', 'form_monitor_type']),
|
||||
},
|
||||
};
|
||||
}
|
||||
return result.body;
|
||||
};
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
describe('EditMonitorsPublicAPI', function () {
|
||||
this.tags('skipCloud');
|
||||
|
||||
const supertestAPI = getService('supertest');
|
||||
export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
|
||||
describe('EditMonitorsPublicAPI - Private Location', function () {
|
||||
const supertestAPI = getService('supertestWithoutAuth');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
const samlAuth = getService('samlAuth');
|
||||
const testPrivateLocations = new PrivateLocationTestService(getService);
|
||||
let editorUser: RoleCredentials;
|
||||
let privateLocation1: PrivateLocation;
|
||||
let privateLocation2: PrivateLocation;
|
||||
|
||||
async function addMonitorAPI(monitor: any, statusCode: number = 200) {
|
||||
return await addMonitorAPIHelper(supertestAPI, monitor, statusCode);
|
||||
return await addMonitorAPIHelper(supertestAPI, monitor, statusCode, editorUser, samlAuth);
|
||||
}
|
||||
|
||||
async function editMonitorAPI(id: string, monitor: any, statusCode: number = 200) {
|
||||
return await editMonitorAPIHelper(supertestAPI, id, monitor, statusCode);
|
||||
return await editMonitorAPIHelper(id, monitor, statusCode);
|
||||
}
|
||||
|
||||
async function editMonitorAPIHelper(monitorId: string, monitor: any, statusCode = 200) {
|
||||
const result = await supertestAPI
|
||||
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + `/${monitorId}`)
|
||||
.set(editorUser.apiKeyHeader)
|
||||
.set(samlAuth.getInternalRequestHeader())
|
||||
.send(monitor);
|
||||
|
||||
expect(result.status).eql(statusCode, JSON.stringify(result.body));
|
||||
|
||||
if (statusCode === 200) {
|
||||
const {
|
||||
created_at: createdAt,
|
||||
updated_at: updatedAt,
|
||||
id,
|
||||
config_id: configId,
|
||||
} = result.body;
|
||||
expect(id).not.empty();
|
||||
expect(configId).not.empty();
|
||||
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);
|
||||
return {
|
||||
rawBody: result.body,
|
||||
body: {
|
||||
...omit(result.body, [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'id',
|
||||
'config_id',
|
||||
'form_monitor_type',
|
||||
]),
|
||||
},
|
||||
};
|
||||
}
|
||||
return result.body;
|
||||
}
|
||||
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
editorUser = await samlAuth.createM2mApiKeyWithRoleScope('editor');
|
||||
await testPrivateLocations.installSyntheticsPackage();
|
||||
privateLocation1 = await testPrivateLocations.addTestPrivateLocation();
|
||||
privateLocation2 = await testPrivateLocations.addTestPrivateLocation();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
@ -70,10 +85,11 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
let monitorId = 'test-id';
|
||||
|
||||
const defaultFields = DEFAULT_FIELDS.http;
|
||||
|
||||
it('adds test monitor', async () => {
|
||||
const monitor = {
|
||||
type: 'http',
|
||||
locations: ['dev'],
|
||||
private_locations: [privateLocation1.id],
|
||||
url: 'https://www.google.com',
|
||||
};
|
||||
const { body: result, rawBody } = await addMonitorAPI(monitor);
|
||||
|
@ -83,7 +99,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [localLoc],
|
||||
locations: [privateLocation1],
|
||||
name: 'https://www.google.com',
|
||||
})
|
||||
);
|
||||
|
@ -114,8 +130,8 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
{ type: 'http', locations: ['mars'] },
|
||||
400
|
||||
);
|
||||
expect(message).eql(
|
||||
"Invalid locations specified. Elastic managed Location(s) 'mars' not found. Available locations are 'dev|dev2'"
|
||||
rawExpect(message).toContain(
|
||||
"Invalid locations specified. Elastic managed Location(s) 'mars' not found."
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -140,24 +156,13 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
},
|
||||
400
|
||||
);
|
||||
expect(result.message).eql(
|
||||
"Invalid locations specified. Elastic managed Location(s) 'mars' not found. Available locations are 'dev|dev2' Private Location(s) 'moon' not found. No private location available to use."
|
||||
);
|
||||
rawExpect(result.message).toContain("Private Location(s) 'moon' not found.");
|
||||
});
|
||||
|
||||
const localLoc = {
|
||||
id: 'dev',
|
||||
label: 'Dev Service',
|
||||
geo: {
|
||||
lat: 0,
|
||||
lon: 0,
|
||||
},
|
||||
isServiceManaged: true,
|
||||
};
|
||||
|
||||
it('throws an error if empty locations', async () => {
|
||||
const monitor = {
|
||||
locations: [],
|
||||
private_locations: [],
|
||||
};
|
||||
const { message } = await editMonitorAPI(monitorId, monitor, 400);
|
||||
|
||||
|
@ -184,9 +189,9 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
const updates: any = {};
|
||||
|
||||
it('can change name of monitor', async () => {
|
||||
updates.name = 'updated name';
|
||||
updates.name = `updated name ${uuidv4()}`;
|
||||
const monitor = {
|
||||
name: 'updated name',
|
||||
name: updates.name,
|
||||
};
|
||||
const { body: result } = await editMonitorAPI(monitorId, monitor);
|
||||
|
||||
|
@ -195,7 +200,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
...defaultFields,
|
||||
...monitor,
|
||||
...updates,
|
||||
locations: [localLoc],
|
||||
locations: [privateLocation1],
|
||||
revision: 2,
|
||||
url: 'https://www.google.com',
|
||||
})
|
||||
|
@ -203,27 +208,35 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
});
|
||||
|
||||
it('prevents duplicate name of monitor', async () => {
|
||||
const name = `test name ${uuidv4()}`;
|
||||
const monitor = {
|
||||
name,
|
||||
type: 'http',
|
||||
locations: ['dev'],
|
||||
private_locations: [privateLocation1.id],
|
||||
url: 'https://www.google.com',
|
||||
};
|
||||
const { body: result, rawBody } = await addMonitorAPI(monitor);
|
||||
// create one monitor with one name
|
||||
await addMonitorAPI(monitor);
|
||||
// create another monitor with a different name
|
||||
const { body: result, rawBody } = await addMonitorAPI({
|
||||
...monitor,
|
||||
name: 'test name',
|
||||
});
|
||||
const newMonitorId = rawBody.id;
|
||||
|
||||
expect(result).eql(
|
||||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...monitor,
|
||||
locations: [localLoc],
|
||||
name: 'https://www.google.com',
|
||||
locations: [privateLocation1],
|
||||
name: 'test name',
|
||||
})
|
||||
);
|
||||
|
||||
const editResult = await editMonitorAPI(
|
||||
newMonitorId,
|
||||
{
|
||||
name: 'updated name',
|
||||
name,
|
||||
},
|
||||
400
|
||||
);
|
||||
|
@ -231,21 +244,16 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
expect(editResult).eql({
|
||||
statusCode: 400,
|
||||
error: 'Bad Request',
|
||||
message: 'Monitor name must be unique, "updated name" already exists.',
|
||||
attributes: { details: 'Monitor name must be unique, "updated name" already exists.' },
|
||||
message: `Monitor name must be unique, "${name}" already exists.`,
|
||||
attributes: {
|
||||
details: `Monitor name must be unique, "${name}" already exists.`,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
let pvtLoc: PrivateLocation;
|
||||
|
||||
it('can add private location to existing monitor', async () => {
|
||||
await testPrivateLocations.installSyntheticsPackage();
|
||||
pvtLoc = await testPrivateLocations.addPrivateLocation();
|
||||
|
||||
expect(pvtLoc).not.empty();
|
||||
|
||||
it('can add a second private location to existing monitor', async () => {
|
||||
const monitor = {
|
||||
private_locations: [pvtLoc.id],
|
||||
private_locations: [privateLocation1.id, privateLocation2.id],
|
||||
};
|
||||
|
||||
const { body: result } = await editMonitorAPI(monitorId, monitor);
|
||||
|
@ -256,29 +264,14 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
...updates,
|
||||
revision: 3,
|
||||
url: 'https://www.google.com',
|
||||
locations: [localLoc, omit(pvtLoc, 'spaces')],
|
||||
})
|
||||
);
|
||||
|
||||
const { body: result2 } = await editMonitorAPI(monitorId, {
|
||||
locations: [pvtLoc],
|
||||
});
|
||||
|
||||
expect(result2).eql(
|
||||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...updates,
|
||||
revision: 4,
|
||||
url: 'https://www.google.com',
|
||||
locations: [omit(pvtLoc, 'spaces')],
|
||||
locations: [omit(privateLocation1, 'spaces'), omit(privateLocation2, 'spaces')],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('can remove private location from existing monitor', async () => {
|
||||
let monitor: any = {
|
||||
locations: [localLoc.id],
|
||||
private_locations: [pvtLoc.id],
|
||||
const monitor = {
|
||||
private_locations: [privateLocation2.id],
|
||||
};
|
||||
|
||||
const { body: result } = await editMonitorAPI(monitorId, monitor);
|
||||
|
@ -287,25 +280,9 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...updates,
|
||||
revision: 5,
|
||||
revision: 4,
|
||||
url: 'https://www.google.com',
|
||||
locations: [localLoc, omit(pvtLoc, 'spaces')],
|
||||
})
|
||||
);
|
||||
|
||||
monitor = {
|
||||
private_locations: [],
|
||||
};
|
||||
|
||||
const { body: result1 } = await editMonitorAPI(monitorId, monitor);
|
||||
|
||||
expect(result1).eql(
|
||||
omitMonitorKeys({
|
||||
...defaultFields,
|
||||
...updates,
|
||||
revision: 6,
|
||||
url: 'https://www.google.com',
|
||||
locations: [localLoc],
|
||||
locations: [omit(privateLocation2, 'spaces')],
|
||||
})
|
||||
);
|
||||
});
|
|
@ -13,7 +13,7 @@
|
|||
"hosts": [ "1.1.1.1" ],
|
||||
"schedule": 1,
|
||||
"tags": [ "service:smtp", "org:google" ],
|
||||
"privateLocations": [ "Test private location 0" ],
|
||||
"privateLocations": [],
|
||||
"wait": "30s",
|
||||
"hash": "ekrjelkjrelkjre"
|
||||
},
|
||||
|
@ -25,7 +25,7 @@
|
|||
"hosts": "1.1.1.1",
|
||||
"schedule": 1,
|
||||
"tags": "tag1,tag2",
|
||||
"privateLocations": [ "Test private location 0" ],
|
||||
"privateLocations": [],
|
||||
"wait": "1m",
|
||||
"hash": "ekrjelkjrelkjre"
|
||||
},
|
||||
|
@ -37,7 +37,7 @@
|
|||
"hosts": "1.1.1.1,2.2.2.2",
|
||||
"schedule": 1,
|
||||
"tags": "tag1,tag2",
|
||||
"privateLocations": [ "Test private location 0" ],
|
||||
"privateLocations": [],
|
||||
"unsupportedKey": {
|
||||
"nestedUnsupportedKey": "unnsuportedValue"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export const LOCAL_PUBLIC_LOCATION = {
|
||||
geo: {
|
||||
lat: 0,
|
||||
lon: 0,
|
||||
},
|
||||
id: 'dev',
|
||||
label: 'Dev Service',
|
||||
isServiceManaged: true,
|
||||
};
|
|
@ -9,24 +9,27 @@ import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_cont
|
|||
|
||||
export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) {
|
||||
describe('SyntheticsAPITests', () => {
|
||||
loadTestFile(require.resolve('./create_monitor'));
|
||||
loadTestFile(require.resolve('./create_monitor_private_location'));
|
||||
loadTestFile(require.resolve('./create_monitor_project'));
|
||||
loadTestFile(require.resolve('./create_monitor_project_private_location'));
|
||||
loadTestFile(require.resolve('./create_monitor_project'));
|
||||
loadTestFile(require.resolve('./create_monitor_public_api_private_location'));
|
||||
loadTestFile(require.resolve('./create_monitor_public_api'));
|
||||
loadTestFile(require.resolve('./create_monitor'));
|
||||
loadTestFile(require.resolve('./create_update_params'));
|
||||
loadTestFile(require.resolve('./delete_monitor_project'));
|
||||
loadTestFile(require.resolve('./delete_monitor'));
|
||||
loadTestFile(require.resolve('./edit_monitor'));
|
||||
loadTestFile(require.resolve('./edit_monitor_private_location'));
|
||||
loadTestFile(require.resolve('./edit_monitor_public_api_private_location'));
|
||||
loadTestFile(require.resolve('./edit_monitor_public_api'));
|
||||
loadTestFile(require.resolve('./edit_monitor'));
|
||||
loadTestFile(require.resolve('./enable_default_alerting'));
|
||||
loadTestFile(require.resolve('./get_filters'));
|
||||
loadTestFile(require.resolve('./get_monitor_project'));
|
||||
loadTestFile(require.resolve('./get_monitor'));
|
||||
loadTestFile(require.resolve('./synthetics_enablement'));
|
||||
loadTestFile(require.resolve('./inspect_monitor'));
|
||||
loadTestFile(require.resolve('./suggestions.ts'));
|
||||
loadTestFile(require.resolve('./sync_global_params'));
|
||||
loadTestFile(require.resolve('./synthetics_enablement'));
|
||||
loadTestFile(require.resolve('./test_now_monitor'));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue