http-server icon indicating copy to clipboard operation
http-server copied to clipboard

testing HTTP request withPlainCookie() always encodes the cookie

Open jared-f opened this issue 1 year ago • 1 comments

Package version

7.2.3

Describe the bug

I am trying to make an API Client test using HTTP client that has a simple plain cookie set.

When I try sending a request using withPlainCookie I can see in the route under test that the cookie is base64 encoded json string of my plain cookie value set in the test.

I would like to be able to disable the encoding on that cookie so that in the route handler I can access ctx.request.plainCookie('sauce', { encoded: false }) and retrieve the value.

Below are some example code:

// test

 test('It creates a taco', async ({ client, assert }) => {
    const companyName = 'Acme Inc'
    const response = await client
      .post('/tacos')
      .withPlainCookie('sauce','spicy')
      .form({ toppings: [ 'cilantro'] })
      .withCsrfToken()
    response.assertStatus(200)
    const taco = await Taco.findBy({ toppings: 'cilantro' })
    assert.ok(taco, 'It should make a tacos')
  })

In the route when I inspect ctx.request.plainCookie('sauce') I have a string like this: eyJtZXNzYWdlIjogInNwaWN5In0=

which is a json object like this:

{ "message": "spicy"}

and should be a simply spicy.

Thanks

Reproduction repo

No response

jared-f avatar Jul 09 '24 19:07 jared-f

created from https://github.com/orgs/adonisjs/discussions/4649

jared-f avatar Jul 09 '24 19:07 jared-f

Hey @jared-f! 👋🏻

Would you mind creating a PR with a failing test to help illustrate the issue?

RomainLanz avatar Nov 26 '24 08:11 RomainLanz

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 26 '25 01:04 stale[bot]