question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Testcafe doesn't use the headers as the original request

See original GitHub issue

What is your Scenario?

I am running testcafe tests on an authentication page and I can see that testcafe is modifying/removing/adding the headers when sending the requests to the website and this is blocking me to do 2FA on this page

As soon as I got the issue, I tried to do the automation with Selenium just to confirm it is testcafe issue. As selenium doesn’t create proxy to insert the js scripts and automate the website I could do the automation with selenium, but I want to use testcafe as the site is developed in react.

When clicking on the next button I should have the 2FA form asking for the code, but I got a page saying was not possible to do the authentication (Something wrong happened) and I saw the response code for the BeginAuth endpoint was 222 without any response instead of 200.

What is the Current behavior?

testcafe sends the request (I add a _ before the headers missing from testcafe, I remove the tokens and ids and change to variables in bold):

POST https://login.microsoftonline.com/common/SAS/BeginAuth HTTP/1.1
Host: 192.168.0.12:50047
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:67.0) Gecko/20100101 Firefox/67.0
Accept: application/json
Accept-Language: en-US,en;q=0.5
Referer: https://login.microsoftonline.com:443/common/DeviceAuthTls/reprocess
hpgid: id
hpgact: id
canary: canary
client-request-id: id
hpgrequestid: id
Content-type: application/json; charset=utf-8
_x-hammerhead|xhr|request-marker: true_
_x-hammerhead|xhr|origin: https://login.microsoftonline.com_
Connection: keep-alive
cache-control: no-cache

{"AuthMethodId":"PhoneAppOTP","Method":"BeginAuth","ctx":"ctx","flowToken":"token"}

the response code from the testcafe request is 222 unknown and the response body is empty

Screenshot 2019-06-18 at 12 37 54

What is the Expected behavior?

the original request should be something similar like (I add a _ before the headers missing from testcafe, I remove the tokens and ids and change to variables in bold):

POST /common/SAS/BeginAuth HTTP/1.1
Host: login.microsoftonline.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:67.0) Gecko/20100101 Firefox/67.0
Accept: application/json
Accept-Language: en-US,en;q=0.5
hpgid: id
hpgact: id
canary: canary
client-request-id: id
hpgrequestid: id
Content-type: application/json; charset=utf-8
_DNT: 1_
Connection: keep-alive
Referer: https://login.microsoftonline.com/common/DeviceAuthTls/reprocess
_Cookie: buid=build; x-ms-gateway-slice=prod; stsservicecookie=ests; MSCC=mscc; wlidperf=FR=L&ST=st; ESTSAUTHPERSISTENT=token; ESTSAUTHLIGHT=id; ESTSSC=00_
cache-control: no-cache

{"AuthMethodId":"PhoneAppOTP","Method":"BeginAuth","ctx":"ctx","flowToken":"token"}

the response code from the original request is 200 and the response body is (I remove the tokens and ids and change to variables in bold):

{"Success":true,"ResultValue":"Success","Message":null,"AuthMethodId":"PhoneAppOTP","ErrCode":0,"Retry":false,"FlowToken":"**token**","Ctx":"**ctx**","SessionId":"**id**","CorrelationId":"**id**","Timestamp":"2019-06-18T09:43:24Z"}

test

What is your public web site URL?

I removed the ids from the url https://login.microsoftonline.com/client_uuid/oauth2/authorize?response_type=code id_token&response_mode=form_post&client_id=client_uuid&scope=openid&x-client-Ver=4.0.0

Your complete app code (or attach your test files):

these are the functions for the test

        await t.typeText(this.emailInput, config.userEmail)
               .click(this.nextButton)
               .typeText(this.passwordInput, config.userPassword)
               .click(this.nextButton)
               .click(this.otpOption)
               .typeText(this.otpInput, this.token)
               .click(this.signinButton)
       }

Steps to Reproduce:

  • go to the url that redirects to the login page

  • testcafe types user

  • click next

  • testcafe types password

  • click next

  • the screen should return with a 2fa code input available

  • When I edit and resend the request I am able to get 200 and the response body, but I need to remove the headers: x-hammerhead|xhr|request-marker: true x-hammerhead|xhr|origin: https://login.microsoftonline.com

and add the origin one: Origin: https://login.microsoftonline.com

Your Environment details:

  • node.js version: 12.1.0
  • browser name and version: Firefox Quantum 67.0.2 (64-bit)
  • platform and version: Macos Mojave 10.14.4 (18E227)
  • other: testcafe ^1.2.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rafaelaazevedocommented, Jul 10, 2019

Thanks guys @LavrovArtem and @miherlosev

1reaction
LavrovArtemcommented, Jun 25, 2019

I’ve reproduced this issue on Mac Os in Firefox, but it does not occur on Windows. We will research it and inform you about the results.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RequestHooks didn't works - not executed at all to add request ...
RequestHook is not applied (or onRequest & onResponse are not executed). I added few console.log(...) s to my hook class to see if...
Read more >
Custom Request Headers within TestCafe are not displayed
TestCafe's RequestLogger logs only original request headers, but not the modified ones. However, this line of code definitely works.
Read more >
API Testing | Intermediate Guides | Guides | Docs - TestCafe
API tests send HTTP requests to the server and compare the server's responses to the expected outcome. Use the request method to send...
Read more >
It's impossible to record a test for a web application that sends ...
When testing the app in Test Cafe, I am getting 'HTTP 431 Request Header Fields Too Large' responses. I think Test Cafe uses...
Read more >
Testing APIs With Ease Using TestCafe - Dev Tester
Let's begin creating our first API test using TestCafe. ... by the Content-Type header returned by the API request), TestCafe automatically ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found