Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 2; |
22 |
use Test::More tests => 3; |
23 |
use Test::Mojo; |
23 |
use Test::Mojo; |
24 |
use Test::Warn; |
24 |
use Test::Warn; |
25 |
use Mojo::JWT; |
25 |
use Mojo::JWT; |
Lines 263-305
subtest 'domain endpoint tests' => sub {
Link Here
|
263 |
$schema->storage->txn_rollback; |
263 |
$schema->storage->txn_rollback; |
264 |
}; |
264 |
}; |
265 |
|
265 |
|
266 |
# subtest 'oauth login tests' => sub { |
266 |
subtest 'oauth login tests' => sub { |
267 |
# plan tests => 4; |
267 |
plan tests => 6; |
268 |
|
268 |
|
269 |
# $schema->storage->txn_begin; |
269 |
$schema->storage->txn_begin; |
|
|
270 |
|
271 |
Koha::Auth::Identity::Provider::Domains->delete; |
272 |
Koha::Auth::Identity::Providers->delete; |
273 |
|
274 |
my ( $borrowernumber, $session_id ) = create_user_and_session({ authorized => 1 }); |
275 |
|
276 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
277 |
|
278 |
# Build provider |
279 |
my $tx = $t->ua->build_tx( POST => "/api/v1/auth/identity_providers", json => $oauth_provider_data ); |
280 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
281 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
270 |
|
282 |
|
271 |
# Koha::Auth::Identity::Provider::Domains->delete; |
283 |
$t->request_ok($tx); |
272 |
# Koha::Auth::Identity::Providers->delete; |
284 |
my $provider_id = $t->tx->res->json->{identity_provider_id}; |
273 |
|
285 |
|
274 |
# my ( $borrowernumber, $session_id ) = create_user_and_session({ authorized => 1 }); |
286 |
# Build domain |
|
|
287 |
$tx = $t->ua->build_tx( POST => "/api/v1/auth/identity_providers/$provider_id/domains", json => $domain_not_matching ); |
288 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
289 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
275 |
|
290 |
|
276 |
# my $t = Test::Mojo->new('Koha::REST::V1'); |
291 |
$t->request_ok($tx); |
277 |
|
292 |
|
278 |
# # Build provider |
293 |
t::lib::Mocks::mock_preference( 'RESTPublicAPI', 1 ); |
279 |
# my $tx = $t->ua->build_tx( POST => "/api/v1/auth/identity_providers", json => $oauth_provider_data ); |
|
|
280 |
# $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
281 |
# $tx->req->env( { REMOTE_ADDR => $remote_address } ); |
282 |
|
294 |
|
283 |
# $t->request_ok($tx); |
295 |
# Simulate server restart |
284 |
# my $provider_id = $t->tx->res->json->{identity_provider_id}; |
296 |
$t = Test::Mojo->new('Koha::REST::V1'); |
285 |
|
297 |
|
286 |
# # Build domain |
298 |
$tx = $t->ua->build_tx(GET => "/api/v1/public/oauth/login/oauth_test/opac"); |
287 |
# $tx = $t->ua->build_tx( POST => "/api/v1/auth/identity_providers/$provider_id/domains", json => $domain_not_matching ); |
299 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
288 |
# $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
300 |
$t->request_ok($tx) |
289 |
# $tx->req->env( { REMOTE_ADDR => $remote_address } ); |
301 |
->status_is(302); |
290 |
|
302 |
|
291 |
# $t->request_ok($tx); |
303 |
my $state = URI->new($t->tx->res->headers->location)->query_param("state"); |
292 |
|
304 |
|
293 |
# t::lib::Mocks::mock_preference( 'RESTPublicAPI', 1 ); |
305 |
C4::Context->_new_userenv('DUMMY SESSION'); |
|
|
306 |
C4::Context->set_userenv(0,42,0,'firstname','surname', 'CPL', 'Library 1', 0, ''); |
294 |
|
307 |
|
295 |
# # Simulate server restart |
308 |
$tx = $t->ua->build_tx(GET => "/api/v1/public/oauth/login/oauth_test/opac?code=code&state=$state"); |
296 |
# $t = Test::Mojo->new('Koha::REST::V1'); |
309 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
|
|
310 |
$t->request_ok($tx); |
311 |
|
312 |
my $error = URI->new($t->tx->res->headers->location)->query_param("auth_error"); |
313 |
isnt($error, "wrong_csrf_token", "CRSF token is recognized even when another user is logged in."); |
297 |
|
314 |
|
298 |
# #$t->ua->max_redirects(10); |
315 |
$schema->storage->txn_rollback; |
299 |
# $t->get_ok("/api/v1/public/oauth/login/oauth_test/opac") |
316 |
}; |
300 |
# ->status_is(302); |
|
|
301 |
# $schema->storage->txn_rollback; |
302 |
# }; |
303 |
|
317 |
|
304 |
sub create_user_and_session { |
318 |
sub create_user_and_session { |
305 |
|
319 |
|
306 |
- |
|
|