[Catalyst] Re: Catalyst::Test Plack and HTTP Auth

Alejandro Imass alejandro.imass at gmail.com
Thu May 24 20:47:16 GMT 2012


On Thu, May 24, 2012 at 2:02 PM, Alejandro Imass
<alejandro.imass at gmail.com> wrote:
> On Thu, May 24, 2012 at 1:53 PM, Alejandro Imass
> <alejandro.imass at gmail.com> wrote:
>> Hello,
>>
>> Is it possible to set the auth headers with the Plack stuff w/o having
>> to do the base64 and set headers manually?
>> I.e. something like with mech:
>>
>> $mech->credentials( $username, $password );
>>
>> But using the Catalyst::Test way...
>>
>
> Update: I think I found a way by using HTTP::Request object instead of
> the URI and then HTTP::Headers object inside that with the auth
> headers and that _should_ work. Will post follow-up here if it
> actually works.....
>
>

I can confirm it works perfectly! With Catalyst::Test you can do most
of the stuff you can do w/ a regular ua (plain lap, mech and even
mech::cat). Below is an example of how I got it working. In this
example I'm testing a JSON-only API so it should get 415 if
content-type and accept are not JSON:

# correct auth, wrong content-type test
$h = HTTP::Headers->new(
  'Content-Type' => 'text/html; charset=utf-8',
  'Accept' => 'text/html; charset=utf-8',
);
$h->authorization_basic('apiuser','user1234');
$req = HTTP::Request->new(
  POST => '/smsrstgw', $h
);
$ret = request($req);
ok($ret->code == 415);




>
>> Thanks!
>>
>> --
>> Alejandro Imass



More information about the Catalyst mailing list