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 120-133
subtest 'Disabled plugins tests' => sub {
Link Here
|
120 |
$schema->storage->txn_rollback; |
122 |
$schema->storage->txn_rollback; |
121 |
}; |
123 |
}; |
122 |
|
124 |
|
123 |
subtest 'Anonymous access routes plugins tests' => sub { |
125 |
subtest 'Permissions and access to plugin routes tests' => sub { |
124 |
|
126 |
|
125 |
plan tests => 9; |
127 |
plan tests => 16; |
126 |
|
128 |
|
127 |
$schema->storage->txn_begin; |
129 |
$schema->storage->txn_begin; |
128 |
|
130 |
|
129 |
# enable plugins |
131 |
# enable plugins |
130 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
132 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
|
|
133 |
# enable BASIC auth |
134 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
131 |
|
135 |
|
132 |
# remove any existing plugins that might interfere |
136 |
# remove any existing plugins that might interfere |
133 |
Koha::Plugins::Methods->search->delete; |
137 |
Koha::Plugins::Methods->search->delete; |
Lines 152-160
subtest 'Anonymous access routes plugins tests' => sub {
Link Here
|
152 |
|
156 |
|
153 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 0 ); |
157 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 0 ); |
154 |
|
158 |
|
155 |
$t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother') |
159 |
$t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother') |
156 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
160 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
157 |
->json_is( { bothered => Mojo::JSON->true } ); |
161 |
->json_is( { bothered => Mojo::JSON->true } ); |
158 |
|
162 |
|
159 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 1 ); |
163 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 1 ); |
160 |
|
164 |
|
Lines 162-167
subtest 'Anonymous access routes plugins tests' => sub {
Link Here
|
162 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
166 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
163 |
->json_is( { bothered => Mojo::JSON->true } ); |
167 |
->json_is( { bothered => Mojo::JSON->true } ); |
164 |
|
168 |
|
|
|
169 |
$t->get_ok('/api/v1/contrib/testplugin/patrons/bother') |
170 |
->status_is(401, 'Plugin routes honour permissions, anonymous access denied'); |
171 |
|
172 |
# Create a patron with permissions, but the wrong ones: 3 => parameters |
173 |
my $librarian = $builder->build_object( |
174 |
{ |
175 |
class => 'Koha::Patrons', |
176 |
value => { flags => 2**3 } |
177 |
} |
178 |
); |
179 |
my $password = 'thePassword123'; |
180 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
181 |
my $userid = $librarian->userid; |
182 |
|
183 |
$t->get_ok("//$userid:$password@/api/v1/contrib/testplugin/patrons/bother") |
184 |
->status_is(403, 'Plugin routes honour permissions, wrong permissions, access denied'); |
185 |
|
186 |
# Set the patron permissions to the right ones: 4 => borrowers |
187 |
$librarian->set({ flags => 2 ** 4 })->store->discard_changes; |
188 |
|
189 |
$t->get_ok("//$userid:$password@/api/v1/contrib/testplugin/patrons/bother") |
190 |
->status_is(200, 'Plugin routes honour permissions, right permissions, access granted') |
191 |
->json_is( { bothered => Mojo::JSON->true } ); |
192 |
|
165 |
$schema->storage->txn_rollback; |
193 |
$schema->storage->txn_rollback; |
166 |
}; |
194 |
}; |
167 |
|
195 |
|
168 |
- |
|
|