From 3294492369e6801b79eaf4ac36310ab6dde9a654 Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 30 Dec 2014 11:57:48 +0000 Subject: start of uri tests the implementation is a stub! --- lib/Net/Hawk/Client.pm | 10 ++++++++++ lib/Net/Hawk/Server.pm | 18 ++++++++++++++++++ lib/Net/Hawk/Uri.pm | 7 +++++++ t/tests/Net/Hawk/Uri.t | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 lib/Net/Hawk/Server.pm create mode 100644 lib/Net/Hawk/Uri.pm create mode 100644 t/tests/Net/Hawk/Uri.t diff --git a/lib/Net/Hawk/Client.pm b/lib/Net/Hawk/Client.pm index 5f649c4..fd28532 100644 --- a/lib/Net/Hawk/Client.pm +++ b/lib/Net/Hawk/Client.pm @@ -145,4 +145,14 @@ package Net::Hawk::Client { return $calculated_hash eq $attributes; }; + our proto getBewit(*@,*%) {*}; + multi getBewit(Str:D $uri!,*%nam) { + return getBewit(URI.new($uri),|%nam); + }; + multi getBewit( + URI:D $uri!, + :%credentials!, + Int:D :$ttl_sec!, + Str :$ext, + ) { return "$ext" }; } diff --git a/lib/Net/Hawk/Server.pm b/lib/Net/Hawk/Server.pm new file mode 100644 index 0000000..1b39352 --- /dev/null +++ b/lib/Net/Hawk/Server.pm @@ -0,0 +1,18 @@ +package Net::Hawk::Server { + use v6; + + our sub authenticate( + %request!, + &credentialsFunc:($,&)!, + %whatever!, + &callback:($,%,%)!, + ) { + my %creds; + &credentialsFunc.('some id', sub ($err,%credentials) { %creds = %credentials }); + %request ~~ m{'bewit=' $=(.*?) ['&'|$]}; + my %attributes = ( + ext => $/; + ); + &callback.(Nil,%creds,%attributes); + }; +}; diff --git a/lib/Net/Hawk/Uri.pm b/lib/Net/Hawk/Uri.pm new file mode 100644 index 0000000..544afd9 --- /dev/null +++ b/lib/Net/Hawk/Uri.pm @@ -0,0 +1,7 @@ +package Net::Hawk::Uri { + use v6; + use Net::Hawk::Client; + use Net::Hawk::Server; + our constant &getBewit := &Net::Hawk::Client::getBewit; + our constant &authenticate := &Net::Hawk::Server::authenticate; +} diff --git a/t/tests/Net/Hawk/Uri.t b/t/tests/Net/Hawk/Uri.t new file mode 100644 index 0000000..769eb98 --- /dev/null +++ b/t/tests/Net/Hawk/Uri.t @@ -0,0 +1,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 ~= "\&bewit=$bewit"; + + Net::Hawk::Uri::authenticate( + %req, + &credentialsFunc, + {}, + sub ($err, %credentials, %attributes) { + ok(!$err,"no error"); + is(%credentials,'steve','correct user'); + is(%attributes,'some-app-data','ext passed on'); + }, + ); + }); +}; + +done; -- cgit v1.2.3