-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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() does not fit when frontend redirects to another domain login page #21201
Comments
@edudelta, it('server redirects to login page', () => {
cy.origin('https://anotherdomain.com', () => {
cy.visit('https://mydomain.com/page') // server responds with a 3xx status code to redirect to anotherdomain.com/login
// perform login steps
cy.get('#login-button').click() // clicking login button redirects back to mydomain.com
})
cy.get('#user').should('contain', 'username')
})
it('client redirects to login page', () => {
cy.visit('https://mydomain.com/page') // server responds with a 2xx status code and client redirects to anotherdomain.com/login
cy.origin('https://anotherdomain.com', () => {
// no visit is needed here since we've already been redirected
// cy.visit('https://mydomain.com/page')
// perform login steps
cy.get('#login-button').click() // clicking login button redirects back to mydomain.com
})
cy.get('#user').should('contain', 'username')
}) |
Hi @mschile thank you so much by your help. Browsers: Chrome 100, Electron 94, Edge 100 |
Are you trying to use a public login provider? Do you have a test case you could provide? Do you see any errors in the browser? Instead of redirecting the login page through it('visits login page', () => {
cy.visit('https://anotherdomain.com/login')
}) |
I'm using a SAP integration to perform login cross-domain and unfortunately I don't have public logs to share. ;/ |
@mschile I've have some problems with multi-domain too. login: (username: string, password: string) => {
cy.session(
[username, password],
() => {
cy.visit('/');
cy.get('#signIn').click(); // The client uses some lib here, prefer to use it instead of calculating the url.
cy.url({ timeout: 10000 }).should('includes', '/realms/'); // If I take this url and move to another browser, it logs in successfully.
cy.url().then(url => {
const { protocol, host } = new URL(url); // sometimes we use keycloak domain, others localhost.
// eslint-disable-next-line @typescript-eslint/no-shadow
cy.origin(`${protocol}//${host}`, { args: { url, username, password } }, ({ url, username, password }) => {
// Reload oauth2 login page due to cypress origin change.
cy.visit(url); // Reload page otherwise below implementation doesn't work. Selectors times out.
cy.get('input[name="username"]').type(username);
cy.get('input[name="password"]').type(password);
cy.getCookies({ log: true }); // Cookies are empty, we should have some Keycloak cookies here.
cy.get('input[type="submit"]').click(); // Fails with We are sorry... An error occurred, please login again through your application.
});
});
cy.url({ timeout: 10000 }).should('eq', Cypress.config().baseUrl + 'tabs/home');
},
{
validate: () => {
cy.authenticatedRequest({ url: '/api/account' }).its('status').should('eq', 200);
},
}
);
}, My guess is that cypress is failing to manage cookies at the secondary domain. |
@mshima cy.get('#signIn').click(); // This redirects, we wait for a non cross origin load unless a cy.origin command is next
cy.url({ timeout: 10000 }).should('includes', '/realms/'); // This command is ran on the 'localhost' origin but tries to interact with the new aut origin and would have a cross origin failure.
cy.url().then(url => { |
@edudelta, I'm not sure how to proceed helping you debug. I think we'd need a reproducible test case that we could access. |
@mjhenkes I’ve removed url and used hardcoded url without success. |
@mshima, yes, a reproducible project would be great. |
mmm... What type of log could help in this case? tail of DEBUG=cypress:* is good enough? |
@mschile the repro is https://github.com/mshima/cypress-origin, and step are at the README. |
This bug looks Keycloak specific. Okta and Auth0 seems to be ok. Failure screenshot: |
@mshima, thanks for the repro. As you suspected, the issue is with cookies in the secondary domain. We added some temporary logic that assumes either localhost or |
@mschile localhost works. |
@mschile I'm using Oauth2 and I will wait for the fix changing to try once more. thank you |
Closing as a duplicate, please follow #20685 for any updates. |
@mschile This is in fact an issue as described originally: when the 'frontend redirects' the page load of Can this be reopened? |
I'm getting some deeply odd behaviour. I visit my homepage, get redirected, and then log in like so:
My first test passes, but subsequent tests fail with:
|
@pezholio Can you please open a separate issue? |
@pezholio Can you somehow link this to your new ticket once created? I am interested in this as well. |
What would you like?
According cy.origin() docs it's needed to step directly to a multidomain page and make all steps needed, being the multidomain required in advance.
However it does not fit when frontend redirects to a login page in another domain when it's not signed in, for instance. This is needed due frontend needs to create tokens, else, and then send to a login page that will redirect back to the main site.
It can be something like:
mydomain/page ---(not signed in)---> anotherdomain/login
Perform login steps...
anotherdomain/login ---(signed in!) ---> back to mydomain/page
Why is this needed?
I don't have enough resources to call anotherdomain/login page and any direct access to login page, in another domain, is not a valid user flow if does not came from main domain.
Other
No response
The text was updated successfully, but these errors were encountered: