Referer header is getting dropped for API calls.
What is your Test Scenario?
The site that I'm testing makes API calls to a third party that are returning a 403 in the latest version, but works in version 1.9.4. It turns out that the APIs are looking for the presence of a referer in the request header to be considered valid. This is keeping me from upgrading.
What is the Current behavior?
The referer header is missing after version 1.10.1, including 1.14.2. In my research, it appears that the referer header does not look like the hammerhead proxy url, it's the normal url, before it gets transformed by hammerhead. This is only happening for API urls. When it attempts to transform it, it gets dropped instead.
What is the Expected behavior?
Refer header should be present.
What is your web application and your TestCafe test code?
Your website URL (or attach your complete example):
Your complete test code (or attach your test files):
<script>
// index.html
function reqListener () {
console.log(this.responseText);
}
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("GET", "https://testcafe.io/");
oReq.send();
</script>
import { RequestLogger } from 'testcafe';
const logger = RequestLogger('https://testcafe.io', {
logRequestHeaders: true
});
fixture `When making an xhr request:`
.page('http://localhost:8080/index.html')
.requestHooks(logger);
test('The origin header is present.', async t => {
await t
.expect(logger.contains(r => r.request.headers.hasOwnProperty('origin'))).ok();
});
test('The referer header is present.', async t => {
await t
.expect(logger.contains(r => r.request.headers.hasOwnProperty('referer'))).ok();
});
Your complete configuration file (if any):
Your complete test report:
Running tests in:
- Chrome 91.0.4472.77 / Windows 10
When making an xhr request:
√ The origin header is present.
× The referer header is present.
1) AssertionError: expected false to be truthy
+ expected - actual
-false
+undefined
Browser: Chrome 91.0.4472.77 / Windows 10
13 | .expect(logger.contains(r => r.request.headers.hasOwnProperty('origin'))).ok();
14 |});
15 |
16 |test('The referer header is present.', async t => {
17 | await t
> 18 | .expect(logger.contains(r =>
r.request.headers.hasOwnProperty('referer'))).ok();
19 |});
at <anonymous> (D:\Projects\xxx\scripts\node\testcafe-bug\tests\referer.js:18:84)
at asyncGeneratorStep
(D:\Projects\xxx\scripts\node\testcafe-bug\tests\referer.js:1:250)
at _next (D:\Projects\xxx\scripts\node\testcafe-bug\tests\referer.js:1:588)
at <anonymous> (D:\Projects\xxx\scripts\node\testcafe-bug\tests\referer.js:1:753)
at <anonymous> (D:\Projects\xxx\scripts\node\testcafe-bug\tests\referer.js:1:494)
at <anonymous> (D:\Projects\xxx\scripts\node\testcafe-bug\tests\referer.js:16:5)
1/2 failed (15s)
Screenshots:
Steps to Reproduce:
- Go to my website ...
- Execute this command...
- See the error...
Your Environment details:
- testcafe version: 1.14.2
- node.js version: v12.18.4
- command-line arguments: npx testcafe chrome:headless
- browser name and version: Chrome 91
- platform and version: Windows 10
- other:
Hi @p0rt23
Thank you for the shared example. I've reproduced the issue.
@miherlosev We're experiencing the same bug and it prevents us from updating to versions of Testcafe after 1.10.1
Hello,
Thank you for pointing this out. We need more time to investigate the issue. We'll get back to you when we have any results.
We're experiencing this same issue, using 1.14.2.
I am not 100% if this Github issue is causing instabilities and fails, but we had to downgrade TestCafe too because every e2e run had couple failed tests and couple unstable ones.
Screenshot showing BEFORE as latest TestCafe e2e test runs, and AFTER where we have downgraded TestCafe:
Nothing helpful in logs, so we assume TestCafe proxy is faulty and something is improperly altering requests.
Here someone debugged some issues all the way to http lib (https://stackoverflow.com/a/59548457/7937721). But even if it's http lib it makes TestCafe completely unstable and unpredictable. If this is the issue, maybe you should consider using different lib.
@AlexanderMoiseev Do you have any updates on this?
No updates yet. Once we get any results, we will post them in this thread.
+1