Testing and cookies #500

Closed
szabgab opened this Issue Oct 30, 2013 · 1 comment

Projects

None yet

3 participants

@szabgab

If this isn't a bug then I think it would be nice to add to the documentation of Dancer2::Test

When testing an application that has session management and want to make sure the cookie received from the server is sent back then setting it via the header

my $r2 = dancer_response GET => "/", {
headers => [
[ 'Cookie' => $cookie ],
],
};

does NOT have the desired effect, but setting an environment variable does:

This call sets up the session:

my $r1 = dancer_response GET => "/set";

We extract the cookie from the header:

my ($cookie) = $r1->header('set-cookie') =~ /(dancer.session=[^;]+);/;

Then we set the cookie and the in the subsequent requests the server will see the cookie:

$ENV{HTTP_COOKIE} = $cookie;
my $r2 = dancer_response GET => "/";

@veryrusty veryrusty added the Bug label Feb 13, 2014
@veryrusty veryrusty self-assigned this Feb 13, 2014
@veryrusty veryrusty added a commit that referenced this issue Feb 13, 2014
@veryrusty veryrusty Add tests for including an arrayref of headers to dancer_response
Ensuring there are tests to match the documentation. Note that extra
cookie headers are currently not being included in the request object cookies
hash. Ref #500.
b0e5d9e
@veryrusty veryrusty added a commit that referenced this issue Feb 13, 2014
@veryrusty veryrusty Build request cookie objects from request->headers, rather than reque…
…st->env.

As the request object is built, headers from the env are added to the headers
object, however cookies were still being populated from the env. However, when
testing you may need to pass in extra headers in the request. Dancer2::Test
allows for this, updating the headers in the request, but any extra cookies
were only accessible via request->header, not request->cookies.

Building the cookie objects from request->headers resolves this and closes #500.
bc42434
@veryrusty veryrusty added a commit that referenced this issue Apr 24, 2014
@veryrusty veryrusty Add tests for including an arrayref of headers to dancer_response
Ensuring there are tests to match the documentation. Note that extra
cookie headers are currently not being included in the request object cookies
hash. Ref #500.
22f3968
@veryrusty veryrusty added a commit that closed this issue Apr 24, 2014
@veryrusty veryrusty Build request cookie objects from request->headers, rather than reque…
…st->env.

As the request object is built, headers from the env are added to the headers
object, however cookies were still being populated from the env. However, when
testing you may need to pass in extra headers in the request. Dancer2::Test
allows for this, updating the headers in the request, but any extra cookies
were only accessible via request->header, not request->cookies.

Building the cookie objects from request->headers resolves this and closes #500.
4859409
@veryrusty veryrusty closed this in 4859409 Apr 24, 2014
@xsawyerx
PerlDancer member

Took some time, but hey, we got there! :)
+1 @szabgab @veryrusty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment