Lines 31-45
my $schema = Koha::Database->new->schema;
Link Here
|
31 |
my $builder = t::lib::TestBuilder->new(); |
31 |
my $builder = t::lib::TestBuilder->new(); |
32 |
|
32 |
|
33 |
subtest '/oauth/token tests' => sub { |
33 |
subtest '/oauth/token tests' => sub { |
34 |
plan tests => 19; |
34 |
plan tests => 24; |
35 |
|
35 |
|
36 |
$schema->storage->txn_begin; |
36 |
$schema->storage->txn_begin; |
37 |
|
37 |
|
38 |
my $patron = $builder->build_object({ |
38 |
my $patron = $builder->build_object({ |
39 |
class => 'Koha::Patrons', |
39 |
class => 'Koha::Patrons', |
40 |
value => { |
40 |
value => { |
41 |
surname => 'Test OAuth', |
41 |
flags => 0 # no permissions |
42 |
flags => 0, |
|
|
43 |
}, |
42 |
}, |
44 |
}); |
43 |
}); |
45 |
|
44 |
|
Lines 57-73
subtest '/oauth/token tests' => sub {
Link Here
|
57 |
->status_is(403) |
56 |
->status_is(403) |
58 |
->json_is({error => 'unauthorized_client'}); |
57 |
->json_is({error => 'unauthorized_client'}); |
59 |
|
58 |
|
60 |
my ($client_id, $client_secret) = ('client1', 'secr3t'); |
59 |
my $api_key = Koha::ApiKey->new({ patron_id => $patron->id, description => 'blah' })->store; |
61 |
t::lib::Mocks::mock_config('api_client', { |
|
|
62 |
'client_id' => $client_id, |
63 |
'client_secret' => $client_secret, |
64 |
patron_id => $patron->borrowernumber, |
65 |
}); |
66 |
|
60 |
|
67 |
my $formData = { |
61 |
my $formData = { |
68 |
grant_type => 'client_credentials', |
62 |
grant_type => 'client_credentials', |
69 |
client_id => $client_id, |
63 |
client_id => $api_key->client_id, |
70 |
client_secret => $client_secret, |
64 |
client_secret => $api_key->secret |
71 |
}; |
65 |
}; |
72 |
$t->post_ok('/api/v1/oauth/token', form => $formData) |
66 |
$t->post_ok('/api/v1/oauth/token', form => $formData) |
73 |
->status_is(200) |
67 |
->status_is(200) |
Lines 91-95
subtest '/oauth/token tests' => sub {
Link Here
|
91 |
$tx->req->headers->authorization("Bearer $access_token"); |
85 |
$tx->req->headers->authorization("Bearer $access_token"); |
92 |
$t->request_ok($tx)->status_is(200); |
86 |
$t->request_ok($tx)->status_is(200); |
93 |
|
87 |
|
|
|
88 |
# expire token |
89 |
my $token = Koha::OAuthAccessTokens->find($access_token); |
90 |
$token->expires( time - 1 )->store; |
91 |
$tx = $t->ua->build_tx( GET => '/api/v1/patrons' ); |
92 |
$tx->req->headers->authorization("Bearer $access_token"); |
93 |
$t->request_ok($tx) |
94 |
->status_is(401); |
95 |
|
96 |
# revoke key |
97 |
$api_key->active(0)->store; |
98 |
$t->post_ok('/api/v1/oauth/token', form => $formData) |
99 |
->status_is(403) |
100 |
->json_is({ error => 'unauthorized_client' }); |
101 |
|
94 |
$schema->storage->txn_rollback; |
102 |
$schema->storage->txn_rollback; |
95 |
}; |
103 |
}; |
96 |
- |
|
|