|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 1; |
20 |
use Test::More tests => 2; |
|
|
21 |
use Test::MockModule; |
| 21 |
use Test::Mojo; |
22 |
use Test::Mojo; |
| 22 |
|
23 |
|
| 23 |
use Koha::Database; |
24 |
use Koha::Database; |
|
Lines 113-115
subtest '/oauth/token tests' => sub {
Link Here
|
| 113 |
|
114 |
|
| 114 |
$schema->storage->txn_rollback; |
115 |
$schema->storage->txn_rollback; |
| 115 |
}; |
116 |
}; |
| 116 |
- |
117 |
|
|
|
118 |
subtest 'Net::OAuth2::AuthorizationServer missing tests' => sub { |
| 119 |
|
| 120 |
plan tests => 10; |
| 121 |
|
| 122 |
my $load_conditional = Test::MockModule->new('Module::Load::Conditional'); |
| 123 |
|
| 124 |
# Enable the client credentials grant syspref |
| 125 |
t::lib::Mocks::mock_preference( 'RESTOAuth2ClientCredentials', 1 ); |
| 126 |
|
| 127 |
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 2**4 } }); |
| 128 |
my $api_key = Koha::ApiKey->new({ patron_id => $patron->id, description => 'blah' })->store; |
| 129 |
|
| 130 |
my $form_data = { |
| 131 |
grant_type => 'client_credentials', |
| 132 |
client_id => $api_key->client_id, |
| 133 |
client_secret => $api_key->secret |
| 134 |
}; |
| 135 |
|
| 136 |
$t->post_ok( '/api/v1/oauth/token', form => $form_data )->status_is(200) |
| 137 |
->json_is( '/expires_in' => 3600 )->json_is( '/token_type' => 'Bearer' ) |
| 138 |
->json_has('/access_token'); |
| 139 |
|
| 140 |
my $access_token = $t->tx->res->json->{access_token}; |
| 141 |
|
| 142 |
$load_conditional->mock( 'can_load', sub { return 0; } ); |
| 143 |
|
| 144 |
my $tx = $t->ua->build_tx( GET => '/api/v1/patrons' ); |
| 145 |
$tx->req->headers->authorization("Bearer $access_token"); |
| 146 |
$t->request_ok($tx) |
| 147 |
->status_is(403); |
| 148 |
|
| 149 |
$t->post_ok( '/api/v1/oauth/token', form => $form_data ) |
| 150 |
->status_is(400) |
| 151 |
->json_is( { error => 'Unimplemented grant type' } ); |
| 152 |
|
| 153 |
}; |