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

Mention HTTP_PROXY if download error occurs; fall back to NPM's proxy… #4705

Merged
merged 5 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cli/__snapshots__/download_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ https://cypress.example.com/desktop/0.20.2?platform=OS&arch=ARCH
exports['download status errors 1'] = `
Error: The Cypress App could not be downloaded.

Please check network connectivity and try again:
Does your workplace require a proxy to be used to access the Internet? If so, you must configure the HTTP_PROXY environment variable before downloading Cypress. Read more: https://on.cypress.io/proxy-configuration

Otherwise, please check network connectivity and try again:

----------

Expand Down
5 changes: 4 additions & 1 deletion cli/lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const hr = '----------'
// common errors Cypress application can encounter
const failedDownload = {
description: 'The Cypress App could not be downloaded.',
solution: 'Please check network connectivity and try again:',
solution: stripIndent`
Does your workplace require a proxy to be used to access the Internet? If so, you must configure the HTTP_PROXY environment variable before downloading Cypress. Read more: https://on.cypress.io/proxy-configuration

Otherwise, please check network connectivity and try again:`,
}

const failedUnzip = {
Expand Down
12 changes: 12 additions & 0 deletions cli/lib/tasks/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ const util = require('../util')

const defaultBaseUrl = 'https://download.cypress.io/'

const getProxyUrl = () => {
return process.env.HTTPS_PROXY ||
process.env.https_proxy ||
process.env.npm_config_https_proxy ||
process.env.HTTP_PROXY ||
process.env.http_proxy ||
process.env.npm_config_proxy ||
null
}

const getRealOsArch = () => {
// os.arch() returns the arch for which this node was compiled
// we want the operating system's arch instead: x64 or x86
Expand Down Expand Up @@ -180,6 +190,7 @@ const downloadFromUrl = ({ url, downloadDestination, progress }) => {

const req = request({
url,
proxy: getProxyUrl(),
flotwig marked this conversation as resolved.
Show resolved Hide resolved
followRedirect (response) {
const version = response.headers['x-version']

Expand Down Expand Up @@ -306,4 +317,5 @@ const start = ({ version, downloadDestination, progress }) => {
module.exports = {
start,
getUrl,
getProxyUrl,
}
29 changes: 28 additions & 1 deletion cli/test/lib/tasks/download_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require('../../spec_helper')

const _ = require('lodash')
const os = require('os')
const la = require('lazy-ass')
const is = require('check-more-types')
Expand Down Expand Up @@ -138,7 +139,7 @@ describe('lib/tasks/download', function () {
})
})

describe('verify downloaded file', function () {
context('verify downloaded file', function () {
before(function () {
this.expectedChecksum = hasha.fromFileSync(examplePath)
this.expectedFileSize = fs.statSync(examplePath).size
Expand Down Expand Up @@ -310,4 +311,30 @@ describe('lib/tasks/download', function () {
return snapshot('download status errors 1', normalize(ctx.stdout.toString()))
})
})

context('with proxy env vars', () => {
beforeEach(function () {
this.env = _.clone(process.env)
})

afterEach(function () {
process.env = this.env
})

it('prefers https_proxy over http_proxy', () => {
process.env.HTTP_PROXY = 'foo'
expect(download.getProxyUrl()).to.eq('foo')
process.env.https_proxy = 'bar'
expect(download.getProxyUrl()).to.eq('bar')
})

it('falls back to npm_config_proxy', () => {
process.env.npm_config_proxy = 'foo'
expect(download.getProxyUrl()).to.eq('foo')
process.env.npm_config_https_proxy = 'bar'
expect(download.getProxyUrl()).to.eq('bar')
process.env.https_proxy = 'baz'
expect(download.getProxyUrl()).to.eq('baz')
})
})
})