|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 2; |
20 |
use Test::More tests => 3; |
| 21 |
use Test::Mojo; |
21 |
use Test::Mojo; |
| 22 |
use Test::Warn; |
22 |
use Test::Warn; |
| 23 |
|
23 |
|
|
Lines 70-77
subtest 'Bad plugins tests' => sub {
Link Here
|
| 70 |
my $routes = get_defined_routes($t); |
70 |
my $routes = get_defined_routes($t); |
| 71 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
71 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
| 72 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
72 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
| 73 |
ok( !exists $routes->{'/contrib/badass/patrons/(:patron_id)/bother_wrong'} && !exists $routes->{'/contrib/badass/patrons/<:patron_id>/bother_wrong'}, 'Route doesn\'t exist' ); |
73 |
ok( !exists $routes->{'/contrib/badass/patrons/bother_wrong'}, 'Route doesn\'t exist' ); |
| 74 |
ok( exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'} || exists $routes->{'/contrib/testplugin/patrons/<:patron_id>/bother'}, 'Route exists' ); |
74 |
ok( exists $routes->{'/contrib/testplugin/patrons/bother'}, 'Route exists' ); |
| 75 |
|
75 |
|
| 76 |
$schema->storage->txn_rollback; |
76 |
$schema->storage->txn_rollback; |
| 77 |
}; |
77 |
}; |
|
Lines 104-110
subtest 'Disabled plugins tests' => sub {
Link Here
|
| 104 |
my $routes = get_defined_routes($t); |
104 |
my $routes = get_defined_routes($t); |
| 105 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
105 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
| 106 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
106 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
| 107 |
ok( !exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'} && !exists $routes->{'/contrib/testplugin/patrons/<:patron_id>/bother'}, |
107 |
ok( !exists $routes->{'/contrib/testplugin/patrons/bother'}, |
| 108 |
'Plugin disabled, route not defined' ); |
108 |
'Plugin disabled, route not defined' ); |
| 109 |
|
109 |
|
| 110 |
$good_plugin->enable; |
110 |
$good_plugin->enable; |
|
Lines 114-125
subtest 'Disabled plugins tests' => sub {
Link Here
|
| 114 |
|
114 |
|
| 115 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
115 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
| 116 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
116 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
| 117 |
ok( exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'} || exists $routes->{'/contrib/testplugin/patrons/<:patron_id>/bother'}, |
117 |
ok( exists $routes->{'/contrib/testplugin/patrons/bother'}, |
| 118 |
'Plugin enabled, route defined' ); |
118 |
'Plugin enabled, route defined' ); |
| 119 |
|
119 |
|
| 120 |
$schema->storage->txn_rollback; |
120 |
$schema->storage->txn_rollback; |
| 121 |
}; |
121 |
}; |
| 122 |
|
122 |
|
|
|
123 |
subtest 'Anonymous access routes plugins tests' => sub { |
| 124 |
|
| 125 |
plan tests => 9; |
| 126 |
|
| 127 |
$schema->storage->txn_begin; |
| 128 |
|
| 129 |
# enable plugins |
| 130 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
| 131 |
|
| 132 |
# remove any existing plugins that might interfere |
| 133 |
Koha::Plugins::Methods->search->delete; |
| 134 |
my $plugins = Koha::Plugins->new; |
| 135 |
$plugins->InstallPlugins; |
| 136 |
|
| 137 |
my @plugins = $plugins->GetPlugins( { all => 1 } ); |
| 138 |
foreach my $plugin (@plugins) { |
| 139 |
$plugin->enable; |
| 140 |
} |
| 141 |
|
| 142 |
# initialize Koha::REST::V1 after mocking |
| 143 |
my $t; |
| 144 |
warning_is |
| 145 |
{ $t = Test::Mojo->new('Koha::REST::V1'); } |
| 146 |
'The resulting spec is invalid. Skipping Bad API Route Plugin', |
| 147 |
'Bad plugins raise warning'; |
| 148 |
|
| 149 |
my $routes = get_defined_routes($t); |
| 150 |
ok( exists $routes->{'/contrib/testplugin/patrons/bother'}, 'Route exists' ); |
| 151 |
ok( exists $routes->{'/contrib/testplugin/public/patrons/bother'}, 'Route exists' ); |
| 152 |
|
| 153 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 0 ); |
| 154 |
|
| 155 |
$t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother') |
| 156 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
| 157 |
->json_is( { bothered => Mojo::JSON->true } ); |
| 158 |
|
| 159 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 1 ); |
| 160 |
|
| 161 |
$t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother') |
| 162 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
| 163 |
->json_is( { bothered => Mojo::JSON->true } ); |
| 164 |
|
| 165 |
$schema->storage->txn_rollback; |
| 166 |
}; |
| 167 |
|
| 123 |
sub get_defined_routes { |
168 |
sub get_defined_routes { |
| 124 |
my ($t) = @_; |
169 |
my ($t) = @_; |
| 125 |
my $routes = {}; |
170 |
my $routes = {}; |