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

Ensure to add localhost communication to NO_PROXY #4260

Merged
merged 1 commit into from Dec 27, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cliv2/internal/cliv2/cliv2.go
Expand Up @@ -249,6 +249,7 @@ func PrepareV1EnvironmentVariables(input []string, integrationName string, integ
inputAsMap[constants.SNYK_HTTPS_PROXY_ENV] = proxyAddress
inputAsMap[constants.SNYK_HTTP_PROXY_ENV] = proxyAddress
inputAsMap[constants.SNYK_CA_CERTIFICATE_LOCATION_ENV] = caCertificateLocation
inputAsMap[constants.SNYK_HTTP_NO_PROXY_ENV] = constants.SNYK_INTERNAL_NO_PROXY

result = utils.ToSlice(inputAsMap, "=")
}
Expand Down
5 changes: 4 additions & 1 deletion cliv2/internal/cliv2/cliv2_test.go
Expand Up @@ -21,7 +21,7 @@ func Test_PrepareV1EnvironmentVariables_Fill_and_Filter(t *testing.T) {
"something=1",
"in=2",
"here=3=2",
"no_proxy=noProxy",
"NO_PROXY=noProxy",
"HTTPS_PROXY=httpsProxy",
"HTTP_PROXY=httpProxy",
"NPM_CONFIG_PROXY=something",
Expand All @@ -41,6 +41,7 @@ func Test_PrepareV1EnvironmentVariables_Fill_and_Filter(t *testing.T) {
"SNYK_SYSTEM_NO_PROXY=noProxy",
"SNYK_SYSTEM_HTTP_PROXY=httpProxy",
"SNYK_SYSTEM_HTTPS_PROXY=httpsProxy",
"NO_PROXY=" + constants.SNYK_INTERNAL_NO_PROXY,
}

actual, err := cliv2.PrepareV1EnvironmentVariables(input, "foo", "bar", "proxy", "cacertlocation")
Expand All @@ -66,6 +67,7 @@ func Test_PrepareV1EnvironmentVariables_DontOverrideExistingIntegration(t *testi
"SNYK_SYSTEM_NO_PROXY=",
"SNYK_SYSTEM_HTTP_PROXY=",
"SNYK_SYSTEM_HTTPS_PROXY=",
"NO_PROXY=" + constants.SNYK_INTERNAL_NO_PROXY,
}

actual, err := cliv2.PrepareV1EnvironmentVariables(input, "foo", "bar", "proxy", "cacertlocation")
Expand All @@ -91,6 +93,7 @@ func Test_PrepareV1EnvironmentVariables_OverrideProxyAndCerts(t *testing.T) {
"SNYK_SYSTEM_NO_PROXY=312123",
"SNYK_SYSTEM_HTTP_PROXY=exists",
"SNYK_SYSTEM_HTTPS_PROXY=already",
"NO_PROXY=" + constants.SNYK_INTERNAL_NO_PROXY,
}

actual, err := cliv2.PrepareV1EnvironmentVariables(input, "foo", "bar", "proxy", "cacertlocation")
Expand Down
1 change: 1 addition & 0 deletions cliv2/internal/constants/constants.go
Expand Up @@ -15,6 +15,7 @@ const SNYK_NPM_NO_PROXY_ENV = "NPM_CONFIG_NO_PROXY"
const SNYK_NPM_ALL_PROXY = "ALL_PROXY"
const SNYK_CA_CERTIFICATE_LOCATION_ENV = "NODE_EXTRA_CA_CERTS"
const SNYK_DEFAULT_API_URL = "https://api.snyk.io"
const SNYK_INTERNAL_NO_PROXY = "localhost,127.0.0.1,::1"

const SNYK_HTTPS_PROXY_ENV_SYSTEM = "SNYK_SYSTEM_HTTPS_PROXY"
const SNYK_HTTP_PROXY_ENV_SYSTEM = "SNYK_SYSTEM_HTTP_PROXY"
Expand Down
25 changes: 23 additions & 2 deletions test/jest/acceptance/https.spec.ts
Expand Up @@ -4,20 +4,41 @@ import { createProjectFromWorkspace } from '../util/createProject';
import { getFixturePath } from '../util/getFixturePath';
import { runSnykCLI } from '../util/runSnykCLI';
import { isCLIV2 } from '../util/isCLIV2';
import * as os from 'os';

jest.setTimeout(1000 * 30);

function getFirstIPv4Address(): string {
let ipaddress = '';

const interfaces = os.networkInterfaces();
for (const [, group] of Object.entries(interfaces)) {
if (group) {
for (const inter of group) {
if (inter && inter.family == 'IPv4' && inter.address != '127.0.0.1') {
ipaddress = inter.address;
break;
}
}
}
}
return ipaddress;
}

describe('https', () => {
let server: FakeServer;
let env: Record<string, string>;

beforeAll(async () => {
const ipaddress = getFirstIPv4Address();
console.log('Using ip: ' + ipaddress);

const port = process.env.PORT || process.env.SNYK_PORT || '12345';
const baseApi = '/api/v1';
env = {
...process.env,
SNYK_API: 'https://localhost:' + port + baseApi,
SNYK_HOST: 'https://localhost:' + port,
SNYK_API: 'https://' + ipaddress + ':' + port + baseApi,
SNYK_HOST: 'https://' + ipaddress + ':' + port,
SNYK_TOKEN: '123456789',
};
server = fakeServer(baseApi, env.SNYK_TOKEN);
Expand Down