diff --git a/cliv2/internal/cliv2/cliv2.go b/cliv2/internal/cliv2/cliv2.go index ef371acc8e1..347f5ddef36 100644 --- a/cliv2/internal/cliv2/cliv2.go +++ b/cliv2/internal/cliv2/cliv2.go @@ -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, "=") } diff --git a/cliv2/internal/cliv2/cliv2_test.go b/cliv2/internal/cliv2/cliv2_test.go index ff8556e7e05..4b574c5d916 100644 --- a/cliv2/internal/cliv2/cliv2_test.go +++ b/cliv2/internal/cliv2/cliv2_test.go @@ -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", @@ -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") @@ -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") @@ -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") diff --git a/cliv2/internal/constants/constants.go b/cliv2/internal/constants/constants.go index 8ed8d83ae4e..2076097dc91 100644 --- a/cliv2/internal/constants/constants.go +++ b/cliv2/internal/constants/constants.go @@ -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" diff --git a/test/jest/acceptance/https.spec.ts b/test/jest/acceptance/https.spec.ts index 9fc5c241080..b655d3e0395 100644 --- a/test/jest/acceptance/https.spec.ts +++ b/test/jest/acceptance/https.spec.ts @@ -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; 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);