Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Cookies are emptied between requests. #271

Open
brice opened this issue Feb 6, 2019 · 5 comments
Open

Cookies are emptied between requests. #271

brice opened this issue Feb 6, 2019 · 5 comments

Comments

@brice
Copy link

brice commented Feb 6, 2019

Hello to all,

Recently we upgraded behatch contexts from 2.5 version to 2.8.1 with several upgrade and i encounter a problem with my API's tests.

So basically i send a request to a page that connect an user then

  Scenario: Simple scenario that 
    Given I am connected as user
    When I send a "GET" request to "/rest/user"
    Then the response status code should be 200
    When I send a "GET" request to "/rest/user"
    Then the response status code should be 200

Before the update this code use to work, after it the last context return this message :

Current response status code is 403, but 200 expected. (Behat\Mink\Exception\ExpectationException)

The function related to the context I am connected as user extends RawMinkContext and simply set a session ID in cookies.

    public function iAmConnectedAs($login)
    {
        $loginUrl = $this->locatePath('/login.php');
        $this->getSession()->setCookie('PHPSESSID', uniqid());
        $this->request('POST', $loginUrl, ['login' => $login, 'passwd' => $login]);
    }

During a debug session i saw that Cookies are emptied between sessions. So that explains the 403 response but why cookies are emptied? Did anyone encountered this after an update? Let me know if i have something to add.

I also write a question on StackOverflow

@Linkinou
Copy link

Linkinou commented Aug 5, 2019

Hi @brice

I'm pretty sure I'm facing the same issue, did you find a solution ?

Everytime the first request is working but then the others fail with that error :
The string '' is not valid json (Exception)

If I remove the first request then the 2nd one works...etc

[EDIT]

Ok it seems to come from the resetHeaders happening between each step.
Kind of complicating things

@brice
Copy link
Author

brice commented Aug 5, 2019

Did you achieve to resolve it?

@Linkinou
Copy link

Linkinou commented Aug 7, 2019

Not yet but still working on it.
It might be something particular to my case : My firewall denies access to the API (because no more header) and send a 401 back. Then behatch (or something else) receives this 401 and considered it invalid because there's no content.

That's why I'm having this weird message : The string '' is not valid json (Exception)

@kelleyc
Copy link

kelleyc commented Dec 2, 2020

I'm running into the same issue. I'm trying to login in the first step and use cookies in the response in subsequent steps within the same scenario, but due to resetHttpHeaders all cookies are cleared between requests.

It looks like this was introduced in #163, but shouldn't that have happened between scenarios instead of after every request? Is it intentional that we should never be able to share cookies between steps in the same scenario?

@gnutix
Copy link

gnutix commented Apr 15, 2021

We are having the same issue. @vincentchalamon @sanpii any chance you might be able to help, as you both worked on #164 ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants