aboutsummaryrefslogtreecommitdiff
path: root/t/tests/Net/Hawk/Uri.t
blob: d63954c7ddc5e5d7b47c8987b0a4cf86580c0212 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!perl6 
use v6;
use Test;
use Net::Hawk::Uri;
 
subtest {
    my sub credentialsFunc($id,&callback{
        &callback.(Nil,{
          id => $id,
          key => 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',
          algorithm => 'sha256',
          user => 'steve',
        });
    };
 
    my %req = (
        method => 'GET',
        url => '/resource/4?a=1&b=2',
        host => 'example.com',
        port => 80,
    );
 
    credentialsFunc('123456'sub ($err%credentials{
        my $bewit = Net::Hawk::Uri::getBewit(
            'http://example.com/resource/4?a=1&b=2',
            credentials => %credentials,
            ttl_sec => 60 * 60 * 24 * 365 * 100,
            ext => 'some-app-data',
        );
        %req<url> ~= "\&bewit=$bewit";
 
        Net::Hawk::Uri::authenticate(
            %req,
            &credentialsFunc,
            {},
            sub ($err%credentials%attributes{
                ok(!$err,"no error");
                is(%credentials<user>,'steve','correct user');
                is(%attributes<ext>,'some-app-data','ext passed on');
            },
        );
    });
}'generate a bewit then successfully authenticate it';
 
done;