summaryrefslogtreecommitdiff
path: root/t/tests/middleware/authorisation.t
blob: af652b31ea86d31680e8a6dc298e266392723e51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;