From fac981eafd25e44b70840fcd275991cf8fc596b7 Mon Sep 17 00:00:00 2001 From: Dzmitry Lemechko Date: Thu, 7 Dec 2023 14:24:13 +0100 Subject: [PATCH] clean code --- packages/kbn-test/src/auth/helper.ts | 14 +++----------- packages/kbn-test/src/auth/session_manager.ts | 8 +------- packages/kbn-test/src/auth/types.ts | 7 +++++++ .../functional/page_objects/svl_common_page.ts | 2 +- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/packages/kbn-test/src/auth/helper.ts b/packages/kbn-test/src/auth/helper.ts index dcd9ce01d8b5d..d13e3ef69f37b 100644 --- a/packages/kbn-test/src/auth/helper.ts +++ b/packages/kbn-test/src/auth/helper.ts @@ -7,17 +7,9 @@ */ import * as fs from 'fs'; -import { User } from './session_manager'; +import { Role, User } from './types'; -export const getProjectType = (serverArgs: string[]) => { - const svlArg = serverArgs.filter((arg) => arg.startsWith('--serverless')); - if (svlArg.length === 0) { - throw new Error('--serverless argument is missing in kbnTestServer.serverArgs'); - } - return svlArg[0].split('=')[1]; -}; - -export const readCloudUsersFromFile = (filePath: string): Array<[string, User]> => { +export const readCloudUsersFromFile = (filePath: string): Array<[Role, User]> => { if (!fs.existsSync(filePath)) { throw new Error(`Please define user roles with email/password in ${filePath}`); } @@ -26,5 +18,5 @@ export const readCloudUsersFromFile = (filePath: string): Array<[string, User]> throw new Error(`'${filePath}' is empty: no roles are defined`); } - return Object.entries(JSON.parse(data)) as Array<[string, User]>; + return Object.entries(JSON.parse(data)) as Array<[Role, User]>; }; diff --git a/packages/kbn-test/src/auth/session_manager.ts b/packages/kbn-test/src/auth/session_manager.ts index 82f8432c73eee..ece9d3b8362d0 100644 --- a/packages/kbn-test/src/auth/session_manager.ts +++ b/packages/kbn-test/src/auth/session_manager.ts @@ -13,13 +13,7 @@ import Url from 'url'; import { KbnClient } from '../kbn_client'; import { readCloudUsersFromFile } from './helper'; import { createCloudSAMLSession, createLocalSAMLSession, Session } from './saml_auth'; - -export interface User { - readonly email: string; - readonly password: string; -} - -export type Role = string; +import { Role, User } from './types'; export interface HostOptions { protocol: 'http' | 'https'; diff --git a/packages/kbn-test/src/auth/types.ts b/packages/kbn-test/src/auth/types.ts index 6eb3812dc6a9b..45e5b78b0ba38 100644 --- a/packages/kbn-test/src/auth/types.ts +++ b/packages/kbn-test/src/auth/types.ts @@ -31,3 +31,10 @@ export interface CreateSamlSessionParams { password: string; log: ToolingLog; } + +export interface User { + readonly email: string; + readonly password: string; +} + +export type Role = string; diff --git a/x-pack/test_serverless/functional/page_objects/svl_common_page.ts b/x-pack/test_serverless/functional/page_objects/svl_common_page.ts index 3709efe36ea1d..ab7eef0b32799 100644 --- a/x-pack/test_serverless/functional/page_objects/svl_common_page.ts +++ b/x-pack/test_serverless/functional/page_objects/svl_common_page.ts @@ -54,7 +54,7 @@ export function SvlCommonPageProvider({ getService, getPageObjects }: FtrProvide const { body } = await supertestWithoutAuth .get('/internal/security/me') .set(svlCommonApi.getInternalRequestHeader()) - .set('Cookie', `sid=${browserCookies[0].value}`); + .set({Cookie: `sid=${browserCookies[0].value}`}); const userData = await svlUserManager.getUserData(role); // email returned from API call must match the email for the specified role