0

We had been using TestCafe for automated testing against our SPA from 2018 - early 2020 where we started to run into issues with MSAL 1.0 and the blocking of 3rd party cookies. We recently upgraded to our authentication packages to MSAL 2.0 in our app to overcome of the 3rd party cookie issue, but are still running into an issue with TestCafe being unable to complete the login flow. We use AAD B2C as our authentication provider. We believe the issue is related to the proxied URL when TestCafe attempts to login as the automatic redirect to the B2C login page fails as the proxied URL is not recognized within the app registration. Has anyone been able to use TestCafe using AAD B2C as an auth provider with a Angular single page app using MSAL 2.0?

Issue: TestCafe navigates to the app URL and there is no redirect to the B2C login page. This issue only exists with the proxied TestCafe traffic.

Expected behavior: Upon navigation to the base URL, the unauthenticated user should be redirect to the B2C login page and upon login redirected to the app in an authenticated state.

Environment Details: Angular 10.2.5, Angular/MSAL 2.0.2, TestCafe 1.15,

App registration as a SPA app with redirect URLS to the app base url.

Have tried with TestCafe preserveURL:true and pageCachingDisabled:true following TestCafe recommendations even though we don't believe this to be the root of the issue.

Any help is appreciated.

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47

2 Answers2

1

Older versions of TestCafe have a few issues with web sites that use MSAL 2.0 (1, 2, 3). In the latest TestCafe version (1.15.3), all these issues are fixed. Try running your tests with the latest TestCafe version and use the --disable-page-caching) option if necessary. You can find more information in the linked issues.

mlosev
  • 5,130
  • 1
  • 19
  • 31
  • Thanks for the reply. I can confirm we are running 1.15.3. and have --disable-page-caching set to true. I believe the issue less MSAL related and more B2C related. Have you used Testcafe with AAD B2C and MSAL 2.0? Previously, things worked with B2C and MSAL 1.0 until browsers made the update to block 3rd party cookies by default. Following the MSAL 2.0 upgrade, our app does not redirect to our Microsoft login page. I believe this is due to the testcafe proxy not being recognized as a redirect/reply URL, but am looking for workarounds. – estpeter Aug 30 '21 at 14:01
  • This behavior looks like a bug. I doubt you will find any workarounds. It's better to create an [issue](https://github.com/DevExpress/testcafe/issues/new?assignees=&labels=&template=bug-report.md) in the TestCafe GitHub repository and share a simple example that reproduces this. – mlosev Sep 01 '21 at 08:14
0

The workaround we found for BC2 authentication was to utilize the testcafe hostname parameter and set this to localhost in the test config JSON. This enables testcafe's proxy to use localhost instead of the test client's IP address in the prefixed application URL.

We already had a B2C tenant app registration for localhost to support local development, and once we enabled this parameter, test scripts were able to login successfully using B2C as the identity and authentication provider.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77