From 6af56ffd860174bc9bfc17263b5245d3f0297b31 Mon Sep 17 00:00:00 2001 From: Julian Gernun Date: Thu, 8 Sep 2022 16:52:10 +0200 Subject: [PATCH] add endpoint integration test --- .../basic/get_browser_fields_by_feature_id.ts | 65 +++++++++++++++++++ .../security_and_spaces/tests/basic/index.ts | 9 +-- 2 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 x-pack/test/rule_registry/security_and_spaces/tests/basic/get_browser_fields_by_feature_id.ts diff --git a/x-pack/test/rule_registry/security_and_spaces/tests/basic/get_browser_fields_by_feature_id.ts b/x-pack/test/rule_registry/security_and_spaces/tests/basic/get_browser_fields_by_feature_id.ts new file mode 100644 index 0000000000000..83cfc1ad26d25 --- /dev/null +++ b/x-pack/test/rule_registry/security_and_spaces/tests/basic/get_browser_fields_by_feature_id.ts @@ -0,0 +1,65 @@ +/* + * 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 { superUser, obsOnlySpacesAll, secOnlyRead } from '../../../common/lib/authentication/users'; +import type { User } from '../../../common/lib/authentication/types'; +import { FtrProviderContext } from '../../../common/ftr_provider_context'; + +// eslint-disable-next-line import/no-default-export +export default ({ getService }: FtrProviderContext) => { + const supertestWithoutAuth = getService('supertestWithoutAuth'); + const esArchiver = getService('esArchiver'); + + const TEST_URL = '/internal/rac/alerts/browser_fields'; + + const getBrowserFieldsByFeatureId = async ( + user: User, + featureIds: string[], + expectedStatusCode: number = 200 + ) => { + const resp = await supertestWithoutAuth + .get(`${TEST_URL}?featureIds=${featureIds.toString()}`) + .auth(user.username, user.password) + .set('kbn-xsrf', 'true') + .expect(expectedStatusCode); + return resp.body; + }; + + describe('Alert - Get browser fields by featureId', () => { + before(async () => { + await esArchiver.load('x-pack/test/functional/es_archives/rule_registry/alerts'); + }); + + describe('Users:', () => { + it(`${obsOnlySpacesAll.username} should be able to get feature id for o11y featureIds`, async () => { + const browserFields = await getBrowserFieldsByFeatureId(obsOnlySpacesAll, [ + 'apm', + 'infrastructure', + 'logs', + 'uptime', + ]); + expect(Object.keys(browserFields)).to.eql(['base']); + }); + + it(`${superUser.username} should be able to get feature id for o11y featureIds`, async () => { + const browserFields = await getBrowserFieldsByFeatureId(superUser, [ + 'apm', + 'infrastructure', + 'logs', + 'uptime', + ]); + expect(Object.keys(browserFields)).to.eql(['base', 'kibana', 'message']); + }); + + it(`${secOnlyRead.username} should not have access to o11y featureIds`, async () => { + await getBrowserFieldsByFeatureId(secOnlyRead, ['siem'], 403); + }); + }); + }); +}; diff --git a/x-pack/test/rule_registry/security_and_spaces/tests/basic/index.ts b/x-pack/test/rule_registry/security_and_spaces/tests/basic/index.ts index e96239f37cdfb..1834a0b284aa7 100644 --- a/x-pack/test/rule_registry/security_and_spaces/tests/basic/index.ts +++ b/x-pack/test/rule_registry/security_and_spaces/tests/basic/index.ts @@ -25,9 +25,10 @@ export default ({ loadTestFile, getService }: FtrProviderContext): void => { // loadTestFile(require.resolve('./update_alert')); // loadTestFile(require.resolve('./bulk_update_alerts')); - loadTestFile(require.resolve('./get_feature_ids_by_registration_contexts')); - loadTestFile(require.resolve('./get_alerts_index')); - loadTestFile(require.resolve('./find_alerts')); - loadTestFile(require.resolve('./search_strategy')); + // loadTestFile(require.resolve('./get_feature_ids_by_registration_contexts')); + // loadTestFile(require.resolve('./get_alerts_index')); + // loadTestFile(require.resolve('./find_alerts')); + // loadTestFile(require.resolve('./search_strategy')); + loadTestFile(require.resolve('./get_browser_fields_by_feature_id')); }); };