Skip to content

Commit

Permalink
Tested and working version
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodecleyre committed Dec 17, 2023
1 parent 11bc503 commit 0216284
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export class Auth {
piiLoggingEnabled: false,
logLevel: debug ? LogLevel.Verbose : LogLevel.Error
},
proxyUrl: process.env.http_proxy || process.env.https_proxy
proxyUrl: process.env.HTTP_PROXY || process.env.HTTTPS_PROXY
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/appInsights.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ describe('appInsights', () => {

it('sets proxyHttpUrl in the telemetry', async () => {
const proxyHttpUrl = 'http://username:password@proxy.contoso.com:8080';
sinon.stub(process, 'env').value({ 'http_proxy': proxyHttpUrl });
sinon.stub(process, 'env').value({ 'HTTP_PROXY': proxyHttpUrl });

const i: any = await import(`./appInsights.js#${Math.random()}`);
assert(i.default.config.proxyHttpUrl === proxyHttpUrl);
});

it('sets proxyHttpsUrl in the telemetry', async () => {
const proxyHttpsUrl = 'https://username:password@proxy.contoso.com:8080';
sinon.stub(process, 'env').value({ 'https_proxy': proxyHttpsUrl });
sinon.stub(process, 'env').value({ 'HTTPS_PROXY': proxyHttpsUrl });

const i: any = await import(`./appInsights.js#${Math.random()}`);
assert(i.default.config.proxyHttpsUrl === proxyHttpsUrl);
Expand Down
4 changes: 2 additions & 2 deletions src/appInsights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ appInsightsClient.commonProperties = {
ci: Boolean(process.env.CI).toString()
};

appInsightsClient.config.proxyHttpUrl = process.env.http_proxy ? process.env.http_proxy : '';
appInsightsClient.config.proxyHttpsUrl = process.env.https_proxy ? process.env.https_proxy : '';
appInsightsClient.config.proxyHttpUrl = process.env.HTTP_PROXY ?? '';
appInsightsClient.config.proxyHttpsUrl = process.env.HTTPS_PROXY ?? '';

appInsightsClient.context.tags['ai.cloud.roleInstance'] = crypto.createHash('sha256').update(appInsightsClient.context.tags['ai.cloud.roleInstance']).digest('hex');
delete appInsightsClient.context.tags['ai.cloud.role'];
Expand Down
8 changes: 4 additions & 4 deletions src/request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ describe('Request', () => {
});

it('returns response of a successful GET request, with a proxy url', (done) => {
sinon.stub(process, 'env').value({ 'https_proxy': 'http://proxy.contoso.com:8080' });
sinon.stub(process, 'env').value({ 'HTTPS_PROXY': 'http://proxy.contoso.com:8080' });

sinon.stub(_request as any, 'req').callsFake((options) => {
_options = options as CliRequestOptions;
Expand All @@ -415,7 +415,7 @@ describe('Request', () => {
});

it('returns response of a successful GET request, with a proxy url and defaults port to 80', (done) => {
sinon.stub(process, 'env').value({ 'https_proxy': 'http://proxy.contoso.com' });
sinon.stub(process, 'env').value({ 'HTTPS_PROXY': 'http://proxy.contoso.com' });

sinon.stub(_request as any, 'req').callsFake((options) => {
_options = options as CliRequestOptions;
Expand All @@ -434,7 +434,7 @@ describe('Request', () => {
});

it('returns response of a successful GET request, with a proxy url and defaults port to 443', (done) => {
sinon.stub(process, 'env').value({ 'https_proxy': 'https://proxy.contoso.com' });
sinon.stub(process, 'env').value({ 'HTTPS_PROXY': 'https://proxy.contoso.com' });

sinon.stub(_request as any, 'req').callsFake((options) => {
_options = options as CliRequestOptions;
Expand All @@ -453,7 +453,7 @@ describe('Request', () => {
});

it('returns response of a successful GET request, with a proxy url with username and password', (done) => {
sinon.stub(process, 'env').value({ 'https_proxy': 'http://username:password@proxy.contoso.com:8080' });
sinon.stub(process, 'env').value({ 'HTTPS_PROXY': 'http://username:password@proxy.contoso.com:8080' });

sinon.stub(_request as any, 'req').callsFake((options) => {
_options = options as CliRequestOptions;
Expand Down
7 changes: 2 additions & 5 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class Request {
}
}

const proxyUrl = process.env.http_proxy || process.env.https_proxy;
const proxyUrl = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
if (proxyUrl) {
options.proxy = this.createProxyConfigFromString(proxyUrl);
}
Expand Down Expand Up @@ -248,10 +248,7 @@ class Request {
password: parsedUrl.password
};
}
else {
authObject = { username: '', password: '' };
}
return { host: hostname, port: Number(port), auth: authObject };
return { host: hostname, port: Number(port), protocol: 'http', ...(authObject && { auth: authObject }) };
}
}

Expand Down

0 comments on commit 0216284

Please sign in to comment.