diff options
author | dakkar <dakkar@thenautilus.net> | 2014-12-28 15:27:10 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2014-12-28 15:27:10 +0000 |
commit | 97d5faa0284703546d63b7c1fe78d0ec0227bc05 (patch) | |
tree | e4ed3bfd7a88ce1a5d4b1a74643c6613051a89ea /t | |
parent | more tests & fixes (diff) | |
download | net-hawk-97d5faa0284703546d63b7c1fe78d0ec0227bc05.tar.gz net-hawk-97d5faa0284703546d63b7c1fe78d0ec0227bc05.tar.bz2 net-hawk-97d5faa0284703546d63b7c1fe78d0ec0227bc05.zip |
crypto partially ported to p6
Diffstat (limited to 't')
-rw-r--r-- | t/tests/Net/Hawk/Crypto.t | 92 |
1 files changed, 43 insertions, 49 deletions
diff --git a/t/tests/Net/Hawk/Crypto.t b/t/tests/Net/Hawk/Crypto.t index 7ae6f7e..3ce0e5e 100644 --- a/t/tests/Net/Hawk/Crypto.t +++ b/t/tests/Net/Hawk/Crypto.t @@ -1,36 +1,33 @@ #!perl -use strict; -use warnings; -use Test::More; +use v6; +use Test; +use URI; use Net::Hawk::Crypto; -my $c = Net::Hawk::Crypto->new(); - -subtest readme => sub { +subtest { my %credentials = ( id => 'dh37fgj492je', key => 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', algorithm => 'sha256', ); my %options = ( - credentials => \%credentials, + credentials => %credentials, timestamp => 1353832234, nonce => 'j4h3g2', ext => 'some-app-ext-data' ); - subtest GET => sub { - my $string = $c->generate_normalized_string( - header => { - credentials => \%credentials, - ts => $options{timestamp}, - nonce => $options{nonce}, - method => 'GET', - resource => '/resource?a=1&b=2', - host => 'example.com', - port => 8000, - ext => $options{ext}, - } + subtest { + my $string = generate_normalized_string( + type => 'header', + credentials => %credentials, + ts => %options<timestamp>, + nonce => %options<nonce>, + method => 'GET', + resource => URI.new('/resource?a=1&b=2'), + host => 'example.com', + port => 8000, + ext => %options<ext>, ); is( @@ -40,28 +37,27 @@ subtest readme => sub { ); }; - subtest POST => sub { + subtest { my $payload = 'Thank you for flying Hawk'; my $content_type = 'text/plain'; - my $payload_hash = $c->calculate_payload_hash( + my $payload_hash = calculate_payload_hash( $payload, - $credentials{algorithm}, + %credentials<algorithm>, $content_type, ); - my $string = $c->generate_normalized_string( - header => { - credentials => \%credentials, - ts => $options{timestamp}, - nonce => $options{nonce}, - method => 'POST', - resource => '/resource?a=1&b=2', - host => 'example.com', - port => 8000, - hash => $payload_hash, - ext => $options{ext}, - } + my $string = generate_normalized_string( + type => 'header', + credentials => %credentials, + ts => %options<timestamp>, + nonce => %options<nonce>, + method => 'POST', + resource => '/resource?a=1&b=2', + host => 'example.com', + port => 8000, + hash => $payload_hash, + ext => %options<ext>, ); is( @@ -72,7 +68,7 @@ subtest readme => sub { }; }; -subtest normalized_string => sub { +subtest { my %args = ( credentials => { key => 'dasdfasdf', @@ -85,8 +81,8 @@ subtest normalized_string => sub { host => 'example.com', port =>8080 ); - my $string = $c->generate_normalized_string( - header => \%args, + my $string = generate_normalized_string( + type=>'header',|%args, ); is( $string, @@ -94,11 +90,10 @@ subtest normalized_string => sub { 'valid normalized string', ); - $string = $c->generate_normalized_string( - header => { - %args, - ext => 'this is some app data', - }, + $string = generate_normalized_string( + type=>'header', + |%args, + ext => 'this is some app data', ); is( $string, @@ -106,12 +101,11 @@ subtest normalized_string => sub { 'valid normalized string (ext)', ); - $string = $c->generate_normalized_string( - header => { - %args, - ext => 'this is some app data', - hash => 'U4MKKSmiVxk37JCCrAVIjV/OhB3y+NdwoCr6RShbVkE=', - }, + $string = generate_normalized_string( + type=>'header', + |%args, + ext => 'this is some app data', + hash => 'U4MKKSmiVxk37JCCrAVIjV/OhB3y+NdwoCr6RShbVkE=', ); is( $string, @@ -120,4 +114,4 @@ subtest normalized_string => sub { ); }; -done_testing; +done; |