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

cy.origin re-redirect #23236

Closed
stychu opened this issue Aug 10, 2022 · 6 comments · Fixed by #23297
Closed

cy.origin re-redirect #23236

stychu opened this issue Aug 10, 2022 · 6 comments · Fixed by #23297
Assignees

Comments

@stychu
Copy link

stychu commented Aug 10, 2022

Current behavior

My login page is on different domain than the app.
I have a redirect within the app that redirects to the login domain.
Trying to make it work with cy.origin but it seems it doesn't pick up middle redirect from the app or I'm doing something wrong.

Flow

  1. Visit http://xyz/baseurl/create-location (not logged in before)
  2. Auto redirect to http://xyz/baseurl/one-login-redirect
  3. http://xyz/baseurl/one-login-redirect redirects to http://abc/login

This doesn't work because of the flow step 2 which triggers second redirect from within the app then goes to the login domain. I can see in the cypress my login domain loaded but cy.origin can't query the dom for the inputs to login

Seems like cy.origin expects direct redirect trigger to properly work.
Can i somehow overcome this? Tried to assert he step 2 url but cy.origin still doesn't work

Desired behavior

cy.origin should work when redirect triggers other redirects (middle redirects) leading to origin

Test code to reproduce

    cy.visit('/create-location')
    cy.origin(Cypress.env('LOGIN_ORIGIN'), { args: users.ADMIN }, ({ username, password }) => {
      cy.get('#username').type(username)
      cy.get('#password').type(password)
      cy.get('button[type=submit]').click()
    })

Cypress Version

10.4.0

Other

Screenshot 2022-08-10 at 11 57 53

@cypress-bot cypress-bot bot added the stage: investigating Someone from Cypress is looking into this label Aug 10, 2022
@AtofStryker
Copy link
Contributor

Hey @stychu. Thank you for opening an issue (hopefully this one is simpler 😅 ). Just have a few questions:

  1. Is your main application and login application on different origins? They both look to be localhost, which might mean you may not need cy.origin
  2. Is your base URL set?
  3. Anyway you could throw together a quick reproduction repo?

This looks like a 302 server side redirect. We have a similar issue opened with #22282 where this happens with a 301 redirect. Does the origin command time out or does the get fail? Are you able to provide the Assertion error?

@stychu
Copy link
Author

stychu commented Aug 11, 2022

@AtofStryker

  1. Yes. Internally we use OneLogin flow. Locally we use WireMock to mock the OneLogin login form submission
  2. Yes
  3. Im bit busy rn but I will try

This looks like a 302 server side redirect. We have a similar issue opened with #22282 where this happens with a 301 redirect. Does the origin command time out or does the get fail? Are you able to provide the Assertion error?

Indeed
Screenshot 2022-08-11 at 12 24 39

As described in the #22282 if I would trigger the OneLogin origin via button click for example from my app at /login it would do direct redirect to OneLogin origin and cy.origin works like a charm. Problem is I want to test a scenario where user gets redirected to login if not authenticated but he tries to access any page of the app. In this case server redirect doesnt seem to work with origin

@cypress-bot cypress-bot bot added stage: routed to e2e-auth and removed stage: investigating Someone from Cypress is looking into this labels Aug 15, 2022
@AtofStryker
Copy link
Contributor

We confirmed that #23297 should fix #22282. We can't 💯 confirm since we do not have a concrete reproduction, but we feel confident that #23297 should resolve this issue.

@stychu
Copy link
Author

stychu commented Aug 23, 2022

We confirmed that #23297 should fix #22282. We can't 💯 confirm since we do not have a concrete reproduction, but we feel confident that #23297 should resolve this issue.

Awesome! As soon as it lands I will try it out.
Sorry for not providing a reproduction but I tried to make it up but failed. I hope for the fixes

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 15, 2022

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

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 27, 2022

Released in 10.9.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v10.9.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants