Skip to content

Origin never changes back on 302 redirect #28795

Closed as not planned
Closed as not planned
@xaviergmail

Description

@xaviergmail

Current behavior

When the page of baseUrl redirects to another origin immediately via HTTP 302 for external login, Cypress changes the top level origin to that other domain and remains there. This causes issues for the rest of our tests, and wrapping all of our existing tests in cy.origin() is not an adequate solution.

image showing error

Desired behavior

Cypress should not do this and instead keep the top level origin the same as the provided baseURL, provide a way to configure a static origin, or allow for the origin to be changed inside a before() hook or another type of event.

Test code to reproduce

The easiest way to reproduce is to create a sample GitHub pages repository and set its visibility to private.

Use the following command to log into a dummy GitHub user with access to view the page:

Cypress.Commands.add('loginToGithubPages', (domain) => {
  const username = require_env('GITHUB_PAGES_USERNAME')
  const password = require_env('GITHUB_PAGES_PASSWORD')

  // View `e2e-tests/docs/github-pages-auth.md` for instructions on how to get this
  const totp_secret = require_env('GITHUB_PAGES_TOTP_SECRET')

  cy.url().should('include', 'github.com/login')
  cy.get('#login_field').clear()
  cy.get('#login_field').type(username)
  cy.get('#password').clear()
  cy.get('#password').type(password)
  cy.get('input[name="commit"]').click()
  cy.get('#app_totp').clear()

  const totp = authenticator.generate(totp_secret)
  cy.get('#app_totp').type(totp)
  cy.get('#app_totp')
    .should('not.exist')
    .then(() => {
      const decline_form = 'form[action="/sessions/trusted-device/decline?hard=true"]'
      if (Cypress.$(decline_form).length > 0) {
        cy.get(decline_form).submit()
      }
    })
  // It auto-submits when typing (at least at the time of writing)

Cypress Version

12.7.4

Node version

16.20.2

Operating System

macOS 14.1.1

Debug Logs

I am unable to release debug logs publicly as they may contain sensitive information but am happy to provide them in private.

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    stage: needs investigatingSomeone from Cypress needs to look at thisstaleno activity on this issue for a long periodtype: unexpected behaviorUser expected result, but got another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions