From ce25202b91bd38df9c3eb54e3d3853a7c2c9a1f9 Mon Sep 17 00:00:00 2001 From: Jeremy Meng Date: Tue, 15 Jun 2021 00:30:17 +0000 Subject: [PATCH 1/2] Allow password-less proxySettings It turns out that in some enterprise customer the proxy auth settings include a username, but not a password: microsoft/AzureStorageExplorer#4430 This change allows password-less auth settings to be passed to the underlying agent. It's unclear whether it's a real scenario when a proxy auth has a password, but not username so this PR doesn't consider this scenario. --- Changelog.md | 4 ++++ lib/proxyAgent.ts | 2 ++ test/proxyAgent.node.ts | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/Changelog.md b/Changelog.md index f746f14..4f36f8b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,4 +1,8 @@ # Changelog + +## 2.5.2 - (2021-06-15) +- Fixed an issue where `proxySettings` does not work when there is username but no password (PR [453](https://github.com/Azure/ms-rest-js/pull/453)) + ## 2.5.1 - (2021-06-07) - [BugFix] Array flattening in deserializer loses previously de-serialized attributes (PR [#451](https://github.com/Azure/ms-rest-js/pull/451)) diff --git a/lib/proxyAgent.ts b/lib/proxyAgent.ts index 3ee29c6..93dd369 100644 --- a/lib/proxyAgent.ts +++ b/lib/proxyAgent.ts @@ -25,6 +25,8 @@ export function createProxyAgent( if (proxySettings.username && proxySettings.password) { tunnelOptions.proxy!.proxyAuth = `${proxySettings.username}:${proxySettings.password}`; + } else if (proxySettings.username) { + tunnelOptions.proxy!.proxyAuth = `${proxySettings.username}`; } const requestScheme = URLBuilder.parse(requestUrl).getScheme() || ""; diff --git a/test/proxyAgent.node.ts b/test/proxyAgent.node.ts index 3622eec..969d403 100644 --- a/test/proxyAgent.node.ts +++ b/test/proxyAgent.node.ts @@ -8,6 +8,7 @@ import https from "https"; import { HttpHeaders } from "../lib/msRest"; import { createProxyAgent, createTunnel } from "../lib/proxyAgent"; +import { ProxySettings } from "../lib/serviceClient"; describe("proxyAgent", () => { describe("createProxyAgent", () => { @@ -62,6 +63,37 @@ describe("proxyAgent", () => { agent.proxyOptions.headers!.should.contain({ "user-agent": "Node.js" }); done(); }); + + it("should set agent proxyAuth correctly", function (done) { + const proxySettings: ProxySettings = { + host: "http://proxy.microsoft.com", + port: 8080, + username: "username", + password: "pass123", + }; + + const proxyAgent = createProxyAgent("http://example.com", proxySettings); + + const agent = proxyAgent.agent as HttpsAgent; + should().exist(agent.options.proxy.proxyAuth); + agent.options.proxy.proxyAuth!.should.equal("username:pass123"); + done(); + }); + + it("should set agent proxyAuth correctly when password is not specified", function (done) { + const proxySettings: ProxySettings = { + host: "http://proxy.microsoft.com", + port: 8080, + username: "username", + }; + + const proxyAgent = createProxyAgent("http://example.com", proxySettings); + + const agent = proxyAgent.agent as HttpsAgent; + should().exist(agent.options.proxy.proxyAuth); + agent.options.proxy.proxyAuth!.should.equal("username"); + done(); + }); }); describe("createTunnel", () => { From 83c3a0b6198c4d5edb569eb15b44e9cfbc377f70 Mon Sep 17 00:00:00 2001 From: Jeremy Meng Date: Tue, 15 Jun 2021 17:21:53 +0000 Subject: [PATCH 2/2] Update version number to 2.5.2 --- lib/util/constants.ts | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/util/constants.ts b/lib/util/constants.ts index 15c91df..16603eb 100644 --- a/lib/util/constants.ts +++ b/lib/util/constants.ts @@ -7,7 +7,7 @@ export const Constants = { * @const * @type {string} */ - msRestVersion: "2.5.1", + msRestVersion: "2.5.2", /** * Specifies HTTP. diff --git a/package.json b/package.json index ad866ec..d5650d9 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "email": "azsdkteam@microsoft.com", "url": "https://github.com/Azure/ms-rest-js" }, - "version": "2.5.1", + "version": "2.5.2", "description": "Isomorphic client Runtime for Typescript/node.js/browser javascript client libraries generated using AutoRest", "tags": [ "isomorphic",