Cypress cy.visit results in 401 unauthorized

Viewed 6001

I am getting a 401 - unauthorized on all my cy.visits that point to a https:// address.

I have tried disabling web security in the cypress.json using:

{
  "chromeWebSecurity": false
}

But this had no effect.

My proxy is properly configured.

Non https:// addresses work just fine. When visiting the pages manually through Chrome, they work just fine. I have tried switch Cypress to Electron, but this made no difference.

Any help would be greatly appreciated.

2 Answers

Cypress support for Kerberos proxy auth is an open issue: https://github.com/cypress-io/cypress/issues/4667

However, you can use Kerberos with Cypress today by setting up a local proxy. Cypress will hit this proxy using plain HTTP, and the proxy will complete the Kerberos authentication process and pass the content back and forth to your proxy server.

  1. Set up https://github.com/genotrance/px according to the README
  2. Run Cypress through the default port used by px:
    npm i -g cross-env
    cross-env HTTP_PROXY=http://127.0.0.1:3128 cypress open
    

For more information about Cypress proxy config, see the documentation

I believe the issue you have come across here is that you have active directory authentication on your web app, and that is why you're getting the 401. To test this, try opening up the app in a Chrome incognito window and if you're prompted for credentials, this is the case.

Here is one solution we are looking at to solve this:

https://www.npmjs.com/package/cypress-ntlm-auth

There is a bit of config you need to set up in your test suite for this to work, but it's documented quite well.

Related