From 00df0a3dd2b002c23af8a4266d631b3d73da85ac Mon Sep 17 00:00:00 2001 From: Rudy Flores <68666202+rudyflores@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:10:57 -0500 Subject: [PATCH 1/8] Attach authentication header to proxy agent Signed-off-by: Rudy Flores <68666202+rudyflores@users.noreply.github.com> --- .../src/rest/src/client/AbstractRestClient.ts | 3 --- .../src/rest/src/client/ProxySettings.ts | 22 +++++++++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/imperative/src/rest/src/client/AbstractRestClient.ts b/packages/imperative/src/rest/src/client/AbstractRestClient.ts index 9da363a5cd..c4f908709c 100644 --- a/packages/imperative/src/rest/src/client/AbstractRestClient.ts +++ b/packages/imperative/src/rest/src/client/AbstractRestClient.ts @@ -476,9 +476,6 @@ export abstract class AbstractRestClient { this.mLogger.info(`Proxy setting "${proxyUrl.href}" will not be used as hostname was found listed under "no_proxy" setting.`); } else { this.mLogger.info(`Using the following proxy setting for the request: ${proxyUrl.href}`); - if (this.session.ISession.proxy?.proxy_authorization) { - reqHeaders.push({ 'Proxy-Authorization': this.session.ISession.proxy.proxy_authorization}); - } options.agent = ProxySettings.getProxyAgent(this.session.ISession); } } diff --git a/packages/imperative/src/rest/src/client/ProxySettings.ts b/packages/imperative/src/rest/src/client/ProxySettings.ts index c414003a64..ab0d3ae6d6 100644 --- a/packages/imperative/src/rest/src/client/ProxySettings.ts +++ b/packages/imperative/src/rest/src/client/ProxySettings.ts @@ -45,12 +45,20 @@ export class ProxySettings { */ public static getProxyAgent(session: ISession): Agent | undefined { const proxySetting = this.getProxySettings(session); + const proxyUrl = proxySetting.proxyUrl; + const proxyAuthorizationHeader = proxySetting.authSetting; if (proxySetting?.protocol === HTTP_PROTOCOL) { - return new HttpProxyAgent(proxySetting.proxyUrl); + const proxyAgentOptions = proxyAuthorizationHeader + ? { headers: { 'Proxy-Authorization': proxyAuthorizationHeader } } + : undefined; + return new HttpProxyAgent(proxyUrl, proxyAgentOptions); } if (proxySetting?.protocol === HTTPS_PROTOCOL) { - return new HttpsProxyAgent(proxySetting.proxyUrl, - { rejectUnauthorized: session.rejectUnauthorized ?? true }); + const proxyAgentOptions = { + rejectUnauthorized: session.rejectUnauthorized ?? true, + headers: { 'Proxy-Authorization': proxyAuthorizationHeader } + }; + return new HttpsProxyAgent(proxyUrl, proxyAgentOptions); } } @@ -109,6 +117,11 @@ export class ProxySettings { envVariable = session.proxy?.https_proxy ?? this.getHttpsEnvVariables(); } const proxyUrl = this.checkUrl(envVariable); + + const authSetting = session.proxy?.proxy_authorization; + if (authSetting) { + return {proxyUrl, protocol, authSetting}; + } if (proxyUrl) { return {proxyUrl, protocol}; } @@ -174,5 +187,6 @@ export class ProxySettings { */ interface ProxySetting { proxyUrl: URL, - protocol: HTTP_PROTOCOL_CHOICES + protocol: HTTP_PROTOCOL_CHOICES, + authSetting?: string } From bf6db6be16b14cf136273796e41e229fdca10286 Mon Sep 17 00:00:00 2001 From: Rudy Flores <68666202+rudyflores@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:28:04 -0500 Subject: [PATCH 2/8] Code cleanup Signed-off-by: Rudy Flores <68666202+rudyflores@users.noreply.github.com> --- .../src/rest/src/client/ProxySettings.ts | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/packages/imperative/src/rest/src/client/ProxySettings.ts b/packages/imperative/src/rest/src/client/ProxySettings.ts index ab0d3ae6d6..6132e9e20b 100644 --- a/packages/imperative/src/rest/src/client/ProxySettings.ts +++ b/packages/imperative/src/rest/src/client/ProxySettings.ts @@ -45,20 +45,17 @@ export class ProxySettings { */ public static getProxyAgent(session: ISession): Agent | undefined { const proxySetting = this.getProxySettings(session); - const proxyUrl = proxySetting.proxyUrl; - const proxyAuthorizationHeader = proxySetting.authSetting; + const proxyOptions = {} as ProxyOptions; + const authHeader = ProxySettings.getProxyAuthHeader(proxySetting); + if(authHeader) { + proxyOptions.headers = authHeader; + } if (proxySetting?.protocol === HTTP_PROTOCOL) { - const proxyAgentOptions = proxyAuthorizationHeader - ? { headers: { 'Proxy-Authorization': proxyAuthorizationHeader } } - : undefined; - return new HttpProxyAgent(proxyUrl, proxyAgentOptions); + return new HttpProxyAgent(proxySetting.proxyUrl, proxyOptions); } if (proxySetting?.protocol === HTTPS_PROTOCOL) { - const proxyAgentOptions = { - rejectUnauthorized: session.rejectUnauthorized ?? true, - headers: { 'Proxy-Authorization': proxyAuthorizationHeader } - }; - return new HttpsProxyAgent(proxyUrl, proxyAgentOptions); + proxyOptions.rejectUnauthorized = session.rejectUnauthorized ?? true; + return new HttpsProxyAgent(proxySetting.proxyUrl, proxyOptions); } } @@ -96,6 +93,12 @@ export class ProxySettings { return false; } + private static getProxyAuthHeader(proxySetting: ProxySetting): { [key: string]: string } | undefined { + return proxySetting.authSetting + ? { 'Proxy-Authorization': proxySetting.authSetting } + : undefined; + } + /** * Parses environment variables for proxy servers. * @private @@ -190,3 +193,8 @@ interface ProxySetting { protocol: HTTP_PROTOCOL_CHOICES, authSetting?: string } + +interface ProxyOptions { + headers?: { [key: string]: string }, + rejectUnauthorized?: boolean +} From 4eb68d89932cc01d90201cabac72e6606d18c4cd Mon Sep 17 00:00:00 2001 From: Rudy Flores <68666202+rudyflores@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:53:38 -0500 Subject: [PATCH 3/8] Add CHANGELOG.md Signed-off-by: Rudy Flores <68666202+rudyflores@users.noreply.github.com> --- packages/imperative/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/imperative/CHANGELOG.md b/packages/imperative/CHANGELOG.md index ded21b7c84..52915b7f41 100644 --- a/packages/imperative/CHANGELOG.md +++ b/packages/imperative/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to the Imperative package will be documented in this file. - BugFix: Modified 8.8.2 bugfix to correct web help alias. [#2361](https://github.com/zowe/zowe-cli/pull/2361) - BugFix: Resolved issue where special characters could be corrupted when downloading a large file. [#2366](https://github.com/zowe/zowe-cli/pull/2366) +- BugFix: Modified location of Proxy-Authorization header to be located in the agent instead of the request. ## `8.8.2` From cd5b2cf6437c978dd3738b1ca284c5b5217f38df Mon Sep 17 00:00:00 2001 From: Rudy Flores <68666202+rudyflores@users.noreply.github.com> Date: Fri, 13 Dec 2024 15:25:26 -0500 Subject: [PATCH 4/8] Fix broken unit tests Signed-off-by: Rudy Flores <68666202+rudyflores@users.noreply.github.com> --- .../client/AbstractRestClient.unit.test.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/packages/imperative/src/rest/__tests__/client/AbstractRestClient.unit.test.ts b/packages/imperative/src/rest/__tests__/client/AbstractRestClient.unit.test.ts index fcd7669552..98005ccff5 100644 --- a/packages/imperative/src/rest/__tests__/client/AbstractRestClient.unit.test.ts +++ b/packages/imperative/src/rest/__tests__/client/AbstractRestClient.unit.test.ts @@ -1502,22 +1502,6 @@ describe("AbstractRestClient tests", () => { const result = privateRestClient.buildOptions(resource, request, reqHeaders); expect(Object.keys(result)).toContain('agent'); }); - - it('Should use session proxy options over env vars for proxy agent', () => { - restSession.ISession.proxy = { proxy_authorization: 'proxy_auth_string'}; - const resource = '/resource'; - const request = ''; - const reqHeaders: any[] = []; - const url = new URL('https://www.zowe.com'); - const proxyAgent = new HttpsProxyAgent(url, { rejectUnauthorized: true }); - getSystemProxyUrlSpy.mockReturnValue(url); - getProxyAgentSpy.mockReturnValue(proxyAgent); - setCertPemAuthSpy.mockReturnValue(true); - const headerSpy = jest.spyOn(privateRestClient, "appendHeaders"); - const result = privateRestClient.buildOptions(resource, request, reqHeaders); - expect(Object.keys(result)).toContain('agent'); - expect(headerSpy).toHaveBeenCalledWith([{'Proxy-Authorization': restSession.ISession.proxy.proxy_authorization}]); - }); }); }); }); From 312c16c381930b34c70ea2e6431e6b7db8f1692f Mon Sep 17 00:00:00 2001 From: Rudy Flores <68666202+rudyflores@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:17:56 -0500 Subject: [PATCH 5/8] Add code coverage Signed-off-by: Rudy Flores <68666202+rudyflores@users.noreply.github.com> --- .../client/ProxySettings.unit.test.ts | 155 ++++++++++++++---- .../src/rest/src/client/ProxySettings.ts | 93 ++++++----- 2 files changed, 180 insertions(+), 68 deletions(-) diff --git a/packages/imperative/src/rest/__tests__/client/ProxySettings.unit.test.ts b/packages/imperative/src/rest/__tests__/client/ProxySettings.unit.test.ts index 952b9e298f..9aeb24ca7b 100644 --- a/packages/imperative/src/rest/__tests__/client/ProxySettings.unit.test.ts +++ b/packages/imperative/src/rest/__tests__/client/ProxySettings.unit.test.ts @@ -1,13 +1,13 @@ /* -* This program and the accompanying materials are made available under the terms of the -* Eclipse Public License v2.0 which accompanies this distribution, and is available at -* https://www.eclipse.org/legal/epl-v20.html -* -* SPDX-License-Identifier: EPL-2.0 -* -* Copyright Contributors to the Zowe Project. -* -*/ + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + * + */ import * as process from "process"; @@ -23,7 +23,7 @@ describe("Proxy tests", () => { const session = { hostname: "fake.com", port: 443, - rejectUnauthorized: false + rejectUnauthorized: false, } as ISession; const privateProxy = ProxySettings as any; const httpUrl = "http://www.zowe.com"; @@ -31,7 +31,9 @@ describe("Proxy tests", () => { const noProxyList = "www.zowe.com, fake.com,ibm.com,broadcom.com "; const passedUrl = "passedurl.com"; let getProxySettingsSpy: jest.SpyInstance; + let getProxyAuthSettingSpy: jest.SpyInstance; let checkUrlSpy: jest.SpyInstance; + let matchesNoProxySettingsSpy: jest.SpyInstance; describe("recognise passed proxy values in session", () => { const noProxySpy = jest.spyOn(privateProxy, "matchesNoProxySettings"); @@ -40,7 +42,7 @@ describe("Proxy tests", () => { checkUrlSpy = jest.spyOn(privateProxy, "checkUrl"); const expected = { proxyUrl: passedUrl, - protocol: HTTPS_PROTOCOL + protocol: HTTPS_PROTOCOL, }; beforeEach(() => { @@ -55,7 +57,9 @@ describe("Proxy tests", () => { expect(httpEnvVarSpy).not.toHaveBeenCalled(); expect(httpsEnvVarSpy).not.toHaveBeenCalled(); checkUrlSpy.mockReturnValueOnce(passedUrl); - expect(JSON.stringify(ProxySettings["getProxySettings"](session))).toEqual(JSON.stringify(expected)); + expect( + JSON.stringify(ProxySettings["getProxySettings"](session)) + ).toEqual(JSON.stringify(expected)); noProxySpy.mockClear(); checkUrlSpy.mockClear(); }); @@ -67,34 +71,89 @@ describe("Proxy tests", () => { expect(httpEnvVarSpy).not.toHaveBeenCalled(); expect(httpsEnvVarSpy).not.toHaveBeenCalled(); checkUrlSpy.mockReturnValueOnce(passedUrl); - expect(JSON.stringify(ProxySettings["getProxySettings"](session))).toEqual(JSON.stringify(expected)); + expect( + JSON.stringify(ProxySettings["getProxySettings"](session)) + ).toEqual(JSON.stringify(expected)); noProxySpy.mockClear(); checkUrlSpy.mockClear(); }); }); describe("getProxyAgent", () => { + const headers = { + "Proxy-Authorization": "Basic ==ThisIsATest123", + }; + beforeEach(() => { jest.clearAllMocks(); + jest.restoreAllMocks(); + jest.resetModules(); + jest.resetAllMocks(); getProxySettingsSpy = jest.spyOn(privateProxy, "getProxySettings"); + getProxyAuthSettingSpy = jest.spyOn( + privateProxy, + "getProxyAuthHeader" + ); }); it("Should retrieve the HTTP proxy agent", () => { - const expected = new HttpProxyAgent(httpUrl); + const expected = new HttpProxyAgent(httpUrl, { headers }); getProxySettingsSpy.mockReturnValue({ proxyUrl: httpUrl, - protocol: HTTP_PROTOCOL + protocol: HTTP_PROTOCOL, }); - expect(JSON.stringify(ProxySettings.getProxyAgent(session))).toEqual(JSON.stringify(expected)); + getProxyAuthSettingSpy.mockReturnValue(headers); + expect( + JSON.stringify(ProxySettings.getProxyAgent(session)) + ).toEqual(JSON.stringify(expected)); }); it("Should retrieve the HTTPS proxy agent", () => { - const expected = new HttpsProxyAgent(httpsUrl, { rejectUnauthorized: false }); + const expected = new HttpsProxyAgent(httpsUrl, { + rejectUnauthorized: false, + }); getProxySettingsSpy.mockReturnValue({ proxyUrl: httpsUrl, - protocol: HTTPS_PROTOCOL + protocol: HTTPS_PROTOCOL, }); - expect(JSON.stringify(ProxySettings.getProxyAgent(session))).toEqual(JSON.stringify(expected)); + expect( + JSON.stringify(ProxySettings.getProxyAgent(session)) + ).toEqual(JSON.stringify(expected)); + }); + + it("Should return undefined when a protocol is not defined in the session", () => { + const noProtocolSession = { ...session }; + noProtocolSession.protocol = undefined; + expect(ProxySettings.getProxyAgent(session)).toEqual(undefined); + }); + }); + + describe("getProxyAuthHeader", () => { + beforeEach(() => { + jest.clearAllMocks(); + jest.restoreAllMocks(); + jest.resetModules(); + jest.resetAllMocks(); + }); + + it("Should retrieve the auth header from the proxy settings", () => { + const proxyAuthSetting = "Basic ==ThisIsATest123"; + expect( + ProxySettings["getProxyAuthHeader"]({ + authSetting: proxyAuthSetting, + proxyUrl: new URL("https://www.google.com/"), + protocol: HTTPS_PROTOCOL, + }) + ).toEqual({ "Proxy-Authorization": proxyAuthSetting }); + }); + + it("Should return undefined if the proxy auth setting is not in the proxy settings", () => { + expect( + ProxySettings["getProxyAuthHeader"]({ + proxyUrl: new URL("https://www.google.com/"), + protocol: HTTPS_PROTOCOL, + }) + ).toEqual(undefined); }); }); @@ -107,7 +166,7 @@ describe("Proxy tests", () => { it("Should retrieve the system proxy URL", () => { getProxySettingsSpy.mockReturnValue({ proxyUrl: httpsUrl, - protocol: HTTPS_PROTOCOL + protocol: HTTPS_PROTOCOL, }); expect(ProxySettings.getSystemProxyUrl(session)).toEqual(httpsUrl); }); @@ -116,16 +175,36 @@ describe("Proxy tests", () => { describe("getProxySettings", () => { beforeEach(() => { jest.clearAllMocks(); + jest.restoreAllMocks(); + jest.resetModules(); + jest.resetAllMocks(); checkUrlSpy = jest.spyOn(privateProxy, "checkUrl"); + matchesNoProxySettingsSpy = jest.spyOn( + privateProxy, + "matchesNoProxySettings" + ); }); it("Should return proxy settings from session", () => { const expected = { proxyUrl: httpsUrl, - protocol: HTTPS_PROTOCOL + protocol: HTTPS_PROTOCOL, + authSetting: "Basic ==ThisIsATest123", }; checkUrlSpy.mockReturnValue(httpsUrl); - expect(ProxySettings["getProxySettings"](session)).toEqual(expected); + session.proxy = { + proxy_authorization: "Basic ==ThisIsATest123", + }; + expect(ProxySettings["getProxySettings"](session)).toEqual( + expected + ); + }); + + it("Should return undefined proxy url matchesNoProxySettings", () => { + matchesNoProxySettingsSpy.mockReturnValue(true); + expect(ProxySettings["getProxySettings"](session)).toEqual( + undefined + ); }); }); @@ -143,28 +222,46 @@ describe("Proxy tests", () => { }); describe("matchesNoProxySettings", () => { - it("Should match session hostname with no_proxy", () => { + beforeEach(() => { + jest.clearAllMocks(); + jest.restoreAllMocks(); + jest.resetModules(); + jest.resetAllMocks(); + }); + + it("Should match session hostname with no_proxy", () => { const expected = true; process.env["NO_PROXY"] = noProxyList; - expect(ProxySettings["matchesNoProxySettings"](session)).toEqual(expected); + expect(ProxySettings["matchesNoProxySettings"](session)).toEqual( + expected + ); process.env["NO_PROXY"] = undefined; }); it("Should return true for match with no_proxy passed with session proxy", () => { session.proxy = { http_proxy: passedUrl, no_proxy: ["fake.com"] }; session.protocol = HTTP_PROTOCOL; - expect(ProxySettings["matchesNoProxySettings"](session)).toEqual(true); + expect(ProxySettings["matchesNoProxySettings"](session)).toEqual( + true + ); }); - it("Should not match session hostname with no_proxy", () => { + it("Should not match session hostname with no_proxy", () => { const expected = false; process.env["NO_PROXY"] = noProxyList; session.hostname = "microsoft.com"; - expect(ProxySettings["matchesNoProxySettings"](session)).toEqual(expected); + expect(ProxySettings["matchesNoProxySettings"](session)).toEqual( + expected + ); process.env["NO_PROXY"] = undefined; }); it("Should return false for match with no_proxy passed with session proxy", () => { - session.proxy = { http_proxy: passedUrl, no_proxy: ["false.com", "blah.com"] }; + session.proxy = { + http_proxy: passedUrl, + no_proxy: ["false.com", "blah.com"], + }; session.protocol = HTTP_PROTOCOL; - expect(ProxySettings["matchesNoProxySettings"](session)).toEqual(false); + expect(ProxySettings["matchesNoProxySettings"](session)).toEqual( + false + ); }); }); }); diff --git a/packages/imperative/src/rest/src/client/ProxySettings.ts b/packages/imperative/src/rest/src/client/ProxySettings.ts index 6132e9e20b..c9cc78aaab 100644 --- a/packages/imperative/src/rest/src/client/ProxySettings.ts +++ b/packages/imperative/src/rest/src/client/ProxySettings.ts @@ -1,22 +1,26 @@ /* -* This program and the accompanying materials are made available under the terms of the -* Eclipse Public License v2.0 which accompanies this distribution, and is available at -* https://www.eclipse.org/legal/epl-v20.html -* -* SPDX-License-Identifier: EPL-2.0 -* -* Copyright Contributors to the Zowe Project. -* -*/ + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + * + */ -import { env } from 'process'; -import { URL } from 'url'; -import { Agent } from 'https'; -import { HttpProxyAgent } from 'http-proxy-agent'; -import { HttpsProxyAgent } from 'https-proxy-agent'; +import { env } from "process"; +import { URL } from "url"; +import { Agent } from "https"; +import { HttpProxyAgent } from "http-proxy-agent"; +import { HttpsProxyAgent } from "https-proxy-agent"; -import { HTTP_PROTOCOL_CHOICES, HTTP_PROTOCOL, HTTPS_PROTOCOL } from '../session/SessConstants'; -import { ISession } from '../session/doc/ISession'; +import { + HTTP_PROTOCOL_CHOICES, + HTTP_PROTOCOL, + HTTPS_PROTOCOL, +} from "../session/SessConstants"; +import { ISession } from "../session/doc/ISession"; /** * Utility class to provide an http agent to REST APIs that is configured for @@ -33,7 +37,6 @@ import { ISession } from '../session/doc/ISession'; * to match with the hostname of the Zowe profile. */ export class ProxySettings { - /** * Retrieve an appropriate http.agent instance if proxy environment variables can be found. * @static @@ -47,14 +50,18 @@ export class ProxySettings { const proxySetting = this.getProxySettings(session); const proxyOptions = {} as ProxyOptions; const authHeader = ProxySettings.getProxyAuthHeader(proxySetting); - if(authHeader) { + if (authHeader) { proxyOptions.headers = authHeader; } - if (proxySetting?.protocol === HTTP_PROTOCOL) { + if (!proxySetting?.protocol) { + return; + } + if (proxySetting.protocol === HTTP_PROTOCOL) { return new HttpProxyAgent(proxySetting.proxyUrl, proxyOptions); } - if (proxySetting?.protocol === HTTPS_PROTOCOL) { - proxyOptions.rejectUnauthorized = session.rejectUnauthorized ?? true; + if (proxySetting.protocol === HTTPS_PROTOCOL) { + proxyOptions.rejectUnauthorized = + session.rejectUnauthorized ?? true; return new HttpsProxyAgent(proxySetting.proxyUrl, proxyOptions); } } @@ -83,7 +90,8 @@ export class ProxySettings { * @memberof ProxySettings */ public static matchesNoProxySettings(session: ISession): boolean { - const noProxyValues = session.proxy?.no_proxy ?? this.getNoProxyEnvVariables(); + const noProxyValues = + session.proxy?.no_proxy ?? this.getNoProxyEnvVariables(); if (!noProxyValues) { return false; } @@ -93,10 +101,12 @@ export class ProxySettings { return false; } - private static getProxyAuthHeader(proxySetting: ProxySetting): { [key: string]: string } | undefined { - return proxySetting.authSetting - ? { 'Proxy-Authorization': proxySetting.authSetting } - : undefined; + private static getProxyAuthHeader( + proxySetting: ProxySetting + ): { [key: string]: string } | undefined { + return proxySetting?.authSetting + ? { "Proxy-Authorization": proxySetting.authSetting } + : undefined; } /** @@ -107,26 +117,29 @@ export class ProxySettings { * @returns instance of private `ProxySetting` or `undefined` * @memberof ProxySettings */ - private static getProxySettings(session: ISession): ProxySetting | undefined { + private static getProxySettings( + session: ISession + ): ProxySetting | undefined { if (this.matchesNoProxySettings(session)) { return; } const protocol = session.protocol ?? HTTPS_PROTOCOL; let envVariable: string | undefined; if (protocol === HTTP_PROTOCOL) { - envVariable = session.proxy?.http_proxy ?? this.getHttpEnvVariables(); - } - else if (protocol === HTTPS_PROTOCOL) { - envVariable = session.proxy?.https_proxy ?? this.getHttpsEnvVariables(); + envVariable = + session.proxy?.http_proxy ?? this.getHttpEnvVariables(); + } else if (protocol === HTTPS_PROTOCOL) { + envVariable = + session.proxy?.https_proxy ?? this.getHttpsEnvVariables(); } const proxyUrl = this.checkUrl(envVariable); const authSetting = session.proxy?.proxy_authorization; if (authSetting) { - return {proxyUrl, protocol, authSetting}; + return { proxyUrl, protocol, authSetting }; } if (proxyUrl) { - return {proxyUrl, protocol}; + return { proxyUrl, protocol }; } } @@ -165,7 +178,9 @@ export class ProxySettings { if (!noProxyValue) { return; } - return noProxyValue.split(',').map(entry => entry.trim().toLocaleLowerCase()); + return noProxyValue + .split(",") + .map((entry) => entry.trim().toLocaleLowerCase()); } /** @@ -189,12 +204,12 @@ export class ProxySettings { * Internal interface to group proxy settings */ interface ProxySetting { - proxyUrl: URL, - protocol: HTTP_PROTOCOL_CHOICES, - authSetting?: string + proxyUrl: URL; + protocol: HTTP_PROTOCOL_CHOICES; + authSetting?: string; } interface ProxyOptions { - headers?: { [key: string]: string }, - rejectUnauthorized?: boolean + headers?: { [key: string]: string }; + rejectUnauthorized?: boolean; } From d90f8c05aae04fe06407b2089c1de206721d937b Mon Sep 17 00:00:00 2001 From: Rudy Flores <68666202+rudyflores@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:19:12 -0500 Subject: [PATCH 6/8] Update code formatting Signed-off-by: Rudy Flores <68666202+rudyflores@users.noreply.github.com> --- .../client/ProxySettings.unit.test.ts | 18 +++++++++--------- .../src/rest/src/client/ProxySettings.ts | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/imperative/src/rest/__tests__/client/ProxySettings.unit.test.ts b/packages/imperative/src/rest/__tests__/client/ProxySettings.unit.test.ts index 9aeb24ca7b..f6ff5aac4c 100644 --- a/packages/imperative/src/rest/__tests__/client/ProxySettings.unit.test.ts +++ b/packages/imperative/src/rest/__tests__/client/ProxySettings.unit.test.ts @@ -1,13 +1,13 @@ /* - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-v20.html - * - * SPDX-License-Identifier: EPL-2.0 - * - * Copyright Contributors to the Zowe Project. - * - */ +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ import * as process from "process"; diff --git a/packages/imperative/src/rest/src/client/ProxySettings.ts b/packages/imperative/src/rest/src/client/ProxySettings.ts index c9cc78aaab..56b8438d3f 100644 --- a/packages/imperative/src/rest/src/client/ProxySettings.ts +++ b/packages/imperative/src/rest/src/client/ProxySettings.ts @@ -1,13 +1,13 @@ /* - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-v20.html - * - * SPDX-License-Identifier: EPL-2.0 - * - * Copyright Contributors to the Zowe Project. - * - */ +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ import { env } from "process"; import { URL } from "url"; From b7a9da3bc941f028b854b71d276ed09932597433 Mon Sep 17 00:00:00 2001 From: Rudy Flores <68666202+rudyflores@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:25:26 -0500 Subject: [PATCH 7/8] Update CHANGELOG.md Signed-off-by: Rudy Flores <68666202+rudyflores@users.noreply.github.com> --- packages/imperative/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/imperative/CHANGELOG.md b/packages/imperative/CHANGELOG.md index 52915b7f41..e2a4a0c96f 100644 --- a/packages/imperative/CHANGELOG.md +++ b/packages/imperative/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to the Imperative package will be documented in this file. - BugFix: Modified 8.8.2 bugfix to correct web help alias. [#2361](https://github.com/zowe/zowe-cli/pull/2361) - BugFix: Resolved issue where special characters could be corrupted when downloading a large file. [#2366](https://github.com/zowe/zowe-cli/pull/2366) -- BugFix: Modified location of Proxy-Authorization header to be located in the agent instead of the request. +- BugFix: Modified location of Proxy-Authorization header to be located in the agent instead of the request. [#2389](https://github.com/zowe/zowe-cli/issues/2389) ## `8.8.2` From c0c27c135179fe979a3efa48447bdf50d946231a Mon Sep 17 00:00:00 2001 From: Rudy Flores <68666202+rudyflores@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:34:37 -0500 Subject: [PATCH 8/8] Update CHANGELOG.md Signed-off-by: Rudy Flores <68666202+rudyflores@users.noreply.github.com> --- packages/imperative/CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/imperative/CHANGELOG.md b/packages/imperative/CHANGELOG.md index e2a4a0c96f..2e6f0212a5 100644 --- a/packages/imperative/CHANGELOG.md +++ b/packages/imperative/CHANGELOG.md @@ -2,11 +2,14 @@ All notable changes to the Imperative package will be documented in this file. +## Recent Changes + +- BugFix: Modified location of Proxy-Authorization header to be located in the agent instead of the request. [#2389](https://github.com/zowe/zowe-cli/issues/2389) + ## `8.8.3` - BugFix: Modified 8.8.2 bugfix to correct web help alias. [#2361](https://github.com/zowe/zowe-cli/pull/2361) - BugFix: Resolved issue where special characters could be corrupted when downloading a large file. [#2366](https://github.com/zowe/zowe-cli/pull/2366) -- BugFix: Modified location of Proxy-Authorization header to be located in the agent instead of the request. [#2389](https://github.com/zowe/zowe-cli/issues/2389) ## `8.8.2`