diff options
author | dakkar <dakkar@thenautilus.net> | 2017-12-16 20:13:52 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2017-12-16 20:13:52 +0000 |
commit | af29c81914a2d172944c00c0a6289e804f8a9988 (patch) | |
tree | 62ecedf32f34567b3109aa1490bec6562deb7ff4 | |
parent | authorisation middleware (diff) | |
download | Ultramarine-af29c81914a2d172944c00c0a6289e804f8a9988.tar.gz Ultramarine-af29c81914a2d172944c00c0a6289e804f8a9988.tar.bz2 Ultramarine-af29c81914a2d172944c00c0a6289e804f8a9988.zip |
fix authorisation to return Subsonic response
-rw-r--r-- | lib/Ultramarine/Middleware/Authorisation.pm | 13 | ||||
-rw-r--r-- | t/tests/middleware/authorisation.t | 9 |
2 files changed, 16 insertions, 6 deletions
diff --git a/lib/Ultramarine/Middleware/Authorisation.pm b/lib/Ultramarine/Middleware/Authorisation.pm index 0ddacf6..86ba8f5 100644 --- a/lib/Ultramarine/Middleware/Authorisation.pm +++ b/lib/Ultramarine/Middleware/Authorisation.pm @@ -11,7 +11,18 @@ class Ultramarine::Middleware::Authorisation emit $request; } else { - emit Cro::HTTP::Response.new(:status<403>); + my $response = Cro::HTTP::Response.new( + :$request, + :status<200>, + ); + $response.set-body({ + status => 'failed', + error => [ + :code<40>, + :message('Wrong username or password'), + ], + }); + emit $response; } } } diff --git a/t/tests/middleware/authorisation.t b/t/tests/middleware/authorisation.t index af652b3..faca6b8 100644 --- a/t/tests/middleware/authorisation.t +++ b/t/tests/middleware/authorisation.t @@ -1,6 +1,7 @@ use v6.d.PREVIEW; use Test; use Cro::HTTP::Response; +use Cro::HTTP::Request; use Ultramarine::Middleware::Authentication; use Ultramarine::Middleware::Authorisation; @@ -17,7 +18,7 @@ sub test_auth($req,$expected,$message) { else { subtest { ok($result ~~ Cro::HTTP::Response,'should get a response'); - is($result.status,403,'with status 403'); + is($result.status,200,'with status 200'); }, $message; } done; @@ -25,9 +26,7 @@ sub test_auth($req,$expected,$message) { }; } -class TestReq { } - -test_auth(TestReq.new,0,'should fail without trait'); -test_auth(TestReq.new but Ultramarine::Request::Authed,1,'should pass with trait'); +test_auth(Cro::HTTP::Request.new,0,'should fail without trait'); +test_auth(Cro::HTTP::Request.new but Ultramarine::Request::Authed,1,'should pass with trait'); done-testing; |