样本cypress脚本绕过SSO [英] Sample cypress script to bypass SSO

查看:399
本文介绍了样本cypress脚本绕过SSO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置新的赛普拉斯测试,以测试Dynamics 365应用程序中的某些功能.但是,我剩下的浏览器窗口的网址为 https://login.microsoftonline.com/__/和文本糟糕",没有要运行的测试.

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

推荐答案

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

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. 在第三方服务器上完成身份验证后登录.
  2. 使用cy.request()解析令牌.
  3. 在本地存储上手动设置令牌.
  4. 映射外部主机并指向本地服务器.
  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)
    })

您可以在此处详细了解- https ://docs.cypress.io/guides/guides/web-security.html#Form-Submission-Redirects

You can read more about this here - 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/

这篇关于样本cypress脚本绕过SSO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆