[Fleet] Use admin user for jest integration tests (#123871) (#123940)

(cherry picked from commit 3d8697d967)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
This commit is contained in:
Kibana Machine 2022-01-27 11:41:05 -05:00 committed by GitHub
parent 8ea0e64f94
commit 9468e62130
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,7 +7,10 @@
import Path from 'path';
import { adminTestUser } from '@kbn/test';
import * as kbnTestServer from 'src/core/test_helpers/kbn_server';
import type { HttpMethod } from 'src/core/test_helpers/kbn_server';
import type { AgentPolicySOAttributes } from '../types';
@ -15,9 +18,16 @@ const logFilePath = Path.join(__dirname, 'logs.log');
type Root = ReturnType<typeof kbnTestServer.createRoot>;
function getSupertestWithAdminUser(root: Root, method: HttpMethod, path: string) {
const testUserCredentials = Buffer.from(`${adminTestUser.username}:${adminTestUser.password}`);
return kbnTestServer
.getSupertest(root, method, path)
.set('Authorization', `Basic ${testUserCredentials.toString('base64')}`);
}
const waitForFleetSetup = async (root: Root) => {
const isFleetSetupRunning = async () => {
const statusApi = kbnTestServer.getSupertest(root, 'get', '/api/status');
const statusApi = getSupertestWithAdminUser(root, 'get', '/api/status');
const resp = await statusApi.send();
const fleetStatus = resp.body?.status?.plugins?.fleet;
if (fleetStatus?.meta?.error) {
@ -181,12 +191,12 @@ describe('Fleet preconfiguration rest', () => {
describe('Reset all policy', () => {
it('Works and reset all preconfigured policies', async () => {
const resetAPI = kbnTestServer.getSupertest(
const resetAPI = getSupertestWithAdminUser(
kbnServer.root,
'post',
'/internal/fleet/reset_preconfigured_agent_policies'
);
await resetAPI.set('kbn-sxrf', 'xx').send();
await resetAPI.set('kbn-sxrf', 'xx').expect(200).send();
const agentPolicies = await kbnServer.coreStart.savedObjects
.createInternalRepository()
@ -208,8 +218,7 @@ describe('Fleet preconfiguration rest', () => {
});
});
// SKIP: https://github.com/elastic/kibana/issues/123528
describe.skip('Reset one preconfigured policy', () => {
describe('Reset one preconfigured policy', () => {
const POLICY_ID = 'test-12345';
it('Works and reset one preconfigured policies if the policy is already deleted (with a ghost package policy)', async () => {
@ -224,12 +233,12 @@ describe('Fleet preconfiguration rest', () => {
const secondAgentPoliciesUpdatedAt = oldAgentPolicies.saved_objects[0].updated_at;
const resetAPI = kbnTestServer.getSupertest(
const resetAPI = getSupertestWithAdminUser(
kbnServer.root,
'post',
'/internal/fleet/reset_preconfigured_agent_policies/test-12345'
);
await resetAPI.set('kbn-sxrf', 'xx').send();
await resetAPI.set('kbn-sxrf', 'xx').expect(200).send();
const agentPolicies = await kbnServer.coreStart.savedObjects
.createInternalRepository()
@ -260,12 +269,12 @@ describe('Fleet preconfiguration rest', () => {
package_policies: [],
});
const resetAPI = kbnTestServer.getSupertest(
const resetAPI = getSupertestWithAdminUser(
kbnServer.root,
'post',
'/internal/fleet/reset_preconfigured_agent_policies/test-12345'
);
await resetAPI.set('kbn-sxrf', 'xx').send();
await resetAPI.set('kbn-sxrf', 'xx').expect(200).send();
const agentPolicies = await soClient.find<AgentPolicySOAttributes>({
type: 'ingest-agent-policies',