From af29c81914a2d172944c00c0a6289e804f8a9988 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 16 Dec 2017 20:13:52 +0000 Subject: fix authorisation to return Subsonic response --- lib/Ultramarine/Middleware/Authorisation.pm | 13 ++++++++++++- 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; -- cgit v1.2.3