How to pass request headers using testcafe proxy for success response (getting 222)
See original GitHub issueI 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:
- Created 3 years ago
- Comments:11 (4 by maintainers)
Top GitHub Comments
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.@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.