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

Allow password-less proxySettings #453

Merged
merged 2 commits into from
Jun 15, 2021
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
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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))

Expand Down
2 changes: 2 additions & 0 deletions lib/proxyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() || "";
Expand Down
2 changes: 1 addition & 1 deletion lib/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const Constants = {
* @const
* @type {string}
*/
msRestVersion: "2.5.1",
msRestVersion: "2.5.2",

/**
* Specifies HTTP.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 32 additions & 0 deletions test/proxyAgent.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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", () => {
Expand Down