示例cypress脚本绕过SSO

问题描述 投票:1回答:1

我正在设置新的cypress测试来测试Dynamics 365应用程序中的一些功能。但是,我留下了一个浏览器窗口,其中包含网址https://login.microsoftonline.com/__/和文本Whoops,没有运行测试。

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

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

})

javascript azure login single-sign-on cypress
1个回答
0
投票

建议您直接进行POST调用以获取SSO身份验证令牌并使用获取的令牌触发cy.visit('https://wipropoc.crm8.dynamics.com')

以下是官方文档中要遵循的步骤,

  1. 在第三方服务器上进行身份验证时登录。
  2. 使用cy.request()解析令牌。
  3. 在本地存储上手动设置令牌。
  4. 映射外部主机并指向本地服务器。

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)
    })

你可以在这里阅读更多相关信息 - https://docs.cypress.io/guides/guides/web-security.html#Form-Submission-Redirects

实时示例 - https://xebia.com/blog/how-to-use-azure-ad-single-sign-on-with-cypress/

© www.soinside.com 2019 - 2024. All rights reserved.