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

(-)a/t/db_dependent/api/v1/auth_authenticate_api_request.t (-2 / +67 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 3;
20
use Test::More tests => 4;
21
use Test::Mojo;
21
use Test::Mojo;
22
22
23
use Module::Load::Conditional qw(can_load);
23
use Module::Load::Conditional qw(can_load);
Lines 192-197 subtest 'anonymous requests to public API' => sub { Link Here
192
    $schema->storage->txn_rollback;
192
    $schema->storage->txn_rollback;
193
};
193
};
194
194
195
subtest 'x-koha-library tests' => sub {
196
197
    plan tests => 10;
198
199
    $schema->storage->txn_begin;
200
201
    my $stash;
202
    my $userenv;
203
204
    $t->app->hook(after_dispatch => sub {
205
        $stash   = shift->stash;
206
        $userenv = C4::Context->userenv;
207
    });
208
209
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
210
    my $superlibrarian = $builder->build_object({
211
        class => 'Koha::Patrons',
212
        value => { flags => 1 }
213
    });
214
    my $password = 'thePassword123';
215
    $superlibrarian->set_password({ password => $password, skip_validation => 1 });
216
    my $superlibrarian_userid = $superlibrarian->userid;
217
218
    my $unprivileged = $builder->build_object({
219
        class => 'Koha::Patrons',
220
        value => { flags => undef }
221
    });
222
    $unprivileged->set_password({ password => $password, skip_validation => 1 });
223
    my $unprivileged_userid = $unprivileged->userid;
224
225
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
226
227
    ## Independent branches tests
228
    t::lib::Mocks::mock_preference('IndependentBranches', 1);
229
230
    $t->get_ok(
231
        "//$unprivileged_userid:$password@/api/v1/cities",
232
        { 'x-koha-library' => $unprivileged->branchcode }
233
    );
234
235
    is( $userenv->{branch}, $unprivileged->branchcode, 'branch set correctly' );
236
237
    $t->get_ok( "//$unprivileged_userid:$password@/api/v1/cities" =>
238
          { 'x-koha-library' => $library->id } )->status_is(403)
239
      ->json_is(
240
        '/error' => 'Unauthorized attempt to set library to ' . $library->id );
241
242
    $t->get_ok( "//$superlibrarian_userid:$password@/api/v1/cities" =>
243
          { 'x-koha-library' => $library->id } )->status_is(200);
244
245
    is( $userenv->{branch}, $library->id, 'branch set correctly' );
246
247
    ## !Independent branches tests
248
    t::lib::Mocks::mock_preference('IndependentBranches', 1);
249
    $t->get_ok(
250
        "//$unprivileged_userid:$password@/api/v1/cities",
251
        { 'x-koha-library' => $unprivileged->branchcode }
252
    );
253
    $t->get_ok(
254
        "//$unprivileged_userid:$password@/api/v1/cities",
255
        { 'x-koha-library' => $library->id }
256
    );
257
258
    $schema->storage->txn_rollback;
259
};
260
195
sub create_user_and_session {
261
sub create_user_and_session {
196
262
197
    my $args  = shift;
263
    my $args  = shift;
198
- 

Return to bug 28157