Skip to content

Commit

Permalink
chore: skip tests that cannot be satisfied with cliv2
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Schäfer <101886095+PeterSchafer@users.noreply.github.com>
Signed-off-by: Peter Schäfer <101886095+PeterSchafer@users.noreply.github.com>
  • Loading branch information
PeterSchafer committed Jun 14, 2022
1 parent 6735df1 commit 3f37725
Showing 1 changed file with 42 additions and 31 deletions.
73 changes: 42 additions & 31 deletions test/jest/acceptance/proxy-behavior.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const SNYK_API_HTTP = 'http://snyk.io/api/v1';
const FAKE_HTTP_PROXY = `http://localhost:${fakeServerPort}`;

jest.setTimeout(1000 * 60 * 1);
const itIfNotCLIV2 = () => (isCLIV2() ? it.skip : it);

describe('Proxy configuration behavior', () => {
describe('*_PROXY against HTTPS host', () => {
Expand Down Expand Up @@ -56,41 +57,51 @@ describe('Proxy configuration behavior', () => {
});

describe('*_PROXY against HTTP host', () => {
it('tries to connect to the HTTP_PROXY when HTTP_PROXY is set', async () => {
const { code, stderr } = await runSnykCLI(`woof -d`, {
env: {
...process.env,
HTTP_PROXY: FAKE_HTTP_PROXY,
SNYK_API: SNYK_API_HTTP,
SNYK_HTTP_PROTOCOL_UPGRADE: '0',
},
});
itIfNotCLIV2()(
'tries to connect to the HTTP_PROXY when HTTP_PROXY is set',
async () => {
const { code, stderr } = await runSnykCLI(`woof -d`, {
env: {
...process.env,
HTTP_PROXY: FAKE_HTTP_PROXY,
SNYK_API: SNYK_API_HTTP,
SNYK_HTTP_PROTOCOL_UPGRADE: '0',
},
});

expect(code).toBe(0);
// eslint-disable-next-line jest/no-standalone-expect
expect(code).toBe(0);

// It will *attempt* to connect to a FAKE_HTTP_PROXY (and fails, because it's not a real proxy server)
expect(stderr).toContain(
`Error: connect ECONNREFUSED 127.0.0.1:${fakeServerPort}`,
);
});
// It will *attempt* to connect to a FAKE_HTTP_PROXY (and fails, because it's not a real proxy server)
// eslint-disable-next-line jest/no-standalone-expect
expect(stderr).toContain(
`Error: connect ECONNREFUSED 127.0.0.1:${fakeServerPort}`,
);
},
);

it('does not try to connect to the HTTPS_PROXY when it is set', async () => {
const { code, stderr } = await runSnykCLI(`woof -d`, {
env: {
...process.env,
HTTPS_PROXY: FAKE_HTTP_PROXY,
SNYK_API: SNYK_API_HTTP,
SNYK_HTTP_PROTOCOL_UPGRADE: '0',
},
});
itIfNotCLIV2()(
'does not try to connect to the HTTPS_PROXY when it is set',
async () => {
const { code, stderr } = await runSnykCLI(`woof -d`, {
env: {
...process.env,
HTTPS_PROXY: FAKE_HTTP_PROXY,
SNYK_API: SNYK_API_HTTP,
SNYK_HTTP_PROTOCOL_UPGRADE: '0',
},
});

expect(code).toBe(2);
// eslint-disable-next-line jest/no-standalone-expect
expect(code).toBe(2);

// Incorrect behavior when Needle tries to upgrade connection after 301 http->https and the Agent option is set to a strict http/s protocol.
// See lines with `keepAlive` in request.ts for more details
expect(stderr).toContain(
'TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported. Expected "http:"',
);
});
// Incorrect behavior when Needle tries to upgrade connection after 301 http->https and the Agent option is set to a strict http/s protocol.
// See lines with `keepAlive` in request.ts for more details
// eslint-disable-next-line jest/no-standalone-expect
expect(stderr).toContain(
'TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported. Expected "http:"',
);
},
);
});
});

0 comments on commit 3f37725

Please sign in to comment.