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

Cypress cannot load pages behind a corporate proxy #672

Closed
getluke opened this issue Sep 20, 2017 · 65 comments
Closed

Cypress cannot load pages behind a corporate proxy #672

getluke opened this issue Sep 20, 2017 · 65 comments

Comments

@getluke
Copy link

@getluke getluke commented Sep 20, 2017

  • Operating System: Mac OS 10.12.6
  • Cypress Version: 0.20.1
  • Browser Version: Chrome v61

Is this a Feature or Bug?

Feature

Current behavior:

When running on a machine that requires a corporate proxy, cypress does not use the proxy settings and therefore cannot access and run tests on pages behind the proxy.

Desired behavior:

Cypress should respect the internal proxy settings of the network. From Brian Mann in Gitter:

"right i think its something we'll have to take into account and upgrade
cypress does not respect the internal proxy settings of the network
it would just work if we took that into account though"

Additional Info (images, stack traces, etc)

Resolving this would allow teams behind corporate proxies to adopt the software.

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Sep 20, 2017

Related issue #584

@yuriMalakhov
Copy link

@yuriMalakhov yuriMalakhov commented Oct 19, 2017

Thank you for the great product!

Any news or workarounds on using Cypress behind a corporate proxy?

@vjefri03
Copy link

@vjefri03 vjefri03 commented Oct 20, 2017

Cypress is an extension on chrome. I was running into the same issue and getting 503. I fixed it by enabling permissions on the extension. Upper right hand where the three dots for settings
screen shot 2017-10-19 at 9 37 55 pm
go to extensions and allow permissions
screen shot 2017-10-19 at 9 37 35 pm

screen shot 2017-10-19 at 9 39 47 pm

@ayellamanchilli
Copy link

@ayellamanchilli ayellamanchilli commented Oct 25, 2017

Thank you for the great product.

I am able to access all the general applications like facebook, gmail so on. Issue is with accessing my application which can be accessible only in my office network. I see runner is trying to invoke the URL but at the end gives an error 'Whoops there is no test to run'.

Other sample tests are running fine without any issues. I had a discussion with my IT team and they are not able to help me on this.

Any update on this issue??

@timothystone
Copy link

@timothystone timothystone commented Nov 4, 2017

@getluke have you seen @vjefri03 suggestion?

@Jan10
Copy link

@Jan10 Jan10 commented Nov 9, 2017

Same problem here.
image

@vjefri03 suggestion does not work for me.

@andrewleith
Copy link

@andrewleith andrewleith commented Nov 20, 2017

Oddly, this works perfectly fine for me on a mac. I am VPN'd into my corporate network, which then forces me to use a proxy to go out to the internet.

My app loads just fine in Cypress, as do the resources coming off CDNs. I wonder why it would work for some of us and not others?

@jivimberg
Copy link

@jivimberg jivimberg commented Nov 20, 2017

Similar setup here: mac with corporate VPN and proxy configured.

My app loads ok but CDN content times out.

@charch
Copy link

@charch charch commented Nov 20, 2017

Oops. I just created a new ticket describing the same issue as jivimberg, but I'm using Windows. Would be great to have this sorted out, as this testing framework seems to have many advantages over the others.

@andrewleith
Copy link

@andrewleith andrewleith commented Nov 21, 2017

I just tried troubleshooting to see why my setup works when others' do not. I removed my proxy settings from the VPN network settings and experienced the same behaviour as the others (no external sites would load). Once I added them back, still no external sites would load.

The only way I've gotten things to work is by running the tests once while not connected to the VPN, then they seem to work correctly afterwards when connected to the VPN (this is obviously not a solution for people trying to use Cypress from work). So I am concluding that this never properly worked for me over the VPN, I just thought it did.

I would very much like to see this issue get fixed so my team can try using Cypress on a few projects :)

Let me know what I can do to help.

@brian-mann
Copy link
Member

@brian-mann brian-mann commented Nov 21, 2017

Since Cypress acts as a reverse proxy to the browser (which also ends up terminating traffic amongst other things), when it makes the external requests to 3rd party servers, it needs to respect the system proxy settings. That's why this is failing.

If Cypress proxied itself to the upstream proxy of the system, then all would work. This is likely a change that only needs to be made in a few places. The trick here is that we need a reproducible repo or the minimum steps to reproduce so we can write tests to ensure this is working.

Until someone does that, there are other things that will take priority over this feature.

@andrewleith
Copy link

@andrewleith andrewleith commented Nov 21, 2017

Well isn't the requirement here for reproduction a VPN where a proxy is required to get out to the internet? It doesn't actually have anything to do with the repo itself, or am I missing something?

@brian-mann
Copy link
Member

@brian-mann brian-mann commented Nov 21, 2017

That is true. However, you could likely put together a repo involving a transparent or reverse proxy that the traffic must tunnel through before hitting a regular http server.

The thing here is that I'm not sure if Cypress is supposed to read off the "corporate proxy" settings from the operating system itself - or if we need to expose configuration via cypress.json or environment variables that enables you to specify what the proxy is.

In other words - help us implement the exact steps needed to reproduce the failing environment so we can implement a solution to it. Even referencing other tools that do work would be helpful so we can look at how they solve this.

@andrewleith
Copy link

@andrewleith andrewleith commented Nov 21, 2017

I can't see why Cypress wouldn't automatically use the system's proxy settings when it can. That would be my vote. Its also what most apps have done in my experience sitting behind our pointless corporate proxy.

As an aside, I have also tried adding environment variables (http_proxy, https_proxy) to the env key of the cypress.json file but still they were not honoured.

@brian-mann
Copy link
Member

@brian-mann brian-mann commented Nov 21, 2017

Right - so we can definitely respect the http_proxy and https_proxy env variables - i just wasn't sure what Cypress would need to do to read off the system proxy settings (if these aren't set as env vars).

@brian-mann
Copy link
Member

@brian-mann brian-mann commented Nov 21, 2017

Can you do an experiment - open node (any version) and check process.env to see if http_proxy is set without you explicitly setting it.

Or you could also just do print_env. What I'm trying to determine is whether these environment variables are automatically added by the system proxy. If they are not, then we'll need to come up with a way to read them all. I haven't looked but there's probably already modules that do this...

@andrewleith
Copy link

@andrewleith andrewleith commented Nov 21, 2017

No, I cannot see either http_ or https_proxy in process.env.

@timothystone
Copy link

@timothystone timothystone commented Nov 22, 2017

They are not added to node via the Mac OS X System Settings. They must be explicitly added to the environment in the shell, e.g., .zshenv. I'm not aware of node support for reading the system network preferences and exposing them as process variables, yet.

Update
I didn't have this gist handy—being on the Enterprise GitHub we run—to show how the standard team, using zsh, sets their proxy for using node

How to manage the proxy in ZSH...or one way to do so at the very least.

@andrewleith
Copy link

@andrewleith andrewleith commented Nov 22, 2017

I would be happy with this working from the cypress.json config. Is that a possibility?

@brian-mann
Copy link
Member

@brian-mann brian-mann commented Nov 22, 2017

Yes it looks like we can simply expose a new set of configuration in cypress.json for the proxy settings and also read them from process.env if they happen to be defined.

@g00fy-
Copy link

@g00fy- g00fy- commented Nov 23, 2017

@brian-mann
please also enable setting strict-ssl, proxy and https-proxy in cypress.json as not all proxy have valid certificates

@brian-mann
Copy link
Member

@brian-mann brian-mann commented Nov 23, 2017

We already turn off strict SSL handling in Cypress since Cypress itself is a proxy that issues invalid on the fly certificates.

Can anyone reference me another application that exposes the kinds of proxy configuration settings that is required here? I am still at a loss as to how many fields would need to be added to cypress.json

@g00fy-
Copy link

@g00fy- g00fy- commented Nov 24, 2017

How about npm ?

https://docs.npmjs.com/misc/config#https-proxy
https://docs.npmjs.com/misc/config#proxy

It turns out that setting HTTPS_PROXY env in windows also works.

@timothystone
Copy link

@timothystone timothystone commented Nov 26, 2017

@brian-mann see above ZSH proxy setter. At a minimum HTTP_PROXY, http_proxy, HTTPS_PROXY, and https_proxy.

In my corporate environment, all SSL connections are terminated at the proxy, so HTTPS and HTTP setting are identical. The UPPER and lower case versions are to cover a couple of edge cases where some programs don't recognize the conventions, e.g., npm apparently likes uses https-proxy (but looks for the underscore versions, as noted by @g00fy-).

@andrewleith
Copy link

@andrewleith andrewleith commented Nov 27, 2017

After some experimentation, it appears cypress respects most of the environment proxy variables once they are set. If I set http_proxy before launching cypress, cypress respects the setting and sends traffic to the proxy first. The little gotcha here was that I also had to set the no_proxy variable to ensure that for localhost it did not attempt to use the proxy.

For some reason, resources over https were not sent through the proxy, even though I had also set the https_proxy variable. Perhaps I should be using some other variable? (I also tried HTTPS_PROXY)

@jivimberg Did you (or could you) try running cypress after setting both http_proxy and no_proxy and see if your setup can work as expected?

In summary, I think cypress should support at a minimum the following environment variables:
http_proxy
https_proxy
no_proxy

@jivimberg
Copy link

@jivimberg jivimberg commented Nov 30, 2017

I tried with the 3 variables set and it's working!
Only thing that didn't work for me is with https requests, but maybe that's just my proxy settings?

@Baasie
Copy link

@Baasie Baasie commented Dec 28, 2017

Looks like i am experiencing the same behaviour on a centos container where i can curl towards an https url but if i set this as my baseUrl it does not work. HTTPS_PROXY and https_proxy both are set.

@cypress-bot
Copy link

@cypress-bot cypress-bot bot commented Apr 1, 2019

The code for this is done in cypress-io/cypress#3531, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link

@cypress-bot cypress-bot bot commented May 17, 2019

Released in 3.3.0.

@santoshauz
Copy link

@santoshauz santoshauz commented May 22, 2019

Resolved: Had a similar issue.

### Windows only
Environment variable gets set automatically with default proxy ( Company Proxy)
Delete the Variable and restart the PC (Optional)
Delete : http_proxy

@RupenAnjaria
Copy link

@RupenAnjaria RupenAnjaria commented Aug 6, 2019

I m facing similar issue, however in Windows 10 running following command tells me that there is no proxy server: netsh winhttp show proxy returns
"Current WinHTTP proxy settings: Direct access (no proxy server)"

However, yarn add cypress -D fails with the message to setup HTTP_PROXY variable.

URL: https://download.cypress.io/desktop/3.4.1?platform=win32&arch=x64
Error: connect ETIMEDOUT 104.25.214.23:443

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Aug 7, 2019

@RupenAnjaria Please make sure to follow the directions on proxy setup from our docs: https://on.cypress.io/proxy-configuration#Windows

@RupenAnjaria
Copy link

@RupenAnjaria RupenAnjaria commented Aug 8, 2019

So I manually downloaded Cypress and opened it along with my project. Upon settings -> Proxy Settings displays message: There is no active proxy configuration.

@flotwig
Copy link
Member

@flotwig flotwig commented Aug 8, 2019

@RupenAnjaria Does your environment require a proxy to access the Internet?

The message that the CLI gives is generic, if you do not usually need a proxy you do not need to set one up.

@RupenAnjaria
Copy link

@RupenAnjaria RupenAnjaria commented Aug 8, 2019

Unfortunately the settings are done by my company's tech support team.
See below, it is configured to check proxy via some script file. I have to be in VPN.
image

@RupenAnjaria
Copy link

@RupenAnjaria RupenAnjaria commented Aug 9, 2019

If I can not add it via yarn add cypress -D then is it okay if I download the CLI and open the project from it?

@flotwig
Copy link
Member

@flotwig flotwig commented Aug 9, 2019

@RupenAnjaria You can download that .pac file under "Automatic configuration script" and extract the proxy server you need, then use HTTP_PROXY=... to supply that to Cypress. You can also try downloading the executable from cypress.io, but that's not a great long-term solution.

@RupenAnjaria
Copy link

@RupenAnjaria RupenAnjaria commented Aug 9, 2019

Download .pac from where?

@flotwig
Copy link
Member

@flotwig flotwig commented Aug 9, 2019

The URL that you've blacked out in the image you shared.

@RupenAnjaria
Copy link

@RupenAnjaria RupenAnjaria commented Aug 9, 2019

it's a dat file and has some javascript within it. As I mentioned earlier running netsh winhttp show proxy command says I do not have any proxy, so in that case what should be the value of HTTP_PROXY?

@flotwig
Copy link
Member

@flotwig flotwig commented Aug 9, 2019

Yeah, the proxy IP and PORT are in that Javascript. Figure out what IP and host are used for external traffic and set that to your HTTP_PROXY (ex, HTTP_PROXY=http://my-company.net:12345). Or, ask your IT support what the correct proxy to use for external traffic is.

@RupenAnjaria
Copy link

@RupenAnjaria RupenAnjaria commented Aug 27, 2019

I tried but they did not understand :( , can I install it without npm? any link/reference which can help to use cypress (without npm proxy setup?)

@nschonni
Copy link

@nschonni nschonni commented Oct 8, 2019

the standard https://docs.npmjs.com/misc/config#strict-ssl didn't work, but setting the environment variable NODE_TLS_REJECT_UNAUTHORIZED to 0 from #1401 (comment) worked

@RupenAnjaria
Copy link

@RupenAnjaria RupenAnjaria commented Oct 24, 2019

the standard https://docs.npmjs.com/misc/config#strict-ssl didn't work, but setting the environment variable NODE_TLS_REJECT_UNAUTHORIZED to 0 from #1401 (comment) worked

not for me :(

@speasley
Copy link

@speasley speasley commented Feb 18, 2020

I am running into this issue upon trying to deploy to Netlify. The deployment is failing because Cypress could not be downloaded.

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Feb 18, 2020

This issue will be closed to further comment as the exact issue here was resolved and tested.

If you're experiencing a bug similar or that seems related to this in Cypress, please fully read and following the instructions in our Proxy Configuration doc: https://on.cypress.io/proxy-configuration

If you're still experiencing an issue, open a new issue with a fully reproducible example that we can run. There may be a specific edge case with the issue that we need more detail to fix.

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Feb 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.