adonisjs / http-server

AdonisJS HTTP Server along with its Router
https://docs.adonisjs.com/guides/http
MIT License
113 stars 30 forks source link

testing HTTP request withPlainCookie() always encodes the cookie #87

Open jared-f opened 4 months ago

jared-f commented 4 months ago

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

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

RomainLanz commented 21 hours ago

Hey @jared-f! šŸ‘‹šŸ»

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