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.

How to pass request headers using testcafe proxy for success response (getting 222)

See original GitHub issue

I am using TestCafe v1.8.7 in with testcafe-react-selector v3.3.0

I’m trying to login to server with my local code, while login request passes, and GraphQL request (with Apollo) passes as well, I can’t pass the registration to SignalR events on server side: I’m getting 222 response on this particular request, while on Wireshark the same request seems to get 200 response. I assume that it’s is only testcafe proxy issue. I also tried to use RequestHook but it didnt help.

NOTE: the request header contains the ORIGIN but the response doesn’t contains the Access-Control-Allow-Origin.

Request that succeeded (remote code is tested): http://172.16.20.205/VisionHubWebApi/signalr/negotiate?clientProtocol=1.5&sessionToken=dda5e074-0c4b-4d47-80bd-9411b4a0550e&connectionData=[{"name"%3A"notificationhub"}]

Request:

GET /VisionHubWebApi/signalr/negotiate?clientProtocol=1.5&sessionToken=dda5e074-0c4b-4d47-80bd-9411b4a0550e&connectionData=%5B%7B%22name%22%3A%22notificationhub%22%7D%5D HTTP/1.1
Host: 172.16.30.205
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36
content-type: application/x-www-form-urlencoded; charset=UTF-8
Accept: */*
**Origin: http://localhost:3000**
Referer: http://localhost:3000/VHConfigurator/login
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Response:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: application/json; charset=UTF-8
Expires: -1
Server: Microsoft-IIS/8.5
**Access-Control-Allow-Origin: http://localhost:3000**
Access-Control-Allow-Credentials: true
X-Content-Type-Options: nosniff
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sun, 28 Jun 2020 13:51:24 GMT

Failed request with the headers: http://172.16.20.109:64781/jy_913qpQ/http://172.16.20.205/VisionHubWebApi/signalr/negotiate?clientProtocol=1.5&sessionToken=81afc732-58c3-4213-b60f-cf25d0483b64&connectionData=[{"name"%3A"notificationhub"}]

Request:

GET /jy_913qpQ/http://172.16.20.205/VisionHubWebApi/signalr/negotiate?clientProtocol=1.5&sessionToken=81afc732-58c3-4213-b60f-cf25d0483b64&connectionData=%5B%7B%22name%22%3A%22notificationhub%22%7D%5D HTTP/1.1
Host: 172.16.32.109:64781
Connection: keep-alive
**x-hammerhead|xhr|origin: http://localhost:3000**
x-hammerhead|xhr|request-marker: true
x-hammerhead|xhr|with-credentials: true
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36
content-type: application/x-www-form-urlencoded; charset=UTF-8
Accept: */*
Referer: http://172.16.20.109:64781/jy_913qpQ/http://localhost:3000/VHConfigurator/login
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Response:

HTTP/1.1 222 unknown
content-type: text/html
Date: Sun, 28 Jun 2020 13:47:16 GMT
Connection: keep-alive
Transfer-Encoding: chunked

My test code:

import LoginPage from './PageModels/LoginPageModel.e2e';
import { ClientFunction ,RequestLogger ,RequestHook } from 'testcafe';
import { waitForReact } from 'testcafe-react-selectors';

const URL = `localhost:3000/VHConfigurator/login`;

class myRequestHook extends RequestHook {
    constructor () {
        super();
    }

    async onRequest (e) {
        e.requestOptions.headers['Access-Control-Allow-Origin'] = '*';  
    }

    async onResponse (e) {

    }
}

const customHook = new myRequestHook()

fixture (`Login to Pegasus`)
    .page (URL)
    .requestHooks( [customHook])
    .beforeEach(async () => {
        await waitForReact();
    });

test
.requestHooks([logger,customHook])
('Login with admin user, success', async t => {
    const getLocation = ClientFunction(() => document.location.href);

    await t
        .typeText(LoginPage.usernameInput,'user', { replace: true, paste: true })

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
aleks-procommented, Dec 21, 2020

Hello @shyedhu,

Thank you for the sample. On my side, the test fails on the navigate to checkout step. Possibly, it happens because of the internal TestCafe problem. I created a separate issue regarding this behavior: https://github.com/DevExpress/testcafe-hammerhead/issues/2514. Please refer to it to be informed about our progress.

1reaction
AlexKamaevcommented, Jul 10, 2020

@vbaprojectgit Thank you for your cooperation. I was able to reproduce the issue. You are correct, the cause of it is in the difference between “Origin” and “origin”. Please note that according to standards, headers are case-insensitive: https://developer.mozilla.org/en-US/docs/Glossary/HTTP_header. So, it’s not directly related to our product and I suggest you try to fix it on your side.

However, for better compatibility, I think we can consider improving this behavior in the future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Intercept HTTP Requests | Advanced Guides - TestCafe
This section describes how to handle HTTP requests in your tests. TestCafe ships with request hooks that allow you to log the requests...
Read more >
CORS issue with XMLHttpRequest AJAX call #1680 - GitHub
An AJAX call with XMLHttpRequest to another domain causes CORS issues and returns a 222 status with no response. We are using nock...
Read more >
testcafe/CHANGELOG.md - UNPKG
In the API, test and fixture metadata is now passed to the [runner.filter](https://devexpress.github.io/testcafe/documentation/using-testcafe/programming- ...
Read more >
How to resolve CORS issues with testcafe for file:// and https ...
I fixed the CORS issues (testcafe proxy was responding with the 222 code) with the file:// URLs by starting up the Http-server npm...
Read more >
testcafe - npmfs
Resources responding with `304` HTTP status code and with the 'content-length: ... testcafe chrome my-tests/**/*.js --proxy proxy.corp.mycompany.com ...
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