Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding functionality to switch user terminal to dom. #15892

Merged
merged 6 commits into from
Feb 12, 2020
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
7 changes: 7 additions & 0 deletions tests/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export * from './driver/IDriver';
export * from './utils/DriverHelper';
export * from './utils/Logger';
export * from './utils/NameGenerator';
export * from './utils/PreferencesHandler';
export * from './utils/requestHandlers/CheApiRequestHandler';
export * from './utils/requestHandlers/headers/CheMultiuserAuthorizationHeaderHandler';
export * from './utils/requestHandlers/headers/CheSingleUserAuthorizationHeaderHandler';
export * from './utils/requestHandlers/headers/IAuthorizationHeaderHandler';
export * from './utils/requestHandlers/tokens/CheMultiuserTokenHandler';
export * from './utils/requestHandlers/tokens/ITokenHandler';
export * from './utils/ScreenCatcher';
export * from './utils/workspace/ITestWorkspaceUtil';
export * from './utils/workspace/TestWorkspaceUtil';
Expand Down
15 changes: 14 additions & 1 deletion tests/e2e/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ import { OcpWebConsolePage } from './pageobjects/openshift/OcpWebConsolePage';
import { OpenWorkspaceWidget } from './pageobjects/ide/OpenWorkspaceWidget';
import { CheLoginPage } from './pageobjects/openshift/CheLoginPage';
import { NotificationCenter } from './pageobjects/ide/NotificationCenter';
import { PreferencesHandler } from './utils/PreferencesHandler';
import { IAuthorizationHeaderHandler } from './utils/requestHandlers/headers/IAuthorizationHeaderHandler';
import { CheMultiuserAuthorizationHeaderHandler } from './utils/requestHandlers/headers/CheMultiuserAuthorizationHeaderHandler';
import { CheMultiuserTokenHandler } from './utils/requestHandlers/tokens/CheMultiuserTokenHandler';
import { CheSingleUserAuthorizationHeaderHandler } from './utils/requestHandlers/headers/CheSingleUserAuthorizationHeaderHandler';
import { ITokenHandler } from './utils/requestHandlers/tokens/ITokenHandler';
import { CheApiRequestHandler } from './utils/requestHandlers/CheApiRequestHandler';


const e2eContainer: Container = new Container();
Expand All @@ -55,13 +62,18 @@ e2eContainer.bind<ITestWorkspaceUtil>(TYPES.WorkspaceUtil).to(TestWorkspaceUtil)
e2eContainer.bind<IOcpLoginPage>(TYPES.OcpLogin).to(OcpLoginByTempAdmin).inSingletonScope();

if (TestConstants.TS_SELENIUM_MULTIUSER) {
e2eContainer.bind<IAuthorizationHeaderHandler>(TYPES.IAuthorizationHeaderHandler).to(CheMultiuserAuthorizationHeaderHandler).inSingletonScope();
e2eContainer.bind<ITokenHandler>(TYPES.ITokenHandler).to(CheMultiuserTokenHandler).inSingletonScope();

if (JSON.parse(TestConstants.TS_SELENIUM_VALUE_OPENSHIFT_OAUTH)) {
e2eContainer.bind<ICheLoginPage>(TYPES.CheLogin).to(RegularUserOcpCheLoginPage).inSingletonScope();
} else {
e2eContainer.bind<ICheLoginPage>(TYPES.CheLogin).to(MultiUserLoginPage).inSingletonScope();
}

} else {
e2eContainer.bind<ICheLoginPage>(TYPES.CheLogin).to(SingleUserLoginPage).inSingletonScope();
e2eContainer.bind<IAuthorizationHeaderHandler>(TYPES.IAuthorizationHeaderHandler).to(CheSingleUserAuthorizationHeaderHandler).inSingletonScope();
}

e2eContainer.bind<ContextMenu>(CLASSES.ContextMenu).to(ContextMenu).inSingletonScope();
Expand All @@ -88,6 +100,7 @@ e2eContainer.bind<OcpWebConsolePage>(CLASSES.OcpWebConsolePage).to(OcpWebConsole
e2eContainer.bind<OpenWorkspaceWidget>(CLASSES.OpenWorkspaceWidget).to(OpenWorkspaceWidget).inSingletonScope();
e2eContainer.bind<CheLoginPage>(CLASSES.CheLoginPage).to(CheLoginPage).inSingletonScope();
e2eContainer.bind<NotificationCenter>(CLASSES.NotificationCenter).to(NotificationCenter).inSingletonScope();

e2eContainer.bind<PreferencesHandler>(CLASSES.PreferencesHandler).to(PreferencesHandler).inSingletonScope();
e2eContainer.bind<CheApiRequestHandler>(CLASSES.CheApiRequestHandler).to(CheApiRequestHandler).inSingletonScope();

export { e2eContainer };
10 changes: 8 additions & 2 deletions tests/e2e/inversify.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const TYPES = {
Driver: Symbol.for('Driver'),
CheLogin: Symbol.for('CheLogin'),
OcpLogin: Symbol.for('OcpLogin'),
WorkspaceUtil: Symbol.for('WorkspaceUtil')
WorkspaceUtil: Symbol.for('WorkspaceUtil'),
IAuthorizationHeaderHandler: Symbol.for('IAuthorizationHeaderHandler'),
ITokenHandler: Symbol.for('ITokenHandler')


};

const CLASSES = {
Expand Down Expand Up @@ -41,7 +45,9 @@ const CLASSES = {
ContextMenu: 'ContextMenu',
CheLoginPage: 'CheLoginPage',
TestWorkspaceUtil: 'TestWorkspaceUtil',
NotificationCenter: 'NotificationCenter'
NotificationCenter: 'NotificationCenter',
PreferencesHandler: 'PreferencesHandler',
CheApiRequestHandler: 'CheApiRequestHandler'
};

export { TYPES, CLASSES };
30 changes: 30 additions & 0 deletions tests/e2e/utils/PreferencesHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

import { injectable, inject } from 'inversify';
import { Logger } from './Logger';
import { CLASSES } from '../inversify.types';
import { CheApiRequestHandler } from './requestHandlers/CheApiRequestHandler';

@injectable()
export class PreferencesHandler {

constructor(@inject(CLASSES.CheApiRequestHandler) private readonly requestHandler: CheApiRequestHandler) {
}

public async setTerminalType(type: string) {
Logger.debug('PreferencesHandler.setTerminalToDom');
const response = await this.requestHandler.get('api/preferences');
let userPref = response.data;
try {
let theiaPref = JSON.parse(userPref['theia-user-preferences']);
theiaPref['terminal.integrated.rendererType'] = type;
userPref['theia-user-preferences'] = JSON.stringify(theiaPref);
this.requestHandler.post('api/preferences', userPref);
} catch (e) {
// setting terminal before running a workspace, so no theia preferences are set
let theiaPref = `{ "terminal.integrated.rendererType":"${type}" }`;
userPref['theia-user-preferences'] = JSON.stringify(JSON.parse(theiaPref));
this.requestHandler.post('api/preferences', userPref);
}

}
}
37 changes: 37 additions & 0 deletions tests/e2e/utils/requestHandlers/CheApiRequestHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*********************************************************************
* Copyright (c) 2019 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import axios, { AxiosResponse } from 'axios';
import { TestConstants } from '../../TestConstants';
import { TYPES } from '../../inversify.types';
import { inject, injectable } from 'inversify';
import { IAuthorizationHeaderHandler } from './headers/IAuthorizationHeaderHandler';

@injectable()
export class CheApiRequestHandler {
constructor(@inject(TYPES.IAuthorizationHeaderHandler) private readonly headerHandler: IAuthorizationHeaderHandler) { }

async get(relativeUrl: string): Promise<AxiosResponse> {
return await axios.get(this.assembleUrl(relativeUrl), await this.headerHandler.get());
}

async post(relativeUrl: string, data?: string): Promise<AxiosResponse> {
return await axios.post(this.assembleUrl(relativeUrl), data, await this.headerHandler.get());
}

async delete(relativeUrl: string): Promise<AxiosResponse> {
return await axios.delete(this.assembleUrl(relativeUrl), await this.headerHandler.get());
}

private assembleUrl(relativeUrl: string): string {
return `${TestConstants.TS_SELENIUM_BASE_URL}/${relativeUrl}`;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*********************************************************************
* Copyright (c) 2019 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
import { AxiosRequestConfig } from 'axios';

import { TYPES } from '../../../inversify.types';
import { IAuthorizationHeaderHandler } from './IAuthorizationHeaderHandler';
import { injectable, inject } from 'inversify';
import { ITokenHandler } from '../tokens/ITokenHandler';

@injectable()
export class CheMultiuserAuthorizationHeaderHandler implements IAuthorizationHeaderHandler {

constructor(@inject(TYPES.ITokenHandler) private readonly tokenHandler: ITokenHandler) {
}

async get(): Promise<AxiosRequestConfig> {
const token = await this.tokenHandler.get();
return { headers: { 'Authorization': `Bearer ${token}` } };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*********************************************************************
* Copyright (c) 2019 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import { IAuthorizationHeaderHandler } from './IAuthorizationHeaderHandler';
import { injectable } from 'inversify';
import { AxiosRequestConfig } from 'axios';

@injectable()
export class CheSingleUserAuthorizationHeaderHandler implements IAuthorizationHeaderHandler {
async get() : Promise<AxiosRequestConfig> {
// no headers needs to be set to single user
return {};
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*********************************************************************
* Copyright (c) 2019 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import { AxiosRequestConfig } from 'axios';

export interface IAuthorizationHeaderHandler {
get(): Promise<AxiosRequestConfig>;
}
42 changes: 42 additions & 0 deletions tests/e2e/utils/requestHandlers/tokens/CheMultiuserTokenHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*********************************************************************
* Copyright (c) 2019 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
import axios from 'axios';
import querystring from 'querystring';
import { injectable } from 'inversify';
import { TestConstants } from '../../../TestConstants';
import { ITokenHandler } from './ITokenHandler';

@injectable()
export class CheMultiuserTokenHandler implements ITokenHandler {
async get(): Promise<string> {
let params = {};

let keycloakUrl = TestConstants.TS_SELENIUM_BASE_URL;
const keycloakAuthSuffix = '/auth/realms/che/protocol/openid-connect/token';
keycloakUrl = keycloakUrl.replace('che', 'keycloak') + keycloakAuthSuffix;
params = {
client_id: 'che-public',
username: TestConstants.TS_SELENIUM_USERNAME,
password: TestConstants.TS_SELENIUM_PASSWORD,
grant_type: 'password'
};

try {
const responseToObtainBearerToken = await axios.post(keycloakUrl, querystring.stringify(params));
return responseToObtainBearerToken.data.access_token;
} catch (err) {
console.log(`Can not get bearer token. URL used: ${keycloakUrl}`);
throw err;
}

}
}


14 changes: 14 additions & 0 deletions tests/e2e/utils/requestHandlers/tokens/ITokenHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*********************************************************************
* Copyright (c) 2019 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/


export interface ITokenHandler {
get(): Promise<string>;
}