testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Recieved Error: Invalid cookie fields on passing Bearer token

Open Awatatah opened this issue 1 year ago • 5 comments

What is your Scenario?

API test call with Authorization Bearer token header causes an error.

What is the Current behavior?

Getting the following errors when the test runs:

 ✖ Get Profile

   1) Error: Invalid cookie fields

      Browser: Chrome 127.0.0.0 / Ubuntu 22.04

         89 |                    if (error) {
         90 |                        const request = {method, params, sessionId};
         91 |                        reject(
         92 |                            error instanceof Error
         93 |                                ? error // low-level WebSocket error
       > 94 |                                : new ProtocolError(request, response)
         95 |                        );
         96 |                    } else {
         97 |                        fulfill(response);
         98 |                    }
         99 |                });

         at <anonymous> (/root/repos/XXXXXXXXX/node_modules/chrome-remote-interface/lib/chrome.js:94:35)
         at Chrome._handleMessage (/root/repos/XXXXXXXXX/node_modules/chrome-remote-interface/lib/chrome.js:272:17)
         at WebSocket.<anonymous> (/root/repos/XXXXXXXXX/node_modules/chrome-remote-interface/lib/chrome.js:240:22)
         at Receiver.receiverOnMessage (/root/repos/XXXXXXXXX/node_modules/ws/lib/websocket.js:1070:20)
         at Receiver.dataMessage (/root/repos/XXXXXXXXX/node_modules/ws/lib/receiver.js:517:14)

What is the Expected behavior?

To not receive error :)

What is the public URL of the test page? (attach your complete example)

N/A

What is your TestCafe test code?

fixture`Profile Login Test`;

let token = "";

test("Test Login", async (t) => {
  const results = await t.request({
    url: `${process.env.MY_AUTH_URL}/some/login`,
    method: "post",
    body: {
      email: process.env.MY_USERNAME,
      password: process.env.MYPASSWORD,
    },
  });

  await t
    .expect(results.status)
    .eql(200)
    .expect(results.headers)
    .contains({ "content-type": "application/json;charset=UTF-8" })
    .expect(results.body.accessToken)
    .ok();

  token = results.body.accessToken;
});

test("Get Profile", async (t) => {
  const results = await t.request({
    url: `${process.env.MY_AUTH_URL}/some/profile`,
    method: "get",
    headers: {
      Authorization: `Bearer ${token}`,
    },
  });

  await t
    .expect(results.status)
    .eql(200)
    .expect(results.headers)
    .contains({ "content-type": "application/json" })
    .expect(results.body.id)
    .ok();
});

Your complete configuration file

N/A

Your complete test report

N/A

Screenshots

N/A

Steps to Reproduce

Create a test with the mentioned code and run it

TestCafe version

3.x.x

Node.js version

22.1.0

Command-line arguments

testcafe 'chromium:headless --no-sandbox' main.js

Browser name(s) and version(s)

Chromium 127.0.6533.88 snap

Platform(s) and version(s)

Ubuntu 22.04

Other

This is a initial setup. There are no other tests.

Awatatah avatar Aug 12 '24 22:08 Awatatah

Additionally, I went back to version 2.6.2 and it works fine. I tested every minor release of version 3 and the error is present

Awatatah avatar Aug 13 '24 21:08 Awatatah

Thank you for submitting a bug report. We would love to help you investigate the issue. Please share a simple code example that reliably reproduces the bug. For more information, read the following article: How To Create a Minimal Working Example When You Submit an Issue. We look forward to your response.

github-actions[bot] avatar Aug 16 '24 06:08 github-actions[bot]

This issue was automatically closed because there was no response to our request for more information from the original author. Currently, we don't have enough information to take action. Please reach out to us if you find the necessary information and are able to share it. We are also eager to know if you resolved the issue on your own and can share your findings with everyone.

github-actions[bot] avatar Aug 26 '24 07:08 github-actions[bot]

Why was this closed? What sample did you need? @PavelMor25

Awatatah avatar Aug 26 '24 23:08 Awatatah

The issue is pretty straight forward based on the information I provided. spin up a basic bearer token auth API, and create a test that adds the authorization bearer token headers. When the tests runs, it will produce the Error: Invalid cookie fields error.

I had to revert to testcafe version 2.6.2 in order to get around the error. All 3.x versions produce this error

Awatatah avatar Aug 26 '24 23:08 Awatatah

Hello,

Please share a simple and reliable example, preferably in the form of a repository.

The repository should contain all the information and files necessary to reproduce the issue. Any user should be able to follow your instructions. Something like this: image

See: How to create a Minimal Working Example when you submit an issue.

Bayheck avatar Aug 30 '24 10:08 Bayheck

This issue was automatically closed because there was no response to our request for more information from the original author. Currently, we don't have enough information to take action. Please reach out to us if you find the necessary information and are able to share it. We are also eager to know if you resolved the issue on your own and can share your findings with everyone.

github-actions[bot] avatar Sep 09 '24 10:09 github-actions[bot]