mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Fleet] Use admin user for jest integration tests (#123871)
This commit is contained in:
parent
be5bc27f0f
commit
3d8697d967
1 changed files with 18 additions and 9 deletions
|
@ -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',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue