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

Revert Fix processing of proxybypass variables from environment #286 #292

Merged
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
2 changes: 0 additions & 2 deletions lib/Constants.ts

This file was deleted.

19 changes: 10 additions & 9 deletions lib/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as url from 'url';
import * as path from 'path';
import zlib = require('zlib');
import { IRequestQueryParams, IHttpClientResponse } from './Interfaces';
import { searchRegExpToReplaceSpecialChars } from './Constants';

/**
* creates an url from a request url and optional base url (http://server:8080)
Expand Down Expand Up @@ -108,15 +107,17 @@ export async function decompressGzippedContent(buffer: Buffer, charset?: string)
* @return {RegExp}
*/
export function buildProxyBypassRegexFromEnv(bypass : string) : RegExp {
// check if expression starts with asterisk and replace it with .*
if (bypass && bypass.startsWith("*")) {
bypass = bypass.replace("*", ".*");
try {
// We need to keep this around for back-compat purposes
return new RegExp(bypass, 'i')
}
catch(err) {
if (err instanceof SyntaxError && (bypass || "").startsWith("*")) {
let wildcardEscaped = bypass.replace('*', '(.*)');
return new RegExp(wildcardEscaped, 'i');
}
throw err;
}

// replace all . symbols in string by \. because point is a special character
const safeRegex = (bypass || "").replace(searchRegExpToReplaceSpecialChars, '\\$1');

return new RegExp(safeRegex, 'i');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typed-rest-client",
"version": "1.8.5",
"version": "1.8.4",
"description": "Node Rest and Http Clients for use with TypeScript",
"main": "./RestClient.js",
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 2 additions & 24 deletions test/units/utiltests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,6 @@ describe('Util Tests', function () {
assert.equal(bypassed, true);
});

it('not bypasses if domain pattern starts with .', () => {
let regExp = util.buildProxyBypassRegexFromEnv('.intranet');
assert(regExp, 'regExp should not be null');
let parsedUrl = url.parse("https://keyvault.vault.azure.net/secrets/test-secret1-intranet");
let bypassed = regExp.test(parsedUrl.href);
assert.equal(bypassed, false);
});

it('bypasses if domain pattern starts with .', () => {
let regExp = util.buildProxyBypassRegexFromEnv('.net');
assert(regExp, 'regExp should not be null');
let parsedUrl = url.parse("https://keyvault.vault.azure.net/secrets/test-secret1-intranet");
let bypassed = regExp.test(parsedUrl.href);
assert.equal(bypassed, true);
});

it('bypasses if domain pattern starts with . and contains complex domain', () => {
let regExp = util.buildProxyBypassRegexFromEnv('.azure.net');
assert(regExp, 'regExp should not be null');
let parsedUrl = url.parse("https://keyvault.vault.azure.net/secrets/test-secret1-intranet");
let bypassed = regExp.test(parsedUrl.href);
assert.equal(bypassed, true);
});
});
});

});