aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2014-12-20 14:27:55 +0000
committerdakkar <dakkar@thenautilus.net>2014-12-20 14:27:55 +0000
commita237abd8e01e2783b9bb9d6eb3c3c26ef8832f92 (patch)
treeed88c9fed05152c9ce2ee77e3bf42dc600a1d24b /t
downloadnet-hawk-a237abd8e01e2783b9bb9d6eb3c3c26ef8832f92.tar.gz
net-hawk-a237abd8e01e2783b9bb9d6eb3c3c26ef8832f92.tar.bz2
net-hawk-a237abd8e01e2783b9bb9d6eb3c3c26ef8832f92.zip
first tests passing
Diffstat (limited to 't')
-rw-r--r--t/tests/Net/Hawk/Crypto.t73
1 files changed, 73 insertions, 0 deletions
diff --git a/t/tests/Net/Hawk/Crypto.t b/t/tests/Net/Hawk/Crypto.t
new file mode 100644
index 0000000..eb1a52f
--- /dev/null
+++ b/t/tests/Net/Hawk/Crypto.t
@@ -0,0 +1,73 @@
+#!perl
+use strict;
+use warnings;
+use Test::More;
+use Net::Hawk::Crypto;
+
+my $c = Net::Hawk::Crypto->new();
+
+my %credentials = (
+ id => 'dh37fgj492je',
+ key => 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',
+ algorithm => 'sha256',
+);
+my %options = (
+ 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},
+ }
+ );
+
+ is(
+ $string,
+ "hawk.1.header\n1353832234\nj4h3g2\nGET\n/resource?a=1&b=2\nexample.com\n8000\n\nsome-app-ext-data\n",
+ 'normalized string generated ok',
+ );
+};
+
+subtest POST => sub {
+ my $payload = 'Thank you for flying Hawk';
+ my $content_type = 'text/plain';
+
+ my $payload_hash = $c->calculate_payload_hash(
+ $payload,
+ $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},
+ }
+ );
+
+ is(
+ $string,
+ "hawk.1.header\n1353832234\nj4h3g2\nPOST\n/resource?a=1&b=2\nexample.com\n8000\nYi9LfIIFRtBEPt74PVmbTF/xVAwPn7ub15ePICfgnuY=\nsome-app-ext-data\n",
+ 'normalized string generated ok',
+ );
+};
+
+done_testing;