diff options
author | dakkar <dakkar@thenautilus.net> | 2017-12-16 18:43:31 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2017-12-16 18:44:04 +0000 |
commit | c2a6e16bc2c8ea03acdf64dfed9d16721ad717f4 (patch) | |
tree | 1b9cc6f466d161d17241b640b03210ebd36b65b8 /t/tests/middleware/authorisation.t | |
parent | authentication middleware (diff) | |
download | Ultramarine-c2a6e16bc2c8ea03acdf64dfed9d16721ad717f4.tar.gz Ultramarine-c2a6e16bc2c8ea03acdf64dfed9d16721ad717f4.tar.bz2 Ultramarine-c2a6e16bc2c8ea03acdf64dfed9d16721ad717f4.zip |
authorisation middleware
Diffstat (limited to 't/tests/middleware/authorisation.t')
-rw-r--r-- | t/tests/middleware/authorisation.t | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/t/tests/middleware/authorisation.t b/t/tests/middleware/authorisation.t new file mode 100644 index 0000000..af652b3 --- /dev/null +++ b/t/tests/middleware/authorisation.t @@ -0,0 +1,33 @@ +use v6.d.PREVIEW; +use Test; +use Cro::HTTP::Response; +use Ultramarine::Middleware::Authentication; +use Ultramarine::Middleware::Authorisation; + +my $auth = Ultramarine::Middleware::Authorisation.new; + +sub test_auth($req,$expected,$message) { + my $supply = supply { emit $req }; + + react { + whenever $auth.process($supply) -> $result { + if ($expected) { + ok($result ~~ $req,$message); + } + else { + subtest { + ok($result ~~ Cro::HTTP::Response,'should get a response'); + is($result.status,403,'with status 403'); + }, $message; + } + done; + }; + }; +} + +class TestReq { } + +test_auth(TestReq.new,0,'should fail without trait'); +test_auth(TestReq.new but Ultramarine::Request::Authed,1,'should pass with trait'); + +done-testing; |