Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlemeshko committed Dec 7, 2023
1 parent 740ab77 commit fac981e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
14 changes: 3 additions & 11 deletions packages/kbn-test/src/auth/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand All @@ -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]>;
};
8 changes: 1 addition & 7 deletions packages/kbn-test/src/auth/session_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 7 additions & 0 deletions packages/kbn-test/src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ export interface CreateSamlSessionParams {
password: string;
log: ToolingLog;
}

export interface User {
readonly email: string;
readonly password: string;
}

export type Role = string;
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fac981e

Please sign in to comment.