[dancer-users] Digest Authentication and Plack::Test and get the user in Dancer2

Arjan Widlak arjan at unitedknowledge.nl
Thu Sep 3 18:51:38 BST 2015


Hi,

Is it possible to test Digest Authentication with Plack::Test without 
starting a live server?

With a live server I can do this:

|    my $browser = LWP::UserAgent->new();||
||    $req = HTTP::Request->new( GET => 'http://localhost:5000/' );||
||    $browser->credentials(||
||        "localhost:5000",||
||        "ZZZZZZ",||
||        'arjan at xxxxxx.nl' => 'xxxxxx'||
||    );||||
||    $res = $browser->request( $req );||
||    ok( $res->status_line eq '200 OK', 'success with login with 
credentials' );|

And in my Dancer2 app I get:

|get '/' => sub {||
||    my $dsl     = shift;||
||    my $user    = $dsl->app->request->user;|

Is it possible to do something like:

my $test = Plack::Test->create($app);

|my $req = GET '/mYtQ2EeQthcclMhsqDZTbVcggwX9kJDo';||
||$req->header( "Accept"           => "application/json" );||
||$req->header( "Host"             => "localhost" );||
||$req->header( "Authorization"    => 'Digest username="arjan at xxxxxx.nl",||
||                                     realm="ZZZZZZ",||
||nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",||
||                                     uri="/",||
||                                     qop=auth,||
||                                     nc=00000001,||
||                                     cnonce="0a4f113b",||
||response="6629fae49393a05397450978507c4ef1",||
||opaque="5ccc069c403ebaf9f0171e9517f40e41"');||
||my $res = $test->request( $req );|

And get the user in Dancer2 in the same way:

|get '/' => sub {||
||    my $dsl     = shift;||
||    my $user    = $dsl->app->request->user;|

Where does Dancer2 get the user that is returned with 
$dsl->app->request->user? I had a hard time finding this in 
Dancer2::Core::Request.pm, where it's in the documentation.

Kind regards,
Arjan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150903/034f95f0/attachment.html>


More information about the dancer-users mailing list