From 4712e6369e8fe40cd9ec8c4b3a73fce8345f5634 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Wed, 21 Aug 2024 07:30:03 -0400 Subject: [PATCH 1/2] Rename Proxy class to ProxySettings Signed-off-by: Timothy Johnson --- packages/imperative/CHANGELOG.md | 4 ++++ ...unit.test.ts => ProxySettings.unit.test.ts} | 18 +++++++++--------- packages/imperative/src/rest/index.ts | 2 +- .../src/rest/src/client/AbstractRestClient.ts | 8 ++++---- .../src/client/{Proxy.ts => ProxySettings.ts} | 16 ++++++++-------- 5 files changed, 26 insertions(+), 22 deletions(-) rename packages/imperative/src/rest/__tests__/client/{Proxy.unit.test.ts => ProxySettings.unit.test.ts} (82%) rename packages/imperative/src/rest/src/client/{Proxy.ts => ProxySettings.ts} (96%) diff --git a/packages/imperative/CHANGELOG.md b/packages/imperative/CHANGELOG.md index 4d862a2abc..81f7b0b02f 100644 --- a/packages/imperative/CHANGELOG.md +++ b/packages/imperative/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the Imperative package will be documented in this file. +## Recent Changes + +- LTS Breaking: Renamed `Proxy` class to `ProxySettings` to avoid name conflict with JS built-in `Proxy` object. [#2230](https://github.com/zowe/zowe-cli/issues/2230) + ## `8.0.0-next.202408191401` - Update: See `5.26.3` and `5.27.0` for details diff --git a/packages/imperative/src/rest/__tests__/client/Proxy.unit.test.ts b/packages/imperative/src/rest/__tests__/client/ProxySettings.unit.test.ts similarity index 82% rename from packages/imperative/src/rest/__tests__/client/Proxy.unit.test.ts rename to packages/imperative/src/rest/__tests__/client/ProxySettings.unit.test.ts index 1e0bff2a57..68d5291c4b 100644 --- a/packages/imperative/src/rest/__tests__/client/Proxy.unit.test.ts +++ b/packages/imperative/src/rest/__tests__/client/ProxySettings.unit.test.ts @@ -11,7 +11,7 @@ import * as process from "process"; -import { Proxy } from "../../src/client/Proxy"; +import { ProxySettings } from "../../src/client/ProxySettings"; import { HTTPS_PROTOCOL, HTTP_PROTOCOL } from "../../src/session/SessConstants"; import { HttpsProxyAgent } from "https-proxy-agent"; @@ -25,7 +25,7 @@ describe("Proxy tests", () => { port: 443, rejectUnauthorized: false } as ISession; - const privateProxy = Proxy as any; + const privateProxy = ProxySettings as any; const httpUrl = "http://www.zowe.com"; const httpsUrl = "https://www.zowe.com"; const noProxyList = "www.zowe.com, fake.com,ibm.com,broadcom.com "; @@ -44,7 +44,7 @@ describe("Proxy tests", () => { proxyUrl: httpUrl, protocol: HTTP_PROTOCOL }); - expect(JSON.stringify(Proxy.getProxyAgent(session))).toEqual(JSON.stringify(expected)); + expect(JSON.stringify(ProxySettings.getProxyAgent(session))).toEqual(JSON.stringify(expected)); }); it("Should retrieve the HTTPS proxy agent", () => { @@ -53,7 +53,7 @@ describe("Proxy tests", () => { proxyUrl: httpsUrl, protocol: HTTPS_PROTOCOL }); - expect(JSON.stringify(Proxy.getProxyAgent(session))).toEqual(JSON.stringify(expected)); + expect(JSON.stringify(ProxySettings.getProxyAgent(session))).toEqual(JSON.stringify(expected)); }); }); @@ -68,7 +68,7 @@ describe("Proxy tests", () => { proxyUrl: httpsUrl, protocol: HTTPS_PROTOCOL }); - expect(Proxy.getSystemProxyUrl(session)).toEqual(httpsUrl); + expect(ProxySettings.getSystemProxyUrl(session)).toEqual(httpsUrl); }); }); @@ -84,7 +84,7 @@ describe("Proxy tests", () => { protocol: HTTPS_PROTOCOL }; checkUrlSpy.mockReturnValue(httpsUrl); - expect(Proxy["getProxySettings"](session)).toEqual(expected); + expect(ProxySettings["getProxySettings"](session)).toEqual(expected); }); }); @@ -96,7 +96,7 @@ describe("Proxy tests", () => { it("Should return the HTTP environment variables if they exist", () => { const expected = httpUrl; process.env["HTTP_PROXY"] = expected; - expect(Proxy["getHttpEnvVariables"]()).toEqual(expected); + expect(ProxySettings["getHttpEnvVariables"]()).toEqual(expected); process.env["HTTP_PROXY"] = undefined; }); }); @@ -105,7 +105,7 @@ describe("Proxy tests", () => { it("Should match session hostname with no_proxy", () => { const expected = true; process.env["NO_PROXY"] = noProxyList; - expect(Proxy["matchesNoProxySettings"](session)).toEqual(expected); + expect(ProxySettings["matchesNoProxySettings"](session)).toEqual(expected); process.env["NO_PROXY"] = undefined; }); @@ -113,7 +113,7 @@ describe("Proxy tests", () => { const expected = false; process.env["NO_PROXY"] = noProxyList; session.hostname = "microsoft.com"; - expect(Proxy["matchesNoProxySettings"](session)).toEqual(expected); + expect(ProxySettings["matchesNoProxySettings"](session)).toEqual(expected); process.env["NO_PROXY"] = undefined; }); }); diff --git a/packages/imperative/src/rest/index.ts b/packages/imperative/src/rest/index.ts index 2b7c2ae485..72ab85c224 100644 --- a/packages/imperative/src/rest/index.ts +++ b/packages/imperative/src/rest/index.ts @@ -17,7 +17,7 @@ export * from "./src/client/doc/IRestClientError"; export * from "./src/client/doc/IRestClientResponse"; export * from "./src/client/doc/IRestOptions"; export * from "./src/client/Headers"; -export * from "./src/client/Proxy"; +export * from "./src/client/ProxySettings"; export * from "./src/client/AbstractRestClient"; // export * from "./src/client/CompressionUtils"; export * from "./src/client/RestClient"; diff --git a/packages/imperative/src/rest/src/client/AbstractRestClient.ts b/packages/imperative/src/rest/src/client/AbstractRestClient.ts index bb9280be54..46b6eec4b3 100644 --- a/packages/imperative/src/rest/src/client/AbstractRestClient.ts +++ b/packages/imperative/src/rest/src/client/AbstractRestClient.ts @@ -33,7 +33,7 @@ import { TextUtils } from "../../../utilities"; import { IRestOptions } from "./doc/IRestOptions"; import * as SessConstants from "../session/SessConstants"; import { CompressionUtils } from "./CompressionUtils"; -import { Proxy } from "./Proxy"; +import { ProxySettings } from "./ProxySettings"; export type RestClientResolve = (data: string) => void; @@ -461,13 +461,13 @@ export abstract class AbstractRestClient { // NOTE(Kelosky): This cannot be set for http requests // options.agent = new https.Agent({secureProtocol: this.session.ISession.secureProtocol}); - const proxyUrl = Proxy.getSystemProxyUrl(this.session.ISession); + const proxyUrl = ProxySettings.getSystemProxyUrl(this.session.ISession); if (proxyUrl) { - if (Proxy.matchesNoProxySettings(this.session.ISession)) { + if (ProxySettings.matchesNoProxySettings(this.session.ISession)) { 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}`); - options.agent = Proxy.getProxyAgent(this.session.ISession); + options.agent = ProxySettings.getProxyAgent(this.session.ISession); } } diff --git a/packages/imperative/src/rest/src/client/Proxy.ts b/packages/imperative/src/rest/src/client/ProxySettings.ts similarity index 96% rename from packages/imperative/src/rest/src/client/Proxy.ts rename to packages/imperative/src/rest/src/client/ProxySettings.ts index 67ac9d685a..f535bc00d4 100644 --- a/packages/imperative/src/rest/src/client/Proxy.ts +++ b/packages/imperative/src/rest/src/client/ProxySettings.ts @@ -32,7 +32,7 @@ import { ISession } from '../session/doc/ISession'; * variables NO_PROXY or no_proxy. These work with a simple comma separated list of hostnames that need * to match with the hostname of the Zowe profile. */ -export class Proxy { +export class ProxySettings { /** * Retrieve an appropriate http.agent instance if proxy environment variables can be found. @@ -41,7 +41,7 @@ export class Proxy { * Uses the session's `rejectUnauthorized` also for the proxy connection. * @returns an instance of an appropriate subclass of node's https.agent if proxy * settings were found. Returns `undefined` if no proxy settings are found. - * @memberof Proxy + * @memberof ProxySettings */ public static getProxyAgent(session: ISession): Agent | undefined { const proxySetting = this.getProxySettings(session); @@ -60,7 +60,7 @@ export class Proxy { * @static * @param session Zowe `ISession` containing the hostname for the http request. * @returns `URL` to proxy server - * @memberof Proxy + * @memberof ProxySettings */ public static getSystemProxyUrl(session: ISession): URL | undefined { return this.getProxySettings(session)?.proxyUrl; @@ -75,7 +75,7 @@ export class Proxy { * @param session Zowe `ISession` containing the hostname for the http request. * @returns `true` if the Zowe session host matches an entry in the comma separated * list of hostnames in the environment variable. `false` otherwise. - * @memberof Proxy + * @memberof ProxySettings */ public static matchesNoProxySettings(session: ISession): boolean { const noProxyValues = this.getNoProxyEnvVariables(); @@ -94,7 +94,7 @@ export class Proxy { * @static * @param session Zowe `ISession` containing the hostname for the http request. * @returns instance of private `ProxySetting` or `undefined` - * @memberof Proxy + * @memberof ProxySettings */ private static getProxySettings(session: ISession): ProxySetting | undefined { if (this.matchesNoProxySettings(session)) { @@ -119,7 +119,7 @@ export class Proxy { * @private * @static * @returns `string` if valid variable is found or undefined. - * @memberof Proxy + * @memberof ProxySettings */ private static getHttpEnvVariables(): string | undefined { return env.HTTP_PROXY ?? env.http_proxy; @@ -130,7 +130,7 @@ export class Proxy { * @private * @static * @returns `string` if valid variable is found or undefined. - * @memberof Proxy + * @memberof ProxySettings */ private static getHttpsEnvVariables(): string | undefined { return env.HTTPS_PROXY ?? env.https_proxy ?? this.getHttpEnvVariables(); @@ -142,7 +142,7 @@ export class Proxy { * @static * @returns `string[]` of all hostnames found in the comma separated list * in lowercase without white spaces. - * @memberof Proxy + * @memberof ProxySettings */ private static getNoProxyEnvVariables(): string[] | undefined { const noProxyValue = env.NO_PROXY ?? env.no_proxy; From 12d117e6ab9df2ef028eaf4256e3cc1762ad8f04 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Wed, 21 Aug 2024 08:09:34 -0400 Subject: [PATCH 2/2] Fix import in AbstractRestClient unit test Signed-off-by: Timothy Johnson --- .../rest/__tests__/client/AbstractRestClient.unit.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 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 61045414d5..d77a854961 100644 --- a/packages/imperative/src/rest/__tests__/client/AbstractRestClient.unit.test.ts +++ b/packages/imperative/src/rest/__tests__/client/AbstractRestClient.unit.test.ts @@ -31,7 +31,7 @@ import { AbstractRestClient } from "../../src/client/AbstractRestClient"; import * as os from "os"; import { join } from "path"; import { IO } from "../../../io"; -import { Proxy } from "../../src/client/Proxy"; +import { ProxySettings } from "../../src/client/ProxySettings"; import { HttpsProxyAgent } from "https-proxy-agent"; /** @@ -1436,8 +1436,8 @@ describe("AbstractRestClient tests", () => { beforeEach(() => { jest.clearAllMocks(); - getSystemProxyUrlSpy = jest.spyOn(Proxy, "getSystemProxyUrl"); - getProxyAgentSpy = jest.spyOn(Proxy, "getProxyAgent"); + getSystemProxyUrlSpy = jest.spyOn(ProxySettings, "getSystemProxyUrl"); + getProxyAgentSpy = jest.spyOn(ProxySettings, "getProxyAgent"); setCertPemAuthSpy = jest.spyOn(privateRestClient, "setCertPemAuth"); });