Lines 21-26
use Test::More tests => 1;
Link Here
|
21 |
use Test::Mojo; |
21 |
use Test::Mojo; |
22 |
|
22 |
|
23 |
use Koha::Database; |
23 |
use Koha::Database; |
|
|
24 |
use Koha::Patrons; |
24 |
|
25 |
|
25 |
use t::lib::Mocks; |
26 |
use t::lib::Mocks; |
26 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
Lines 34-46
subtest '/oauth/token tests' => sub {
Link Here
|
34 |
|
35 |
|
35 |
$schema->storage->txn_begin; |
36 |
$schema->storage->txn_begin; |
36 |
|
37 |
|
37 |
my $patron = $builder->build({ |
38 |
my $borrower = $builder->build({ |
38 |
source => 'Borrower', |
39 |
source => 'Borrower', |
39 |
value => { |
40 |
value => { |
40 |
surname => 'Test OAuth', |
41 |
surname => 'Test OAuth', |
41 |
flags => 0, |
42 |
flags => 0, |
42 |
}, |
43 |
}, |
43 |
}); |
44 |
}); |
|
|
45 |
my $patron = Koha::Patrons->find($borrower->{borrowernumber}); |
44 |
|
46 |
|
45 |
# Missing parameter grant_type |
47 |
# Missing parameter grant_type |
46 |
$t->post_ok('/api/v1/oauth/token') |
48 |
$t->post_ok('/api/v1/oauth/token') |
Lines 60-66
subtest '/oauth/token tests' => sub {
Link Here
|
60 |
t::lib::Mocks::mock_config('api_client', { |
62 |
t::lib::Mocks::mock_config('api_client', { |
61 |
'client_id' => $client_id, |
63 |
'client_id' => $client_id, |
62 |
'client_secret' => $client_secret, |
64 |
'client_secret' => $client_secret, |
63 |
patron_id => $patron->{borrowernumber}, |
65 |
patron_id => $patron->borrowernumber, |
64 |
}); |
66 |
}); |
65 |
|
67 |
|
66 |
my $formData = { |
68 |
my $formData = { |
Lines 85-98
subtest '/oauth/token tests' => sub {
Link Here
|
85 |
$t->request_ok($tx)->status_is(403); |
87 |
$t->request_ok($tx)->status_is(403); |
86 |
|
88 |
|
87 |
# With access token and permissions, it returns 200 |
89 |
# With access token and permissions, it returns 200 |
88 |
$builder->build({ |
90 |
$patron->flags(2**4)->store; |
89 |
source => 'UserPermission', |
|
|
90 |
value => { |
91 |
borrowernumber => $patron->{borrowernumber}, |
92 |
module_bit => 4, # borrowers |
93 |
code => 'edit_borrowers', |
94 |
}, |
95 |
}); |
96 |
$tx = $t->ua->build_tx(GET => '/api/v1/patrons'); |
91 |
$tx = $t->ua->build_tx(GET => '/api/v1/patrons'); |
97 |
$tx->req->headers->authorization("Bearer $access_token"); |
92 |
$tx->req->headers->authorization("Bearer $access_token"); |
98 |
$t->request_ok($tx)->status_is(200); |
93 |
$t->request_ok($tx)->status_is(200); |
99 |
- |
|
|