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-139
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 |
|
135 |
# enable plugins |
137 |
# enable plugins |
136 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
138 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
|
|
139 |
# enable BASIC auth |
140 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
137 |
|
141 |
|
138 |
# remove any existing plugins that might interfere |
142 |
# remove any existing plugins that might interfere |
139 |
Koha::Plugins::Methods->search->delete; |
143 |
Koha::Plugins::Methods->search->delete; |
Lines 159-167
subtest 'Anonymous access routes plugins tests' => sub {
Link Here
|
159 |
|
163 |
|
160 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 0 ); |
164 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 0 ); |
161 |
|
165 |
|
162 |
$t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother') |
166 |
$t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother') |
163 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
167 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
164 |
->json_is( { bothered => Mojo::JSON->true } ); |
168 |
->json_is( { bothered => Mojo::JSON->true } ); |
165 |
|
169 |
|
166 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 1 ); |
170 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 1 ); |
167 |
|
171 |
|
Lines 169-174
subtest 'Anonymous access routes plugins tests' => sub {
Link Here
|
169 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
173 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
170 |
->json_is( { bothered => Mojo::JSON->true } ); |
174 |
->json_is( { bothered => Mojo::JSON->true } ); |
171 |
|
175 |
|
|
|
176 |
$t->get_ok('/api/v1/contrib/testplugin/patrons/bother') |
177 |
->status_is(401, 'Plugin routes honour permissions, anonymous access denied'); |
178 |
|
179 |
# Create a patron with permissions, but the wrong ones: 3 => parameters |
180 |
my $librarian = $builder->build_object( |
181 |
{ |
182 |
class => 'Koha::Patrons', |
183 |
value => { flags => 2**3 } |
184 |
} |
185 |
); |
186 |
my $password = 'thePassword123'; |
187 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
188 |
my $userid = $librarian->userid; |
189 |
|
190 |
$t->get_ok("//$userid:$password@/api/v1/contrib/testplugin/patrons/bother") |
191 |
->status_is(403, 'Plugin routes honour permissions, wrong permissions, access denied'); |
192 |
|
193 |
# Set the patron permissions to the right ones: 4 => borrowers |
194 |
$librarian->set({ flags => 2 ** 4 })->store->discard_changes; |
195 |
|
196 |
$t->get_ok("//$userid:$password@/api/v1/contrib/testplugin/patrons/bother") |
197 |
->status_is(200, 'Plugin routes honour permissions, right permissions, access granted') |
198 |
->json_is( { bothered => Mojo::JSON->true } ); |
199 |
|
172 |
$schema->storage->txn_rollback; |
200 |
$schema->storage->txn_rollback; |
173 |
}; |
201 |
}; |
174 |
|
202 |
|
175 |
- |
|
|