Sample cypress script to bypass SSO

老子叫甜甜 提交于 2020-01-05 05:41:24

问题


I am setting up new cypress tests to test some functionalities in Dynamics 365 application. But, I'm left with a browser window with the url https://login.microsoftonline.com/__/ and the text Whoops, there is no test to run.

describe('Initial Cypress Tests', () => {

it('navigate to D365', () => {
    cy.visit('https://wipropoc.crm8.dynamics.com')
} )

})


回答1:


Would suggest you to directly do a POST call for getting SSO authentication token and fire cy.visit('https://wipropoc.crm8.dynamics.com') with the obtained token.

Here are the steps to follow from official documentation,

  1. Login when authentication is done on a 3rd party server.
  2. Parse tokens using cy.request().
  3. Manually set tokens on local storage.
  4. Map external hosts and point to local servers.

cy.request('POST', 'https://sso.corp.com/auth', { username: 'foo', password: 'bar' })
    .then((response) => {
    // pull out the location redirect
    const loc = response.headers['Location']

    // parse out the token from the url (assuming its in there)
    const token = parseOutMyToken(loc)

    // do something with the token that your web application expects
    // likely the same behavior as what your SSO does under the hood
    // assuming it handles query string tokens like this
    cy.visit('http://localhost:8080?token=' + token)

    // if you don't need to work with the token you can sometimes
    // just visit the location header directly
    cy.visit(loc)
    })

You can read more about this here - https://docs.cypress.io/guides/guides/web-security.html#Form-Submission-Redirects

Real time example - https://xebia.com/blog/how-to-use-azure-ad-single-sign-on-with-cypress/



来源:https://stackoverflow.com/questions/55342478/sample-cypress-script-to-bypass-sso

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!