Lines 44-50
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' );
Link Here
|
44 |
subtest 'token-based tests' => sub { |
44 |
subtest 'token-based tests' => sub { |
45 |
|
45 |
|
46 |
if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) { |
46 |
if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) { |
47 |
plan tests => 12; |
47 |
plan tests => 14; |
48 |
} |
48 |
} |
49 |
else { |
49 |
else { |
50 |
plan skip_all => 'Net::OAuth2::AuthorizationServer not available'; |
50 |
plan skip_all => 'Net::OAuth2::AuthorizationServer not available'; |
Lines 74-95
subtest 'token-based tests' => sub {
Link Here
|
74 |
|
74 |
|
75 |
my $access_token = $t->tx->res->json->{access_token}; |
75 |
my $access_token = $t->tx->res->json->{access_token}; |
76 |
|
76 |
|
77 |
# With access token and permissions, it returns 200 |
|
|
78 |
#$patron->flags(2**4)->store; |
79 |
|
80 |
my $stash; |
77 |
my $stash; |
|
|
78 |
my $interface; |
79 |
my $userenv; |
81 |
|
80 |
|
82 |
my $tx = $t->ua->build_tx(GET => '/api/v1/acquisitions/orders'); |
81 |
my $tx = $t->ua->build_tx(GET => '/api/v1/acquisitions/orders'); |
83 |
$tx->req->headers->authorization("Bearer $access_token"); |
82 |
$tx->req->headers->authorization("Bearer $access_token"); |
84 |
$tx->req->headers->header( 'x-koha-embed' => 'fund' ); |
83 |
$tx->req->headers->header( 'x-koha-embed' => 'fund' ); |
85 |
|
84 |
|
86 |
$t->app->hook(after_dispatch => sub { $stash = shift->stash }); |
85 |
$t->app->hook(after_dispatch => sub { |
|
|
86 |
$stash = shift->stash; |
87 |
$interface = C4::Context->interface; |
88 |
$userenv = C4::Context->userenv; |
89 |
}); |
90 |
|
91 |
# With access token and permissions, it returns 200 |
92 |
#$patron->flags(2**4)->store; |
87 |
$t->request_ok($tx)->status_is(200); |
93 |
$t->request_ok($tx)->status_is(200); |
88 |
|
94 |
|
89 |
my $user = $stash->{'koha.user'}; |
95 |
my $user = $stash->{'koha.user'}; |
90 |
ok( defined $user, 'The \'koha.user\' object is defined in the stash') and |
96 |
ok( defined $user, 'The \'koha.user\' object is defined in the stash') and |
91 |
is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and |
97 |
is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and |
92 |
is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' ); |
98 |
is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' ); |
|
|
99 |
is( $userenv->{number}, $patron->borrowernumber, 'userenv set correctly' ); |
100 |
is( $interface, 'api', "Interface correctly set to \'api\'" ); |
93 |
|
101 |
|
94 |
my $embed = $stash->{'koha.embed'}; |
102 |
my $embed = $stash->{'koha.embed'}; |
95 |
ok( defined $embed, 'The embed hashref is generated and stashed' ); |
103 |
ok( defined $embed, 'The embed hashref is generated and stashed' ); |
Lines 100-106
subtest 'token-based tests' => sub {
Link Here
|
100 |
|
108 |
|
101 |
subtest 'cookie-based tests' => sub { |
109 |
subtest 'cookie-based tests' => sub { |
102 |
|
110 |
|
103 |
plan tests => 6; |
111 |
plan tests => 8; |
104 |
|
112 |
|
105 |
$schema->storage->txn_begin; |
113 |
$schema->storage->txn_begin; |
106 |
|
114 |
|
Lines 111-123
subtest 'cookie-based tests' => sub {
Link Here
|
111 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
119 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
112 |
|
120 |
|
113 |
my $stash; |
121 |
my $stash; |
114 |
$t->app->hook(after_dispatch => sub { $stash = shift->stash }); |
122 |
my $interface; |
|
|
123 |
my $userenv; |
124 |
|
125 |
$t->app->hook(after_dispatch => sub { |
126 |
$stash = shift->stash; |
127 |
$interface = C4::Context->interface; |
128 |
$userenv = C4::Context->userenv; |
129 |
}); |
130 |
|
115 |
$t->request_ok($tx)->status_is(200); |
131 |
$t->request_ok($tx)->status_is(200); |
116 |
|
132 |
|
117 |
my $user = $stash->{'koha.user'}; |
133 |
my $user = $stash->{'koha.user'}; |
118 |
ok( defined $user, 'The \'koha.user\' object is defined in the stash') and |
134 |
ok( defined $user, 'The \'koha.user\' object is defined in the stash') and |
119 |
is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and |
135 |
is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and |
120 |
is( $user->borrowernumber, $borrowernumber, 'The stashed user is the right one' ); |
136 |
is( $user->borrowernumber, $borrowernumber, 'The stashed user is the right one' ); |
|
|
137 |
is( $userenv->{number}, $borrowernumber, 'userenv set correctly' ); |
138 |
is( $interface, 'api', "Interface correctly set to \'api\'" ); |
121 |
|
139 |
|
122 |
subtest 'logged-out tests' => sub { |
140 |
subtest 'logged-out tests' => sub { |
123 |
plan tests => 3; |
141 |
plan tests => 3; |