|
Lines 37-44
BEGIN {
Link Here
|
| 37 |
|
37 |
|
| 38 |
use Koha::Database; |
38 |
use Koha::Database; |
| 39 |
use Koha::Plugins; |
39 |
use Koha::Plugins; |
|
|
40 |
use t::lib::TestBuilder; |
| 40 |
|
41 |
|
| 41 |
my $schema = Koha::Database->new->schema; |
42 |
my $schema = Koha::Database->new->schema; |
|
|
43 |
my $builder = t::lib::TestBuilder->new; |
| 42 |
|
44 |
|
| 43 |
subtest 'Bad plugins tests' => sub { |
45 |
subtest 'Bad plugins tests' => sub { |
| 44 |
|
46 |
|
|
Lines 118-126
subtest 'Disabled plugins tests' => sub {
Link Here
|
| 118 |
$schema->storage->txn_rollback; |
120 |
$schema->storage->txn_rollback; |
| 119 |
}; |
121 |
}; |
| 120 |
|
122 |
|
| 121 |
subtest 'Anonymous access routes plugins tests' => sub { |
123 |
subtest 'Permissions and access to plugin routes tests' => sub { |
| 122 |
|
124 |
|
| 123 |
plan tests => 9; |
125 |
plan tests => 16; |
| 124 |
|
126 |
|
| 125 |
$schema->storage->txn_begin; |
127 |
$schema->storage->txn_begin; |
| 126 |
|
128 |
|
|
Lines 150-158
subtest 'Anonymous access routes plugins tests' => sub {
Link Here
|
| 150 |
|
152 |
|
| 151 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 0 ); |
153 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 0 ); |
| 152 |
|
154 |
|
| 153 |
$t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother') |
155 |
$t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother') |
| 154 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
156 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
| 155 |
->json_is( { bothered => Mojo::JSON->true } ); |
157 |
->json_is( { bothered => Mojo::JSON->true } ); |
| 156 |
|
158 |
|
| 157 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 1 ); |
159 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 1 ); |
| 158 |
|
160 |
|
|
Lines 160-165
subtest 'Anonymous access routes plugins tests' => sub {
Link Here
|
| 160 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
162 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
| 161 |
->json_is( { bothered => Mojo::JSON->true } ); |
163 |
->json_is( { bothered => Mojo::JSON->true } ); |
| 162 |
|
164 |
|
|
|
165 |
$t->get_ok('/api/v1/contrib/testplugin/patrons/bother') |
| 166 |
->status_is(401, 'Plugin routes honour permissions, anonymous accesss denied'); |
| 167 |
|
| 168 |
my $librarian = $builder->build_object( |
| 169 |
{ |
| 170 |
class => 'Koha::Patrons', |
| 171 |
value => { flags => 2**3 } # borrowers flag = 4 |
| 172 |
} |
| 173 |
); |
| 174 |
my $password = 'thePassword123'; |
| 175 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
| 176 |
my $userid = $librarian->userid; |
| 177 |
|
| 178 |
$t->get_ok("//$userid:$password@/api/v1/contrib/testplugin/patrons/bother") |
| 179 |
->status_is(401, 'Plugin routes honour permissions, wrong permissions, accesss denied'); |
| 180 |
|
| 181 |
$librarian->set({ flags => 2 ** 4 })->store->discard_changes; |
| 182 |
|
| 183 |
$t->get_ok("//$userid:$password@/api/v1/contrib/testplugin/patrons/bother") |
| 184 |
->status_is(200, 'Plugin routes honour permissions, right permissions, accesss granted') |
| 185 |
->json_is( { bothered => Mojo::JSON->true } ); |
| 186 |
|
| 163 |
$schema->storage->txn_rollback; |
187 |
$schema->storage->txn_rollback; |
| 164 |
}; |
188 |
}; |
| 165 |
|
189 |
|
| 166 |
- |
|
|