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

(-)a/t/db_dependent/api/v1/auth_authenticate_api_request.t (-3 / +32 lines)
Lines 29-37 use Koha::Patrons; Link Here
29
use t::lib::Mocks;
29
use t::lib::Mocks;
30
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
31
31
32
my $t = Test::Mojo->new('Koha::REST::V1');
33
my $schema  = Koha::Database->new->schema;
32
my $schema  = Koha::Database->new->schema;
34
my $builder = t::lib::TestBuilder->new();
33
my $builder = t::lib::TestBuilder->new();
34
my $t = Test::Mojo->new('Koha::REST::V1');
35
35
36
my $remote_address = '127.0.0.1';
36
my $remote_address = '127.0.0.1';
37
my $tx;
37
my $tx;
Lines 44-50 t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' ); Link Here
44
subtest 'token-based tests' => sub {
44
subtest 'token-based tests' => sub {
45
45
46
    if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) {
46
    if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) {
47
        plan tests => 12;
47
        plan tests => 14;
48
    }
48
    }
49
    else {
49
    else {
50
        plan skip_all => 'Net::OAuth2::AuthorizationServer not available';
50
        plan skip_all => 'Net::OAuth2::AuthorizationServer not available';
Lines 95-106 subtest 'token-based tests' => sub { Link Here
95
    ok( defined $embed, 'The embed hashref is generated and stashed' );
95
    ok( defined $embed, 'The embed hashref is generated and stashed' );
96
    is_deeply( $embed, { fund => {} }, 'The embed data structure is correct' );
96
    is_deeply( $embed, { fund => {} }, 'The embed data structure is correct' );
97
97
98
    my $mock = Test::MockModule->new('Koha::REST::V1::Patrons');
99
    $mock->mock( list => sub {
100
        my $c = shift;
101
        return $c->render(
102
            status => 200,
103
            json   => { userenv => C4::Context->userenv() }
104
        );
105
    });
106
107
    $tx = $t->ua->build_tx(GET => '/api/v1/patrons');
108
    $tx->req->headers->authorization("Bearer $access_token");
109
    $t->request_ok($tx)
110
      ->json_is('/userenv/number' => $patron->borrowernumber );
111
98
    $schema->storage->txn_rollback;
112
    $schema->storage->txn_rollback;
99
};
113
};
100
114
101
subtest 'cookie-based tests' => sub {
115
subtest 'cookie-based tests' => sub {
102
116
103
    plan tests => 6;
117
    plan tests => 8;
104
118
105
    $schema->storage->txn_begin;
119
    $schema->storage->txn_begin;
106
120
Lines 119-124 subtest 'cookie-based tests' => sub { Link Here
119
    is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and
133
    is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and
120
    is( $user->borrowernumber, $borrowernumber, 'The stashed user is the right one' );
134
    is( $user->borrowernumber, $borrowernumber, 'The stashed user is the right one' );
121
135
136
    my $mock = Test::MockModule->new('Koha::REST::V1::Patrons');
137
    $mock->mock( list => sub {
138
        my $c = shift;
139
        return $c->render(
140
            status => 200,
141
            json   => { userenv => C4::Context->userenv() }
142
        );
143
    });
144
145
    $tx = $t->ua->build_tx(GET => '/api/v1/patrons');
146
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
147
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
148
    $t->request_ok($tx)
149
      ->json_is('/userenv/number' => $borrowernumber );
150
122
    subtest 'logged-out tests' => sub {
151
    subtest 'logged-out tests' => sub {
123
        plan tests => 3;
152
        plan tests => 3;
124
153
(-)a/t/db_dependent/api/v1/auth_basic.t (-3 / +12 lines)
Lines 30-36 my $t = Test::Mojo->new('Koha::REST::V1'); Link Here
30
30
31
subtest 'success tests' => sub {
31
subtest 'success tests' => sub {
32
32
33
    plan tests => 5;
33
    plan tests => 6;
34
34
35
    $schema->storage->txn_begin;
35
    $schema->storage->txn_begin;
36
36
Lines 43-50 subtest 'success tests' => sub { Link Here
43
    $patron->set_password({ password => $password });
43
    $patron->set_password({ password => $password });
44
    my $userid = $patron->userid;
44
    my $userid = $patron->userid;
45
45
46
    my $mock = Test::MockModule->new('Koha::REST::V1::Patrons');
47
    $mock->mock( list => sub {
48
        my $c = shift;
49
        return $c->render(
50
            status => 200,
51
            json   => { userenv => C4::Context->userenv() }
52
        );
53
    });
54
46
    $t->get_ok("//$userid:$password@/api/v1/patrons")
55
    $t->get_ok("//$userid:$password@/api/v1/patrons")
47
      ->status_is( 200, 'Successful authentication and permissions check' );
56
      ->status_is( 200, 'Successful authentication and permissions check' )
57
      ->json_is('/userenv/number' => $patron->borrowernumber );
48
58
49
    $patron->flags(undef)->store;
59
    $patron->flags(undef)->store;
50
60
51
- 

Return to bug 24003