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@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@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.