testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Referer header is getting dropped for API calls.

Open p0rt23 opened this issue 5 years ago • 9 comments

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:

  1. Go to my website ...
  2. Execute this command...
  3. 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:

p0rt23 avatar Jun 09 '21 17:06 p0rt23

Hi @p0rt23

Thank you for the shared example. I've reproduced the issue.

miherlosev avatar Jun 14 '21 07:06 miherlosev

@miherlosev We're experiencing the same bug and it prevents us from updating to versions of Testcafe after 1.10.1

florianeckerstorfer avatar Jul 26 '21 07:07 florianeckerstorfer

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.

AlexanderMoiseev avatar Jul 27 '21 08:07 AlexanderMoiseev

We're experiencing this same issue, using 1.14.2.

kacy-weakley avatar Aug 13 '21 14:08 kacy-weakley

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:

CleanShot 2021-09-22 at 17 25 15@2x

Nothing helpful in logs, so we assume TestCafe proxy is faulty and something is improperly altering requests.

Evilweed avatar Sep 22 '21 15:09 Evilweed

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.

Evilweed avatar Sep 22 '21 15:09 Evilweed

@AlexanderMoiseev Do you have any updates on this?

ani-im avatar Feb 01 '22 17:02 ani-im

No updates yet. Once we get any results, we will post them in this thread.

github-actions[bot] avatar Feb 02 '22 03:02 github-actions[bot]

+1

hex0cter avatar Mar 08 '22 20:03 hex0cter