View | Details | Raw Unified | Return to bug 24003
Collapse All | Expand All

(-)a/t/db_dependent/api/v1/auth_basic.t (-2 / +21 lines)
Lines 19-24 use Modern::Perl; Link Here
19
19
20
use Test::More tests => 2;
20
use Test::More tests => 2;
21
use Test::Mojo;
21
use Test::Mojo;
22
use Test::MockModule;
22
23
23
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
24
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 26-36 use t::lib::Mocks; Link Here
26
my $schema  = Koha::Database->new->schema;
27
my $schema  = Koha::Database->new->schema;
27
my $builder = t::lib::TestBuilder->new;
28
my $builder = t::lib::TestBuilder->new;
28
29
30
my $mock = create_a_test_endpoint();
31
29
my $t = Test::Mojo->new('Koha::REST::V1');
32
my $t = Test::Mojo->new('Koha::REST::V1');
30
33
31
subtest 'success tests' => sub {
34
subtest 'success tests' => sub {
32
35
33
    plan tests => 5;
36
    plan tests => 9;
34
37
35
    $schema->storage->txn_begin;
38
    $schema->storage->txn_begin;
36
39
Lines 46-51 subtest 'success tests' => sub { Link Here
46
    $t->get_ok("//$userid:$password@/api/v1/patrons")
49
    $t->get_ok("//$userid:$password@/api/v1/patrons")
47
      ->status_is( 200, 'Successful authentication and permissions check' );
50
      ->status_is( 200, 'Successful authentication and permissions check' );
48
51
52
    $t->post_ok("//$userid:$password@/api/v1/oauth/token")
53
      ->status_is( 418, 'Successful authentication and not enough permissions' )
54
      ->json_is('/userenv/number'   => $patron->borrowernumber)
55
      ->json_is('/userenv/id'       => $userid);
56
49
    $patron->flags(undef)->store;
57
    $patron->flags(undef)->store;
50
58
51
    $t->get_ok("//$userid:$password@/api/v1/patrons")
59
    $t->get_ok("//$userid:$password@/api/v1/patrons")
Lines 90-93 subtest 'failure tests' => sub { Link Here
90
    $schema->storage->txn_rollback;
98
    $schema->storage->txn_rollback;
91
};
99
};
92
100
101
sub create_a_test_endpoint {
102
    # Mock POST /oauth/token endpoint to return userenv
103
    # (it could be any other endpoint that doesn't require authentication too)
104
    my $mock = Test::MockModule->new('Koha::REST::V1::OAuth');
105
    $mock->mock(token => sub {
106
        my $c = shift;
107
        return $c->render( status => 418,
108
                           json => { userenv => C4::Context->userenv });
109
    });
110
    return $mock;
111
}
112
93
1;
113
1;
94
- 

Return to bug 24003