Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ export { IndexPatternsService } from './services/index_patterns';
export { RandomnessService } from './services/randomness';
export { KibanaSupertestProvider, ElasticsearchSupertestProvider } from './services/supertest';
export { retryForSuccess } from './services/retry/retry_for_success';
export { SecurityService } from './services/security';
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { RandomnessService } from './randomness';
import { SupertestWithoutAuthProvider } from './supertest_without_auth';
import { SamlAuthProvider } from './saml_auth';
import { KibanaSupertestProvider, ElasticsearchSupertestProvider } from './supertest';
import { SecurityServiceProvider } from './security';

export const services = {
es: EsProvider,
Expand All @@ -38,4 +39,5 @@ export const services = {
supertest: KibanaSupertestProvider,
esSupertest: ElasticsearchSupertestProvider,
supertestWithoutAuth: SupertestWithoutAuthProvider,
security: SecurityServiceProvider,
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import { format as formatUrl } from 'url';
import supertest from 'supertest';

import type { Browser } from '../browser';
import type { TestSubjects } from '../test_subjects';
import { Role } from './role';
import { User } from './user';
import { FtrService, FtrProviderContext } from '../ftr_provider_context';
Expand All @@ -23,15 +21,13 @@ export class TestUser extends FtrService {
private readonly config = this.ctx.getService('config');
private readonly log = this.ctx.getService('log');

private readonly browser: Browser | void =
private readonly browser =
// browser service is not normally available in common.
this.ctx.hasService('browser') ? (this.ctx.getService('browser' as any) as Browser) : undefined;
this.ctx.hasService('browser') ? this.ctx.getService('browser' as any) : undefined;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The construction here was not ideal: the service tries to determine if it's loaded for a UI suite and in that case adds steps in the UI after the test user role has been updated. Importing the types from the UI services would introduce a cyclic dependency. I've decided to remove the typing here as it's only a few lines of code making use of it. The alternative would probably be to move the browser and test subject services to yet another package so we can import from this common package as well as from the UI package, but to me that seemed too much effort for the gained benefit.


private readonly testSubjects: TestSubjects | undefined =
private readonly testSubjects =
// testSubject service is not normally available in common.
this.ctx.hasService('testSubjects')
? (this.ctx.getService('testSubjects' as any) as TestSubjects)
: undefined;
this.ctx.hasService('testSubjects') ? this.ctx.getService('testSubjects' as any) : undefined;

constructor(
ctx: FtrProviderContext,
Expand Down Expand Up @@ -129,7 +125,7 @@ export async function createTestUserService(ctx: FtrProviderContext, role: Role,

// delete the test_user if present (will it error if the user doesn't exist?)
try {
await user.delete(TEST_USER_NAME);
await user.delete(TEST_USER_NAME, { retries: 1 });
} catch (exception) {
log.debug('no test user to delete');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ export class User {
this.log.debug(`created user ${username}`);
}

public async delete(username: string) {
public async delete(username: string, options?: { retries?: number }) {
this.log.debug(`deleting user ${username}`);
const { data, status, statusText } = await this.kbnClient.request({
path: `/internal/security/users/${username}`,
method: 'DELETE',
retries: options?.retries,
});
if (status !== 204) {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ export {
} from './services/remote/network_profiles';
export type { TimeoutOpt } from './types';
export { TestSubjects } from './services/test_subjects';
export { SecurityService } from './services/security';
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { FindProvider } from './find';
import { TestSubjects } from './test_subjects';
import { BrowserProvider } from './browser';
import { ToastsService } from './toasts';
import { SecurityServiceProvider } from './security';

export const services = {
retryOnStale: RetryOnStaleProvider,
Expand All @@ -22,5 +21,4 @@ export const services = {
testSubjects: TestSubjects,
browser: BrowserProvider,
toasts: ToastsService,
security: SecurityServiceProvider,
};
5 changes: 1 addition & 4 deletions test/common/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import { commonFunctionalServices } from '@kbn/ftr-common-functional-services';
import { commonFunctionalUIServices } from '@kbn/ftr-common-functional-ui-services';

// pick only services that work for any FTR config, e.g. 'samlAuth' requires SAML setup in config file
const {
Expand All @@ -26,11 +25,9 @@ const {
supertest,
esSupertest,
supertestWithoutAuth,
security,
} = commonFunctionalServices;

// pick what was there previously
const { security } = commonFunctionalUIServices;

export const services = {
es,
esArchiver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import type { Agent as SuperTestAgent } from 'supertest';

import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { CLOUD_SECURITY_PLUGIN_VERSION } from '@kbn/cloud-security-posture-plugin/common/constants';
import { SecurityService } from '@kbn/ftr-common-functional-ui-services';
import { RoleCredentials } from '@kbn/ftr-common-functional-services';
import { RoleCredentials, SecurityService } from '@kbn/ftr-common-functional-services';

export async function createPackagePolicy(
supertest: SuperTestAgent,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
ELASTIC_HTTP_VERSION_HEADER,
X_ELASTIC_INTERNAL_ORIGIN_REQUEST,
} from '@kbn/core-http-common';
import type { SecurityService } from '@kbn/ftr-common-functional-ui-services';
import type { SecurityService } from '@kbn/ftr-common-functional-services';
import basicClusterFixture from './fixtures/basiccluster.json';
import multiClusterFixture from './fixtures/multicluster.json';
import type { FtrProviderContext } from '../../ftr_provider_context';
Expand Down
2 changes: 0 additions & 2 deletions x-pack/test/common/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import { services as kibanaApiIntegrationServices } from '@kbn/test-suites-src/api_integration/services';
import { commonFunctionalServices } from '@kbn/ftr-common-functional-services';
import { commonFunctionalUIServices } from '@kbn/ftr-common-functional-ui-services';
import { InfraLogViewsServiceProvider } from './infra_log_views';
import { SpacesServiceProvider } from './spaces';
import { SearchSecureService } from './search_secure';
Expand All @@ -16,7 +15,6 @@ import { InfraSynthtraceKibanaClientProvider } from './infra_synthtrace_kibana_c

export const services = {
...commonFunctionalServices,
...commonFunctionalUIServices,
infraLogViews: InfraLogViewsServiceProvider,
supertest: kibanaApiIntegrationServices.supertest,
spaces: SpacesServiceProvider,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/fleet_api_integration/apis/test_users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { SecurityService } from '@kbn/ftr-common-functional-ui-services';
import type { SecurityService } from '@kbn/ftr-common-functional-services';

export const testUsers: {
[rollName: string]: { username: string; password: string; permissions?: any };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/* eslint-disable no-console */

import { difference, union } from 'lodash';
import type { SecurityService } from '@kbn/ftr-common-functional-ui-services';
import type { SecurityService } from '@kbn/ftr-common-functional-services';
import { Elasticsearch, Kibana } from '..';
import { callKibana, isAxiosError } from './call_kibana';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/
import { asyncForEach } from '@kbn/std';
import type { SecurityService } from '@kbn/ftr-common-functional-ui-services';
import type { SecurityService } from '@kbn/ftr-common-functional-services';
import { ProfilingUsername, profilingUsers } from './authentication';
import { AbortError, callKibana } from './helpers/call_kibana';
import { createOrUpdateUser } from './helpers/create_or_update_user';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { SecurityService } from '@kbn/ftr-common-functional-ui-services';
import type { SecurityService } from '@kbn/ftr-common-functional-services';

export const usersAndRolesFactory = (security: SecurityService) => ({
createRole: async ({ name, privileges }: { name: string; privileges: any }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"@kbn/elastic-assistant-common",
"@kbn/search-types",
"@kbn/security-plugin",
"@kbn/ftr-common-functional-ui-services",
"@kbn/spaces-plugin",
"@kbn/elastic-assistant-plugin",
"@kbn/test-suites-src",
Expand Down
Loading