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

(-)a/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t (-7 / +32 lines)
Lines 38-43 BEGIN { Link Here
38
38
39
use Koha::Database;
39
use Koha::Database;
40
use Koha::Plugins;
40
use Koha::Plugins;
41
use t::lib::TestBuilder;
41
42
42
my $logger = Test::MockModule->new('Koha::Logger');
43
my $logger = Test::MockModule->new('Koha::Logger');
43
$logger->mock('error', sub {
44
$logger->mock('error', sub {
Lines 45-51 $logger->mock('error', sub { Link Here
45
    warn @_;
46
    warn @_;
46
});
47
});
47
48
48
my $schema = Koha::Database->new->schema;
49
my $schema  = Koha::Database->new->schema;
50
my $builder = t::lib::TestBuilder->new;
49
51
50
subtest 'Bad plugins tests' => sub {
52
subtest 'Bad plugins tests' => sub {
51
53
Lines 126-134 subtest 'Disabled plugins tests' => sub { Link Here
126
    $schema->storage->txn_rollback;
128
    $schema->storage->txn_rollback;
127
};
129
};
128
130
129
subtest 'Anonymous access routes plugins tests' => sub {
131
subtest 'Permissions and access to plugin routes tests' => sub {
130
132
131
    plan tests => 9;
133
    plan tests => 16;
132
134
133
    $schema->storage->txn_begin;
135
    $schema->storage->txn_begin;
134
136
Lines 159-167 subtest 'Anonymous access routes plugins tests' => sub { Link Here
159
161
160
    C4::Context->set_preference( 'RESTPublicAnonymousRequests', 0 );
162
    C4::Context->set_preference( 'RESTPublicAnonymousRequests', 0 );
161
163
162
   $t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother')
164
    $t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother')
163
     ->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests')
165
      ->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests')
164
     ->json_is( { bothered => Mojo::JSON->true } );
166
      ->json_is( { bothered => Mojo::JSON->true } );
165
167
166
    C4::Context->set_preference( 'RESTPublicAnonymousRequests', 1 );
168
    C4::Context->set_preference( 'RESTPublicAnonymousRequests', 1 );
167
169
Lines 169-174 subtest 'Anonymous access routes plugins tests' => sub { Link Here
169
      ->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests')
171
      ->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests')
170
      ->json_is( { bothered => Mojo::JSON->true } );
172
      ->json_is( { bothered => Mojo::JSON->true } );
171
173
174
    $t->get_ok('/api/v1/contrib/testplugin/patrons/bother')
175
      ->status_is(401, 'Plugin routes honour permissions, anonymous access denied');
176
177
    # Create a patron with permissions, but the wrong ones: 3 => parameters
178
    my $librarian = $builder->build_object(
179
        {
180
            class => 'Koha::Patrons',
181
            value => { flags => 2**3 }
182
        }
183
    );
184
    my $password = 'thePassword123';
185
    $librarian->set_password( { password => $password, skip_validation => 1 } );
186
    my $userid = $librarian->userid;
187
188
    $t->get_ok("//$userid:$password@/api/v1/contrib/testplugin/patrons/bother")
189
      ->status_is(403, 'Plugin routes honour permissions, wrong permissions, access denied');
190
191
    # Set the patron permissions to the right ones: 4 => borrowers
192
    $librarian->set({ flags => 2 ** 4 })->store->discard_changes;
193
194
    $t->get_ok("//$userid:$password@/api/v1/contrib/testplugin/patrons/bother")
195
      ->status_is(200, 'Plugin routes honour permissions, right permissions, access granted')
196
      ->json_is( { bothered => Mojo::JSON->true } );
197
172
    $schema->storage->txn_rollback;
198
    $schema->storage->txn_rollback;
173
};
199
};
174
200
175
- 

Return to bug 26322