aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2014-12-27 21:48:02 +0000
committerdakkar <dakkar@thenautilus.net>2014-12-27 21:48:02 +0000
commit11105db8ba8015a970b5dc02f241ce8c37087351 (patch)
tree09147fe985f16606035683ee33befd25b336ce77
parentfix exception stringification (diff)
downloadnet-hawk-11105db8ba8015a970b5dc02f241ce8c37087351.tar.gz
net-hawk-11105db8ba8015a970b5dc02f241ce8c37087351.tar.bz2
net-hawk-11105db8ba8015a970b5dc02f241ce8c37087351.zip
more tests & fixes
-rw-r--r--lib/Net/Hawk/Utils.pm6
-rw-r--r--t/tests/Net/Hawk/Utils.t14
2 files changed, 14 insertions, 6 deletions
diff --git a/lib/Net/Hawk/Utils.pm b/lib/Net/Hawk/Utils.pm
index e0473a2..a476ac9 100644
--- a/lib/Net/Hawk/Utils.pm
+++ b/lib/Net/Hawk/Utils.pm
@@ -48,17 +48,17 @@ package Net::Hawk::Utils {
Net::Hawk::Errors::BadRequest.new(
text => "Unknown attribute $key",
value => $header,
- ) unless $valid_keys{$key} :exists;
+ ).throw unless $valid_keys{~$key} :exists;
Net::Hawk::Errors::BadRequest.new(
text => "Bad attribute value $value",
value => $header,
- ) unless $value ~~ m{^<[ \w !#$%&'()*+,\-./:;\<=\>?@\[\]^`{|}~ ]>+$};
+ ).throw unless $value ~~ m{^<[ \w !#$%&'()*+,\-./:;\<=\>?@\[\]^`{|}~ ]>+$};
Net::Hawk::Errors::BadRequest.new(
text => "Duplicate attribute $key",
value => $header,
- ) if %attributes{$key} :exists;
+ ).throw if %attributes{$key} :exists;
%attributes{$key} = ~$value;
}
diff --git a/t/tests/Net/Hawk/Utils.t b/t/tests/Net/Hawk/Utils.t
index 126450e..7db7b1d 100644
--- a/t/tests/Net/Hawk/Utils.t
+++ b/t/tests/Net/Hawk/Utils.t
@@ -12,15 +12,23 @@ subtest {
subtest {
throws_like { parse_authorization_header(Str) },
Net::Hawk::Errors::UnAuthorized,
- text => 'no header';
+ text => rx:s/no header/;
throws_like { parse_authorization_header('bad') },
Net::Hawk::Errors::BadRequest,
- text => 'invalid header syntax';
+ text => rx:s/invalid header/;
throws_like { parse_authorization_header('hawk: bad') },
Net::Hawk::Errors::BadRequest,
- text => 'Bad header format';
+ text => rx:i:s/bad header/;
+
+ throws_like { parse_authorization_header('hawk: bad="a"') },
+ Net::Hawk::Errors::BadRequest,
+ text => rx:i:s/unknown attribute/;
+
+ throws_like { parse_authorization_header('hawk: id="a", id="b"') },
+ Net::Hawk::Errors::BadRequest,
+ text => rx:i:s/duplicate attribute/;
is_deeply( parse_authorization_header('hawk: id="1"'),
{ id => '1' },