aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2014-12-21 10:31:54 +0000
committerdakkar <dakkar@thenautilus.net>2014-12-21 10:31:54 +0000
commit694865f1c08bcd2e6cd2f7c8022502f686f70d1a (patch)
treee6a8fbdda924e012ff0513d80db808885ebe3cf1
parentmore client tests (diff)
downloadnet-hawk-694865f1c08bcd2e6cd2f7c8022502f686f70d1a.tar.gz
net-hawk-694865f1c08bcd2e6cd2f7c8022502f686f70d1a.tar.bz2
net-hawk-694865f1c08bcd2e6cd2f7c8022502f686f70d1a.zip
move "readme" tests in own subtest
better mirroring JS test layout
-rw-r--r--t/tests/Net/Hawk/Client.t74
-rw-r--r--t/tests/Net/Hawk/Crypto.t114
2 files changed, 96 insertions, 92 deletions
diff --git a/t/tests/Net/Hawk/Client.t b/t/tests/Net/Hawk/Client.t
index e4c0dbb..320de94 100644
--- a/t/tests/Net/Hawk/Client.t
+++ b/t/tests/Net/Hawk/Client.t
@@ -6,47 +6,49 @@ use Net::Hawk::Client;
my $c = Net::Hawk::Client->new();
-my %credentials = (
- id => 'dh37fgj492je',
- key => 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',
- algorithm => 'sha256',
-);
-my %options = (
- credentials => \%credentials,
- timestamp => 1353832234,
- nonce => 'j4h3g2',
- ext => 'some-app-ext-data'
-);
+subtest readme => sub {
+ 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 $field = $c->header(
- 'http://example.com:8000/resource/1?b=1&a=2',
- 'GET',
- \%options,
- )->{field};
+ subtest GET => sub {
+ my $field = $c->header(
+ 'http://example.com:8000/resource/1?b=1&a=2',
+ 'GET',
+ \%options,
+ )->{field};
- is(
- $field,
- 'Hawk id="dh37fgj492je", ts="1353832234", nonce="j4h3g2", ext="some-app-ext-data", mac="6R4rV5iE+NPoym+WwjeHzjAGXUtLNIxmo1vpMofpLAE="',
- 'Hawk header generated ok',
- );
-};
+ is(
+ $field,
+ 'Hawk id="dh37fgj492je", ts="1353832234", nonce="j4h3g2", ext="some-app-ext-data", mac="6R4rV5iE+NPoym+WwjeHzjAGXUtLNIxmo1vpMofpLAE="',
+ 'Hawk header generated ok',
+ );
+ };
-subtest POST => sub {
- $options{payload} = 'Thank you for flying Hawk';
- $options{content_type} = 'text/plain';
+ subtest POST => sub {
+ $options{payload} = 'Thank you for flying Hawk';
+ $options{content_type} = 'text/plain';
- my $field = $c->header(
- 'http://example.com:8000/resource/1?b=1&a=2',
- 'POST',
- \%options,
- )->{field};
+ my $field = $c->header(
+ 'http://example.com:8000/resource/1?b=1&a=2',
+ 'POST',
+ \%options,
+ )->{field};
- is(
- $field,
- 'Hawk id="dh37fgj492je", ts="1353832234", nonce="j4h3g2", hash="Yi9LfIIFRtBEPt74PVmbTF/xVAwPn7ub15ePICfgnuY=", ext="some-app-ext-data", mac="aSe1DERmZuRl3pI36/9BdZmnErTw3sNzOOAUlfeKjVw="',
- 'Hawk header generated ok',
- );
+ is(
+ $field,
+ 'Hawk id="dh37fgj492je", ts="1353832234", nonce="j4h3g2", hash="Yi9LfIIFRtBEPt74PVmbTF/xVAwPn7ub15ePICfgnuY=", ext="some-app-ext-data", mac="aSe1DERmZuRl3pI36/9BdZmnErTw3sNzOOAUlfeKjVw="',
+ 'Hawk header generated ok',
+ );
+ };
};
subtest header => sub {
diff --git a/t/tests/Net/Hawk/Crypto.t b/t/tests/Net/Hawk/Crypto.t
index 58e263f..7ae6f7e 100644
--- a/t/tests/Net/Hawk/Crypto.t
+++ b/t/tests/Net/Hawk/Crypto.t
@@ -6,68 +6,70 @@ 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},
- }
+subtest readme => sub {
+ my %credentials = (
+ id => 'dh37fgj492je',
+ key => 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',
+ algorithm => 'sha256',
);
-
- 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',
+ my %options = (
+ credentials => \%credentials,
+ timestamp => 1353832234,
+ nonce => 'j4h3g2',
+ ext => 'some-app-ext-data'
);
-};
-subtest POST => sub {
- my $payload = 'Thank you for flying Hawk';
- my $content_type = 'text/plain';
+ 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},
+ }
+ );
- my $payload_hash = $c->calculate_payload_hash(
- $payload,
- $credentials{algorithm},
- $content_type,
- );
+ 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',
+ );
+ };
- 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},
- }
- );
+ subtest POST => sub {
+ my $payload = 'Thank you for flying Hawk';
+ my $content_type = 'text/plain';
- 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',
- );
+ 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',
+ );
+ };
};
subtest normalized_string => sub {