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;