Skip to content

Commit

Permalink
add endpoint integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
jcger committed Sep 8, 2022
1 parent 018bd72 commit 6af56ff
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
};

0 comments on commit 6af56ff

Please sign in to comment.