Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
elena-shostak committed Dec 27, 2024
1 parent c5c5a45 commit 1464f66
Show file tree
Hide file tree
Showing 14 changed files with 268 additions and 627 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
* 2.0.
*/

import type { Agent as SuperTestAgent } from 'supertest';

import expect from '@kbn/expect/expect';

import type {
DeploymentAgnosticFtrProviderContext,
SupertestWithRoleScopeType,
} from '../../deployment_agnostic/ftr_provider_context';
import { getRoleDefinitionForUser, isBuiltInRole } from '../lib/authentication';
import { getTestScenariosForSpace } from '../lib/space_test_utils';
import type { DescribeFn, TestDefinitionAuthentication } from '../lib/types';

Expand All @@ -38,8 +35,6 @@ interface CreateTestDefinition {
export function createTestSuiteFactory({ getService }: DeploymentAgnosticFtrProviderContext) {
const esArchiver = getService('esArchiver');
const roleScopedSupertest = getService('roleScopedSupertest');
const samlAuth = getService('samlAuth');
const supertestWithoutAuth = getService('supertestWithoutAuth');

const expectConflictResponse = (resp: { [key: string]: any }) => {
expect(resp.body).to.only.have.keys(['error', 'message', 'statusCode']);
Expand Down Expand Up @@ -110,30 +105,14 @@ export function createTestSuiteFactory({ getService }: DeploymentAgnosticFtrProv
(describeFn: DescribeFn) =>
(description: string, { user, spaceId, tests }: CreateTestDefinition) => {
describeFn(description, () => {
let supertest: SupertestWithRoleScopeType | SuperTestAgent;
let supertest: SupertestWithRoleScopeType;

before(async () => {
if (user) {
const isBuiltIn = isBuiltInRole(user.role);
if (!isBuiltIn) {
await samlAuth.setCustomRole(getRoleDefinitionForUser(user));
}
supertest = await roleScopedSupertest.getSupertestWithRoleScope(
isBuiltIn ? user.role : 'customRole',
{
useCookieHeader: true,
withInternalHeaders: true,
}
);
} else {
supertest = supertestWithoutAuth;
}
supertest = await roleScopedSupertest.getSupertestWithRoleScope(user!);
});

after(async () => {
if (user) {
await (supertest as SupertestWithRoleScopeType).destroy();
}
await supertest.destroy();
});

beforeEach(() =>
Expand Down
198 changes: 0 additions & 198 deletions x-pack/test/spaces_api_integration/common/suites/create.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { Agent as SuperTestAgent } from 'supertest';

import { ALL_SAVED_OBJECT_INDICES } from '@kbn/core-saved-objects-server';
import expect from '@kbn/expect';
import expect from '@kbn/expect/expect';

import type {
DeploymentAgnosticFtrProviderContext,
SupertestWithRoleScopeType,
} from '../../deployment_agnostic/ftr_provider_context';
import { getRoleDefinitionForUser, isBuiltInRole } from '../lib/authentication';
import { MULTI_NAMESPACE_SAVED_OBJECT_TEST_CASES as CASES } from '../lib/saved_object_test_cases';
import { getAggregatedSpaceData, getTestScenariosForSpace } from '../lib/space_test_utils';
import type { DescribeFn, TestDefinitionAuthentication } from '../lib/types';
Expand All @@ -36,11 +34,9 @@ interface DeleteTestDefinition {
}

export function deleteTestSuiteFactory({ getService }: DeploymentAgnosticFtrProviderContext) {
const roleScopedSupertest = getService('roleScopedSupertest');
const samlAuth = getService('samlAuth');
const supertestWithoutAuth = getService('supertestWithoutAuth');
const esArchiver = getService('esArchiver');
const es = getService('es');
const roleScopedSupertest = getService('roleScopedSupertest');

const createExpectResult = (expectedResult: any) => (resp: { [key: string]: any }) => {
expect(resp.body).to.eql(expectedResult);
Expand Down Expand Up @@ -206,29 +202,13 @@ export function deleteTestSuiteFactory({ getService }: DeploymentAgnosticFtrProv
(describeFn: DescribeFn) =>
(description: string, { user, spaceId, tests }: DeleteTestDefinition) => {
describeFn(description, () => {
let supertest: SupertestWithRoleScopeType | SuperTestAgent;
let supertest: SupertestWithRoleScopeType;

before(async () => {
if (user) {
const isBuiltIn = isBuiltInRole(user.role);
if (!isBuiltIn) {
await samlAuth.setCustomRole(getRoleDefinitionForUser(user));
}
supertest = await roleScopedSupertest.getSupertestWithRoleScope(
isBuiltIn ? user.role : 'customRole',
{
useCookieHeader: true,
withInternalHeaders: true,
}
);
} else {
supertest = supertestWithoutAuth;
}
supertest = await roleScopedSupertest.getSupertestWithRoleScope(user!);
});
after(async () => {
if (user) {
await (supertest as SupertestWithRoleScopeType).destroy();
}
await supertest.destroy();
});

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,17 @@ export function getTestSuiteFactory(context: DeploymentAgnosticFtrProviderContex
(describeFn: DescribeFn) =>
(description: string, { user, currentSpaceId, spaceId, tests }: GetTestDefinition) => {
describeFn(description, () => {
let supertest: SupertestWithRoleScopeType | SuperTestAgent;
const roleScopedSupertest = context.getService('roleScopedSupertest');
let supertest: SupertestWithRoleScopeType;

before(async () => {
supertest = await getSupertest(context, user);
supertest = await roleScopedSupertest.getSupertestWithRoleScope(user!);
await esArchiver.load(
'x-pack/test/spaces_api_integration/common/fixtures/es_archiver/saved_objects/spaces'
);
});
after(async () => {
await maybeDestroySupertest(supertest);
await supertest.destroy();
await esArchiver.unload(
'x-pack/test/spaces_api_integration/common/fixtures/es_archiver/saved_objects/spaces'
);
Expand Down
Loading

0 comments on commit 1464f66

Please sign in to comment.