Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: SonarSource/sonar-scanner-npm
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e06fd72f81f4c44bf068d695aa6cffd9ab3b4a08
Choose a base ref
...
head repository: SonarSource/sonar-scanner-npm
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5850a9e8b1646878731b763e0de729a8df536c7a
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Sep 16, 2024

  1. SCANNPM-47 Assume all proxies use http protocol

    7PH committed Sep 16, 2024
    Copy the full SHA
    999d80c View commit details

Commits on Sep 18, 2024

  1. NO-JIRA Bump package.json version to 4.2.3

    7PH committed Sep 18, 2024
    Copy the full SHA
    5850a9e View commit details
Showing with 10 additions and 19 deletions.
  1. +2 −2 package-lock.json
  2. +1 −1 package.json
  3. +3 −12 src/proxy.ts
  4. +1 −1 test/unit/proxy.test.ts
  5. +3 −3 test/unit/request.test.ts
4 changes: 2 additions & 2 deletions 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,7 +1,7 @@
{
"name": "sonarqube-scanner",
"description": "SonarQube/SonarCloud Scanner for the JavaScript world",
"version": "4.2.2",
"version": "4.2.3",
"homepage": "https://github.com/SonarSource/sonar-scanner-npm",
"author": {
"name": "Fabrice Bellingard",
15 changes: 3 additions & 12 deletions src/proxy.ts
Original file line number Diff line number Diff line change
@@ -21,24 +21,15 @@ import { URL } from 'url';
import { LogLevel, log } from './logging';
import { ScannerProperties, ScannerProperty } from './types';

const DEFAULT_HTTPS_PROXY_PORT = 443;
const DEFAULT_HTTP_PROXY_PORT = 80;

export function getProxyUrl(properties: ScannerProperties): URL | undefined {
const proxyHost = properties[ScannerProperty.SonarScannerProxyHost];
const serverUsesHttps = properties[ScannerProperty.SonarHostUrl].startsWith('https');

if (proxyHost) {
// We assume that the proxy protocol is the same as the endpoint.
const protocol = serverUsesHttps ? 'https' : 'http';
const proxyPort =
properties[ScannerProperty.SonarScannerProxyPort] ??
(serverUsesHttps ? DEFAULT_HTTPS_PROXY_PORT : DEFAULT_HTTP_PROXY_PORT);
const proxyPort = properties[ScannerProperty.SonarScannerProxyPort] ?? '80';
const proxyUser = properties[ScannerProperty.SonarScannerProxyUser] ?? '';
const proxyPassword = properties[ScannerProperty.SonarScannerProxyPassword] ?? '';
const proxyUrl = new URL(
`${protocol}://${proxyUser}:${proxyPassword}@${proxyHost}:${proxyPort}`,
);
// SCANNPM-47 We assume the proxy is HTTP. HTTPS proxies are not supported by the scanner yet (CONNECT over TLS)
const proxyUrl = new URL(`http://${proxyUser}:${proxyPassword}@${proxyHost}:${proxyPort}`);
log(LogLevel.DEBUG, `Detecting proxy: ${proxyUrl}`);
return proxyUrl;
} else if (
2 changes: 1 addition & 1 deletion test/unit/proxy.test.ts
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ describe('proxy', () => {
};
getProxyUrl(properties);

expect(getProxyUrl(properties)?.toString()).toBe('https://some-proxy.io/');
expect(getProxyUrl(properties)?.toString()).toBe('http://some-proxy.io/');
});

it('should detect proxy with host and port', () => {
6 changes: 3 additions & 3 deletions test/unit/request.test.ts
Original file line number Diff line number Diff line change
@@ -45,9 +45,9 @@ describe('request', () => {
[ScannerProperty.SonarScannerProxyHost]: 'proxy.com',
});
expect(agents.httpAgent).toBeInstanceOf(HttpProxyAgent);
expect(agents.httpAgent?.proxy.toString()).toBe('https://proxy.com/');
expect(agents.httpAgent?.proxy.toString()).toBe('http://proxy.com/');
expect(agents.httpsAgent).toBeInstanceOf(HttpsProxyAgent);
expect(agents.httpsAgent?.proxy.toString()).toBe('https://proxy.com/');
expect(agents.httpsAgent?.proxy.toString()).toBe('http://proxy.com/');
});

it('should not define agents when no proxy is provided', async () => {
@@ -160,7 +160,7 @@ describe('request', () => {
expect(ca).toContain(certificatePem);
expect(httpsAgent?.options.pfx).toEqual(fsExtra.readFileSync(keystorePath));
expect(httpsAgent?.options.passphrase).toBe(keystorePass);
expect(httpsAgent?.proxy.toString()).toBe('https://proxy.com/');
expect(httpsAgent?.proxy.toString()).toBe('http://proxy.com/');
});
});