DevExpress / testcafe

A Node.js tool to automate end-to-end web testing.
https://testcafe.io
MIT License
9.82k stars 672 forks source link

Recieved Error: Invalid cookie fields on passing Bearer token #8253

Closed Awatatah closed 1 month ago

Awatatah commented 2 months ago

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 commented 2 months ago

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

github-actions[bot] commented 2 months ago

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] commented 2 months ago

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.

Awatatah commented 2 months ago

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

Awatatah commented 2 months ago

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

Bayheck commented 2 months ago

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.

github-actions[bot] commented 1 month ago

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.