[dancer-users] How to send back cookies in Dancer2 Tests?
Gabor Szabo
gabor at szabgab.com
Wed Oct 30 15:07:26 GMT 2013
Hmm,
I have this problem during testing, no server is launched.
In config.yml I have
session: YAML
and I saw a file called UnD4WqseotQvyKMGxpoVXSUYRASXQ0TA.yml
in the sessions/ directory. So I think the session should have been
accessible even if I hit a different server process.
(I even added now a test case checking if the file exists before I send the
second request, and it does.)
after running dancer2 -a Test
and having these files: https://gist.github.com/szabgab/7234175
would be a minimal case.
Gabor
On Wed, Oct 30, 2013 at 3:23 PM, Andrew Solomon <andrew at illywhacker.net> wrote:
> If you're using "simple" sessions, you need to make sure you've only got one
> process since the cookies aren't shared between processes. That is, you
> probably got the cookie with one process and served the second request with
> another.
>
> With the example in this tutorial, change the starman script to set the
> --workers to 1
>
> http://perlmaven.com/getting-started-with-perl-dancer-on-digital-ocean
>
> cheers
>
> Andrew
>
>
> On Wed, Oct 30, 2013 at 12:23 PM, Gabor Szabo <gabor at szabgab.com> wrote:
>>
>> Hi there,
>>
>> While testing an application I write in Dancer2 I was trying to
>> test the login mechanism. For this I need to send back the cookie
>> I received from the server. I have code like this:
>>
>>
>> my $r2 = dancer_response POST => '/login',
>> params => {
>> username => $users{username},
>> password => $users{password},
>> },
>> };
>>
>> my ($cookie) = $r2->header('set-cookie') =~ /(dancer.session=[^;]+);/;
>> diag $cookie; # dancer.session=UnD4WqseotQvyKMGxpoVXSUYRASXQ0TA
>>
>>
>> my $r3 = dancer_response GET => '/', {
>> headers => [
>> [ 'Cookie' => $cookie ],
>> ],
>> };
>>
>>
>> But the server responds to the second query as if the cookie
>> was not received by it.
>> The same works when using a regular browser.
>>
>> What am I doing wrong?
>> What do I need to do in order for the session cookie to be sent back?
>>
>> regards
>> Gabor
More information about the dancer-users
mailing list