aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2014-12-30 11:57:48 +0000
committerdakkar <dakkar@thenautilus.net>2014-12-30 11:57:48 +0000
commit3294492369e6801b79eaf4ac36310ab6dde9a654 (patch)
tree83aff05ed940c9e6ac9720dd43bbca8f45d1d363
parentwhitespace fixes (diff)
downloadnet-hawk-3294492369e6801b79eaf4ac36310ab6dde9a654.tar.gz
net-hawk-3294492369e6801b79eaf4ac36310ab6dde9a654.tar.bz2
net-hawk-3294492369e6801b79eaf4ac36310ab6dde9a654.zip
start of uri tests
the implementation is a stub!
-rw-r--r--lib/Net/Hawk/Client.pm10
-rw-r--r--lib/Net/Hawk/Server.pm18
-rw-r--r--lib/Net/Hawk/Uri.pm7
-rw-r--r--t/tests/Net/Hawk/Uri.t45
4 files changed, 80 insertions, 0 deletions
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<hash>;
};
+ 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<url> ~~ m{'bewit=' $<ext>=(.*?) ['&'|$]};
+ my %attributes = (
+ ext => $/<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<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');
+ },
+ );
+ });
+};
+
+done;