Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
Adding patch for request logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrewTSW committed Apr 7, 2020
1 parent b7b7473 commit 7b19313
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
4 changes: 3 additions & 1 deletion dockerfiles/e2e-saas/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ fi
if [ -z $DEBUG_LEVEL ]; then
DEBUG_LEVEL="DEBUG"
fi
if [ -z $DEBUG_LEVEL ]; then
DEBUG_LEVEL="DEBUG"
fi

cd rh-che
length=${#USERNAME}
Expand Down Expand Up @@ -145,7 +148,6 @@ echo "Applying patches..."
# currently in /tmp/rh-che folder
patch -u ../e2e/pageobjects/dashboard/Dashboard.ts -i ../test_patches/Dashboard.patch
patch -u ../e2e/utils/requestHandlers/CheApiRequestHandler.ts -i ../test_patches/CheApiRequestHandler.patch
patch -u ../e2e/package.json -i ../test_patches/upstream_package.patch

# rebuild upstream patched code
cd ../e2e && npm i && tsc && cd ../rh-che
Expand Down
50 changes: 27 additions & 23 deletions dockerfiles/e2e-saas/test_patches/CheApiRequestHandler.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/tests/e2e/utils/requestHandlers/CheApiRequestHandler.ts b/tests/e2e/utils/requestHandlers/CheApiRequestHandler.ts
index 4d9ab66fa9..5d061062d1 100644
index 4d9ab66fa9..48ef828d30 100644
--- a/tests/e2e/utils/requestHandlers/CheApiRequestHandler.ts
+++ b/tests/e2e/utils/requestHandlers/CheApiRequestHandler.ts
@@ -8,11 +8,12 @@
@@ -8,7 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

Expand All @@ -11,26 +11,24 @@ index 4d9ab66fa9..5d061062d1 100644
import { TestConstants } from '../../TestConstants';
import { TYPES } from '../../inversify.types';
import { inject, injectable } from 'inversify';
import { IAuthorizationHeaderHandler } from './headers/IAuthorizationHeaderHandler';
+import lodash from 'lodash';
@@ -16,6 +16,46 @@ import { IAuthorizationHeaderHandler } from './headers/IAuthorizationHeaderHandl

@injectable()
export class CheApiRequestHandler {
@@ -30,6 +31,37 @@ export class CheApiRequestHandler {
return await axios.delete(this.assembleUrl(relativeUrl), await this.headerHandler.get());
}

+
+ /**
+ * This method adds a request interceptor into axios request interceptors list and returns an ID of the interceptor
+ */
+ public static enableRequestInteceptor(): number {
+ console.log(`CheApiRequestHandler.enableRequestInterceptor`);
+ return axios.interceptors.request.use( request => {
+ if (TestConstants.TS_SELENIUM_LOG_LEVEL === "TRACE") {
+ let request_censored: AxiosRequestConfig = lodash.cloneDeep(request);
+ request_censored.headers['Authorization'] = "CENSORED";
+ console.log(`RequestHandler request:\n`, request_censored);
+ }
+ try {
+ let request_censored: AxiosRequestConfig = JSON.parse(JSON.stringify(request));
+ request_censored.headers['Authorization'] = 'CENSORED';
+ console.log(`RequestHandler request:\n`, request_censored);
+ } catch (err) {
+ console.log(`RequestHandler request: Failed to deep clone AxiosRequestConfig:`, err);
+ }
+ return request;
+ });
+ }
Expand All @@ -41,16 +39,22 @@ index 4d9ab66fa9..5d061062d1 100644
+ public static enableResponseInterceptor(): number {
+ console.log(`CheApiRequestHandler.enableResponseRedirects`);
+ return axios.interceptors.response.use( response => {
+ if (TestConstants.TS_SELENIUM_LOG_LEVEL === "TRACE") {
+ let response_censored: AxiosResponse = lodash.cloneDeep(response);
+ response_censored.config.headers["Authorization"] = "CENSORED";
+ response_censored.request = "CENSORED";
+ console.log(`RequestHandler response:\n`, response_censored);
+ }
+ try {
+ let response_censored: AxiosResponse = JSON.parse(JSON.stringify(response, (key, value) => {
+ switch (key) {
+ case 'request': return 'CENSORED';
+ default: return value;
+ }
+ }));
+ response_censored.config.headers['Authorization'] = 'CENSORED';
+ console.log(`RequestHandler response:\n`, response_censored);
+ } catch (err) {
+ console.log(`RequestHandler response: Failed to deep clone AxiosResponse:`, err);
+ }
+ return response;
+ })
+ });
+ }
+
private assembleUrl(relativeUrl: string): string {
return `${TestConstants.TS_SELENIUM_BASE_URL}/${relativeUrl}`;
}
constructor(@inject(TYPES.IAuthorizationHeaderHandler) private readonly headerHandler: IAuthorizationHeaderHandler) { }

async get(relativeUrl: string): Promise<AxiosResponse> {
1 change: 0 additions & 1 deletion e2e-saas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@types/node": "^11.13.4",
"@types/rimraf": "^2.0.3",
"@types/selenium-webdriver": "^3.0.16",
"@types/lodash": "^4.14.149",
"axios": "^0.19.2",
"chai": "^4.2.0",
"chromedriver": "^2.46.0",
Expand Down
6 changes: 4 additions & 2 deletions e2e-saas/utils/RhCheReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ class RhCheReporter extends mocha.reporters.Spec {
console.log(launchInformation);

rm.sync(TestConstants.TS_SELENIUM_REPORT_FOLDER);
CheApiRequestHandler.enableRequestInteceptor();
CheApiRequestHandler.enableResponseInterceptor();
if (TestConstants.TS_SELENIUM_LOG_LEVEL === "TRACE") {
CheApiRequestHandler.enableRequestInteceptor();
CheApiRequestHandler.enableResponseInterceptor();
}
preferencesHalder.setConfirmExit(AskForConfirmationType.never);
});

Expand Down

0 comments on commit 7b19313

Please sign in to comment.