Bugzilla – Attachment 143236 Details for
Bug 31378
Add a generic OAuth2/OIDC client implementation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31378: (QA follow-up) Tidy tests
Bug-31378-QA-follow-up-Tidy-tests.patch (text/plain), 31.79 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-11-04 15:02:02 UTC
(
hide
)
Description:
Bug 31378: (QA follow-up) Tidy tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-11-04 15:02:02 UTC
Size:
31.79 KB
patch
obsolete
>From 2ee1a54ff55dadea78ec473eac6ec3d9570e9cfa Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 4 Nov 2022 11:20:50 -0300 >Subject: [PATCH] Bug 31378: (QA follow-up) Tidy tests > >This patch perltidys the tests added lately. It also removes some >commented debugging lines. > >Note: There's an attempt to write tests on the full auth workflow that >is commented out but left there on purpose for now. >--- > t/db_dependent/Koha/Auth/Client.t | 260 +++++++++++++------------ > t/db_dependent/api/v1/idp.t | 314 ++++++++++++++---------------- > 2 files changed, 285 insertions(+), 289 deletions(-) > >diff --git a/t/db_dependent/Koha/Auth/Client.t b/t/db_dependent/Koha/Auth/Client.t >index 972fb626ea2..7f97e8295c8 100755 >--- a/t/db_dependent/Koha/Auth/Client.t >+++ b/t/db_dependent/Koha/Auth/Client.t >@@ -38,142 +38,152 @@ my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > > subtest 'get_user() tests' => sub { >- plan tests => 4; >- >- $schema->storage->txn_begin; >- >- my $client = Koha::Auth::Client::OAuth->new; >- my $provider = $builder->build_object( { class => 'Koha::Auth::Identity::Providers', value => { matchpoint => 'email' } } ); >- my $domain = $builder->build_object( { class => 'Koha::Auth::Identity::Provider::Domains', value => { identity_provider_id => $provider->id, domain => '', update_on_auth => 0, allow_opac => 1, allow_staff => 0 } } ); >- my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { email => 'patron@test.com' } } ); >- my $mapping = { >- email => 'electronic_mail', >- firstname => 'given_name', >- surname => 'family_name' >- }; >- $provider->set_mapping($mapping)->store; >- >- my $id_token = 'header.'.encode_base64url(encode_json({ >- electronic_mail => 'patron@test.com', >- given_name => 'test name' >- })).'.footer'; >- >- my $data = { >- id_token => $id_token >- }; >- >- my ($resolved_patron, $mapped_data, $resolved_domain) = $client->get_user({ provider => $provider->code, data => $data, interface => 'opac' }); >- is_deeply( $resolved_patron->to_api, $patron->to_api, 'Patron correctly retrieved' ); >- is( $mapped_data->{firstname}, 'test name', 'Data mapped correctly' ); >- is( $mapped_data->{surname}, undef, 'No surname mapped'); >- is( $domain->identity_provider_domain_id, $resolved_domain->identity_provider_domain_id, 'Is the same domain'); >- >- $schema->storage->txn_rollback; >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $client = Koha::Auth::Client::OAuth->new; >+ my $provider = $builder->build_object( { class => 'Koha::Auth::Identity::Providers', value => { matchpoint => 'email' } } ); >+ my $domain = $builder->build_object( >+ { class => 'Koha::Auth::Identity::Provider::Domains', >+ value => { identity_provider_id => $provider->id, domain => '', update_on_auth => 0, allow_opac => 1, allow_staff => 0 } >+ } >+ ); >+ my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { email => 'patron@test.com' } } ); >+ my $mapping = { >+ email => 'electronic_mail', >+ firstname => 'given_name', >+ surname => 'family_name' >+ }; >+ $provider->set_mapping($mapping)->store; >+ >+ my $id_token = 'header.' >+ . encode_base64url( >+ encode_json( >+ { electronic_mail => 'patron@test.com', >+ given_name => 'test name' >+ } >+ ) >+ ) . '.footer'; >+ >+ my $data = { id_token => $id_token }; >+ >+ my ( $resolved_patron, $mapped_data, $resolved_domain ) = $client->get_user( { provider => $provider->code, data => $data, interface => 'opac' } ); >+ is_deeply( $resolved_patron->to_api, $patron->to_api, 'Patron correctly retrieved' ); >+ is( $mapped_data->{firstname}, 'test name', 'Data mapped correctly' ); >+ is( $mapped_data->{surname}, undef, 'No surname mapped' ); >+ is( $domain->identity_provider_domain_id, $resolved_domain->identity_provider_domain_id, 'Is the same domain' ); >+ >+ $schema->storage->txn_rollback; > > }; > > subtest 'get_valid_domain_config() tests' => sub { >- plan tests => 10; >- >- $schema->storage->txn_begin; >- >- my $client = Koha::Auth::Client->new; >- my $provider = $builder->build_object( { class => 'Koha::Auth::Identity::Providers', value => { matchpoint => 'email' } } ); >- my $domain1 = $builder->build_object( { class => 'Koha::Auth::Identity::Provider::Domains', value => { identity_provider_id => $provider->id, domain => '', allow_opac => 0, allow_staff => 0 } } ); >- my $domain2 = $builder->build_object( { class => 'Koha::Auth::Identity::Provider::Domains', value => { identity_provider_id => $provider->id, domain => '*library.com', allow_opac => 1, allow_staff => 0 } } ); >- my $domain3 = $builder->build_object( { class => 'Koha::Auth::Identity::Provider::Domains', value => { identity_provider_id => $provider->id, domain => '*.library.com', allow_opac => 1, allow_staff => 0 } } ); >- my $domain4 = $builder->build_object( { class => 'Koha::Auth::Identity::Provider::Domains', value => { identity_provider_id => $provider->id, domain => 'student.library.com', allow_opac => 1, allow_staff => 0 } } ); >- my $domain5 = $builder->build_object( { class => 'Koha::Auth::Identity::Provider::Domains', value => { identity_provider_id => $provider->id, domain => 'staff.library.com', allow_opac => 1, allow_staff => 1 } } ); >- >- my $retrieved_domain; >- >- # Test @gmail.com >- $retrieved_domain = $client->get_valid_domain_config({ provider => $provider, email => 'user@gmail.com', interface => 'opac'}); >- is($retrieved_domain, undef, 'gmail user cannot enter opac'); >- $retrieved_domain = $client->get_valid_domain_config({ provider => $provider, email => 'user@gmail.com', interface => 'staff'}); >- is($retrieved_domain, undef, 'gmail user cannot enter staff'); >- >- # Test @otherlibrary.com >- $retrieved_domain = $client->get_valid_domain_config({ provider => $provider, email => 'user@otherlibrary.com', interface => 'opac'}); >- is($retrieved_domain->identity_provider_domain_id, $domain2->identity_provider_domain_id, 'otherlibaray user can enter opac with domain2'); >- $retrieved_domain = $client->get_valid_domain_config({ provider => $provider, email => 'user@otherlibrary.com', interface => 'staff'}); >- is($retrieved_domain, undef, 'otherlibrary user cannot enter staff'); >- >- # Test @provider.library.com >- $retrieved_domain = $client->get_valid_domain_config({ provider => $provider, email => 'user@provider.library.com', interface => 'opac'}); >- is($retrieved_domain->identity_provider_domain_id, $domain3->identity_provider_domain_id, 'provider.library user can enter opac with domain3'); >- $retrieved_domain = $client->get_valid_domain_config({ provider => $provider, email => 'user@provider.library.com', interface => 'staff'}); >- is($retrieved_domain, undef, 'provider.library user cannot enter staff'); >- >- # Test @student.library.com >- $retrieved_domain = $client->get_valid_domain_config({ provider => $provider, email => 'user@student.library.com', interface => 'opac'}); >- is($retrieved_domain->identity_provider_domain_id, $domain4->identity_provider_domain_id, 'student.library user can enter opac with domain4'); >- $retrieved_domain = $client->get_valid_domain_config({ provider => $provider, email => 'user@student.library.com', interface => 'staff'}); >- is($retrieved_domain, undef, 'student.library user cannot enter staff'); >- >- # Test @staff.library.com >- $retrieved_domain = $client->get_valid_domain_config({ provider => $provider, email => 'user@staff.library.com', interface => 'opac'}); >- is($retrieved_domain->identity_provider_domain_id, $domain5->identity_provider_domain_id, 'staff.library user can enter opac with domain5'); >- $retrieved_domain = $client->get_valid_domain_config({ provider => $provider, email => 'user@staff.library.com', interface => 'staff'}); >- is($retrieved_domain->identity_provider_domain_id, $domain5->identity_provider_domain_id, 'staff.library user can enter staff with domain5'); >- >- $schema->storage->txn_rollback; >+ plan tests => 10; >+ >+ $schema->storage->txn_begin; >+ >+ my $client = Koha::Auth::Client->new; >+ my $provider = $builder->build_object( { class => 'Koha::Auth::Identity::Providers', value => { matchpoint => 'email' } } ); >+ my $domain1 = $builder->build_object( >+ { class => 'Koha::Auth::Identity::Provider::Domains', value => { identity_provider_id => $provider->id, domain => '', allow_opac => 0, allow_staff => 0 } } ); >+ my $domain2 = $builder->build_object( >+ { class => 'Koha::Auth::Identity::Provider::Domains', value => { identity_provider_id => $provider->id, domain => '*library.com', allow_opac => 1, allow_staff => 0 } } ); >+ my $domain3 = $builder->build_object( >+ { class => 'Koha::Auth::Identity::Provider::Domains', value => { identity_provider_id => $provider->id, domain => '*.library.com', allow_opac => 1, allow_staff => 0 } } >+ ); >+ my $domain4 = $builder->build_object( >+ { class => 'Koha::Auth::Identity::Provider::Domains', >+ value => { identity_provider_id => $provider->id, domain => 'student.library.com', allow_opac => 1, allow_staff => 0 } >+ } >+ ); >+ my $domain5 = $builder->build_object( >+ { class => 'Koha::Auth::Identity::Provider::Domains', >+ value => { identity_provider_id => $provider->id, domain => 'staff.library.com', allow_opac => 1, allow_staff => 1 } >+ } >+ ); >+ >+ my $retrieved_domain; >+ >+ # Test @gmail.com >+ $retrieved_domain = $client->get_valid_domain_config( { provider => $provider, email => 'user@gmail.com', interface => 'opac' } ); >+ is( $retrieved_domain, undef, 'gmail user cannot enter opac' ); >+ $retrieved_domain = $client->get_valid_domain_config( { provider => $provider, email => 'user@gmail.com', interface => 'staff' } ); >+ is( $retrieved_domain, undef, 'gmail user cannot enter staff' ); >+ >+ # Test @otherlibrary.com >+ $retrieved_domain = $client->get_valid_domain_config( { provider => $provider, email => 'user@otherlibrary.com', interface => 'opac' } ); >+ is( $retrieved_domain->identity_provider_domain_id, $domain2->identity_provider_domain_id, 'otherlibaray user can enter opac with domain2' ); >+ $retrieved_domain = $client->get_valid_domain_config( { provider => $provider, email => 'user@otherlibrary.com', interface => 'staff' } ); >+ is( $retrieved_domain, undef, 'otherlibrary user cannot enter staff' ); >+ >+ # Test @provider.library.com >+ $retrieved_domain = $client->get_valid_domain_config( { provider => $provider, email => 'user@provider.library.com', interface => 'opac' } ); >+ is( $retrieved_domain->identity_provider_domain_id, $domain3->identity_provider_domain_id, 'provider.library user can enter opac with domain3' ); >+ $retrieved_domain = $client->get_valid_domain_config( { provider => $provider, email => 'user@provider.library.com', interface => 'staff' } ); >+ is( $retrieved_domain, undef, 'provider.library user cannot enter staff' ); >+ >+ # Test @student.library.com >+ $retrieved_domain = $client->get_valid_domain_config( { provider => $provider, email => 'user@student.library.com', interface => 'opac' } ); >+ is( $retrieved_domain->identity_provider_domain_id, $domain4->identity_provider_domain_id, 'student.library user can enter opac with domain4' ); >+ $retrieved_domain = $client->get_valid_domain_config( { provider => $provider, email => 'user@student.library.com', interface => 'staff' } ); >+ is( $retrieved_domain, undef, 'student.library user cannot enter staff' ); >+ >+ # Test @staff.library.com >+ $retrieved_domain = $client->get_valid_domain_config( { provider => $provider, email => 'user@staff.library.com', interface => 'opac' } ); >+ is( $retrieved_domain->identity_provider_domain_id, $domain5->identity_provider_domain_id, 'staff.library user can enter opac with domain5' ); >+ $retrieved_domain = $client->get_valid_domain_config( { provider => $provider, email => 'user@staff.library.com', interface => 'staff' } ); >+ is( $retrieved_domain->identity_provider_domain_id, $domain5->identity_provider_domain_id, 'staff.library user can enter staff with domain5' ); >+ >+ $schema->storage->txn_rollback; > }; > > subtest 'has_valid_domain_config() tests' => sub { >- plan tests => 2; >- $schema->storage->txn_begin; >+ plan tests => 2; >+ $schema->storage->txn_begin; > >- my $client = Koha::Auth::Client->new; >- my $provider = $builder->build_object( { class => 'Koha::Auth::Identity::Providers', value => { matchpoint => 'email' } } ); >- my $domain1 = $builder->build_object( { class => 'Koha::Auth::Identity::Provider::Domains', value => { identity_provider_id => $provider->id, domain => '', allow_opac => 1, allow_staff => 0 } } ); >+ my $client = Koha::Auth::Client->new; >+ my $provider = $builder->build_object( { class => 'Koha::Auth::Identity::Providers', value => { matchpoint => 'email' } } ); >+ my $domain1 = $builder->build_object( >+ { class => 'Koha::Auth::Identity::Provider::Domains', value => { identity_provider_id => $provider->id, domain => '', allow_opac => 1, allow_staff => 0 } } ); > >- # Test @gmail.com >- my $retrieved_domain = $client->has_valid_domain_config({ provider => $provider, email => 'user@gmail.com', interface => 'opac'}); >- is($retrieved_domain->identity_provider_domain_id, $domain1->identity_provider_domain_id, 'gmail user can enter opac with domain1'); >- throws_ok { $client->has_valid_domain_config({ provider => $provider, email => 'user@gmail.com', interface => 'staff'}) } 'Koha::Exceptions::Auth::NoValidDomain', 'gmail user cannot enter staff'; >+ # Test @gmail.com >+ my $retrieved_domain = $client->has_valid_domain_config( { provider => $provider, email => 'user@gmail.com', interface => 'opac' } ); >+ is( $retrieved_domain->identity_provider_domain_id, $domain1->identity_provider_domain_id, 'gmail user can enter opac with domain1' ); >+ throws_ok { $client->has_valid_domain_config( { provider => $provider, email => 'user@gmail.com', interface => 'staff' } ) } 'Koha::Exceptions::Auth::NoValidDomain', >+ 'gmail user cannot enter staff'; > >- $schema->storage->txn_rollback; >+ $schema->storage->txn_rollback; > }; > > subtest '_traverse_hash() tests' => sub { >- plan tests => 3; >- >- my $client = Koha::Auth::Client->new; >- >- my $hash = { >- a => { >- hash => { >- with => 'complicated structure' >- } >- }, >- an => { >- array => [ >- { >- inside => 'a hash' >- }, >- { >- inside => 'second element' >+ plan tests => 3; >+ >+ my $client = Koha::Auth::Client->new; >+ >+ my $hash = { >+ a => { hash => { with => 'complicated structure' } }, >+ an => { array => [ { inside => 'a hash' }, { inside => 'second element' } ] } >+ }; >+ >+ my $first_result = $client->_traverse_hash( >+ { base => $hash, >+ keys => 'a.hash.with' >+ } >+ ); >+ is( $first_result, 'complicated structure', 'get the value within a hash structure' ); >+ >+ my $second_result = $client->_traverse_hash( >+ { base => $hash, >+ keys => 'an.array.0.inside' > } >- ] >- } >- }; >- >- my $first_result = $client->_traverse_hash({ >- base => $hash, >- keys => 'a.hash.with' >- }); >- is($first_result, 'complicated structure', 'get the value within a hash structure'); >- >- my $second_result = $client->_traverse_hash({ >- base => $hash, >- keys => 'an.array.0.inside' >- }); >- is($second_result, 'a hash', 'get the value of the first element of an array within a hash structure'); >- >- my $third_result = $client->_traverse_hash({ >- base => $hash, >- keys => 'an.array.1.inside' >- }); >- is($third_result, 'second element', 'get the value of the second element of an array within a hash structure'); >-}; >\ No newline at end of file >+ ); >+ is( $second_result, 'a hash', 'get the value of the first element of an array within a hash structure' ); >+ >+ my $third_result = $client->_traverse_hash( >+ { base => $hash, >+ keys => 'an.array.1.inside' >+ } >+ ); >+ is( $third_result, 'second element', 'get the value of the second element of an array within a hash structure' ); >+}; >diff --git a/t/db_dependent/api/v1/idp.t b/t/db_dependent/api/v1/idp.t >index 6dfbbcf4d9e..c67b5124e00 100755 >--- a/t/db_dependent/api/v1/idp.t >+++ b/t/db_dependent/api/v1/idp.t >@@ -46,230 +46,221 @@ my $remote_address = '127.0.0.1'; > > # my $idp_port = t::lib::IdP::ExternalIdP->start; > >- > my $oauth_provider_data = { >- code => 'oauth_test', >- description => 'OAuth provider', >- protocol => 'OAuth', >- mapping => { >+ code => 'oauth_test', >+ description => 'OAuth provider', >+ protocol => 'OAuth', >+ mapping => { > email => 'users.0.email', > firstname => 'users.0.custom_name', > surname => 'users.0.custom_surname', > userid => 'users.0.id' >- }, >- matchpoint => 'email', >- config => { >- authorize_url => "/idp/test/authorization_endpoint", >- token_url => "/idp/test/token_endpoint/without_id_token", >- userinfo_url => "/idp/test/userinfo_endpoint", >- key => "client_id", >- secret => "client_secret" >- } >+ }, >+ matchpoint => 'email', >+ config => { >+ authorize_url => "/idp/test/authorization_endpoint", >+ token_url => "/idp/test/token_endpoint/without_id_token", >+ userinfo_url => "/idp/test/userinfo_endpoint", >+ key => "client_id", >+ secret => "client_secret" >+ } > }; > > my $oidc_with_email_provider_data = { >- code => 'oidc_email', >- description => 'OIDC with email provider', >- protocol => 'OIDC', >- mapping => { >- email => 'email', >- firstname => 'given_name', >- surname => 'family_name', >- userid => 'sub' >- }, >- matchpoint => 'email', >- config => { >- authorize_url => "/idp/test/authorization_endpoint", >- well_known_url => "/idp/test/with_email/.well_known", >- key => "client_id", >- secret => "client_secret" >- } >+ code => 'oidc_email', >+ description => 'OIDC with email provider', >+ protocol => 'OIDC', >+ mapping => { >+ email => 'email', >+ firstname => 'given_name', >+ surname => 'family_name', >+ userid => 'sub' >+ }, >+ matchpoint => 'email', >+ config => { >+ authorize_url => "/idp/test/authorization_endpoint", >+ well_known_url => "/idp/test/with_email/.well_known", >+ key => "client_id", >+ secret => "client_secret" >+ } > }; > > my $oidc_without_email_provider_data = { >- code => 'oidc_no_email', >- description => 'OIDC without email provider', >- protocol => 'OIDC', >- mapping => { >- email => 'users.0.email', >- firstname => 'given_name', >- surname => 'family_name', >- userid => 'sub' >- }, >- matchpoint => 'email', >- config => { >- authorize_url => "/idp/test/authorization_endpoint", >- well_known_url => "/idp/test/without_email/.well_known", >- key => "client_id", >- secret => "client_secret" >- } >+ code => 'oidc_no_email', >+ description => 'OIDC without email provider', >+ protocol => 'OIDC', >+ mapping => { >+ email => 'users.0.email', >+ firstname => 'given_name', >+ surname => 'family_name', >+ userid => 'sub' >+ }, >+ matchpoint => 'email', >+ config => { >+ authorize_url => "/idp/test/authorization_endpoint", >+ well_known_url => "/idp/test/without_email/.well_known", >+ key => "client_id", >+ secret => "client_secret" >+ } > }; > > my $domain_not_matching = { >- domain => 'gmail.com', >- auto_register => 0, >- update_on_auth => 0, >- default_library_id => undef, >- default_category_id => undef, >- allow_opac => 1, >- allow_staff => 0 >+ domain => 'gmail.com', >+ auto_register => 0, >+ update_on_auth => 0, >+ default_library_id => undef, >+ default_category_id => undef, >+ allow_opac => 1, >+ allow_staff => 0 > }; > > my $domain_no_register = { >- domain => 'some.library.com', >- auto_register => 0, >- update_on_auth => 0, >- default_library_id => undef, >- default_category_id => undef, >- allow_opac => 1, >- allow_staff => 0 >+ domain => 'some.library.com', >+ auto_register => 0, >+ update_on_auth => 0, >+ default_library_id => undef, >+ default_category_id => undef, >+ allow_opac => 1, >+ allow_staff => 0 > }; > >-my $library = $builder->build_object({class => 'Koha::Libraries'}); >-my $category = $builder->build_object({class => 'Koha::Patron::Categories'}); >+my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+my $category = $builder->build_object( { class => 'Koha::Patron::Categories' } ); > > my $domain_register = { >- domain => 'some.library.com', >- auto_register => 1, >- update_on_auth => 0, >- default_library_id => $library->branchcode, >- default_category_id => $category->categorycode, >- allow_opac => 1, >- allow_staff => 1 >+ domain => 'some.library.com', >+ auto_register => 1, >+ update_on_auth => 0, >+ default_library_id => $library->branchcode, >+ default_category_id => $category->categorycode, >+ allow_opac => 1, >+ allow_staff => 1 > }; > > my $domain_register_update = { >- domain => 'some.library.com', >- auto_register => 1, >- update_on_auth => 1, >- default_library_id => $library->branchcode, >- default_category_id => $category->categorycode, >- allow_opac => 1, >- allow_staff => 0 >+ domain => 'some.library.com', >+ auto_register => 1, >+ update_on_auth => 1, >+ default_library_id => $library->branchcode, >+ default_category_id => $category->categorycode, >+ allow_opac => 1, >+ allow_staff => 0 > }; > > subtest 'provider endpoint tests' => sub { >- plan tests => 12; >+ plan tests => 12; > >- $schema->storage->txn_begin; >+ $schema->storage->txn_begin; > >- Koha::Auth::Identity::Provider::Domains->delete; >- Koha::Auth::Identity::Providers->delete; >+ Koha::Auth::Identity::Provider::Domains->delete; >+ Koha::Auth::Identity::Providers->delete; > >- my ( $borrowernumber, $session_id ) = create_user_and_session({ authorized => 1 }); >+ my ( $borrowernumber, $session_id ) = create_user_and_session( { authorized => 1 } ); > >- my $t = Test::Mojo->new('Koha::REST::V1'); >+ my $t = Test::Mojo->new('Koha::REST::V1'); > >- my $tx = $t->ua->build_tx( POST => "/api/v1/auth/identity_providers", json => $oauth_provider_data ); >- $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >- $tx->req->env( { REMOTE_ADDR => $remote_address } ); >+ my $tx = $t->ua->build_tx( POST => "/api/v1/auth/identity_providers", json => $oauth_provider_data ); >+ $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >+ $tx->req->env( { REMOTE_ADDR => $remote_address } ); > >- $t->request_ok($tx) >- ->status_is(201); >+ $t->request_ok($tx)->status_is(201); > >- my $provider = Koha::Auth::Identity::Providers->search({code => 'oauth_test'})->next; >- is ($provider->code, 'oauth_test', 'Provider was created'); >+ my $provider = Koha::Auth::Identity::Providers->search( { code => 'oauth_test' } )->next; >+ is( $provider->code, 'oauth_test', 'Provider was created' ); > >- $tx = $t->ua->build_tx( GET => "/api/v1/auth/identity_providers" ); >- $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >- $tx->req->env( { REMOTE_ADDR => $remote_address } ); >+ $tx = $t->ua->build_tx( GET => "/api/v1/auth/identity_providers" ); >+ $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >+ $tx->req->env( { REMOTE_ADDR => $remote_address } ); > >- $t->request_ok($tx) >- ->json_has('/0/code', 'oauth_test'); >+ $t->request_ok($tx)->json_has( '/0/code', 'oauth_test' ); > >- my %modified_provider_data_hash = %{$oauth_provider_data}; >- my $modified_provider_data = \%modified_provider_data_hash; >- $modified_provider_data->{code} = 'some_code'; >+ my %modified_provider_data_hash = %{$oauth_provider_data}; >+ my $modified_provider_data = \%modified_provider_data_hash; >+ $modified_provider_data->{code} = 'some_code'; > >- $tx = $t->ua->build_tx( PUT => "/api/v1/auth/identity_providers/".$provider->identity_provider_id, json => $modified_provider_data); >- $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >- $tx->req->env( { REMOTE_ADDR => $remote_address } ); >+ $tx = $t->ua->build_tx( PUT => "/api/v1/auth/identity_providers/" . $provider->identity_provider_id, json => $modified_provider_data ); >+ $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >+ $tx->req->env( { REMOTE_ADDR => $remote_address } ); > >- $t->request_ok($tx) >- ->status_is(200); >+ $t->request_ok($tx)->status_is(200); > >- $tx = $t->ua->build_tx( GET => "/api/v1/auth/identity_providers/".$provider->identity_provider_id); >- $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >- $tx->req->env( { REMOTE_ADDR => $remote_address } ); >+ $tx = $t->ua->build_tx( GET => "/api/v1/auth/identity_providers/" . $provider->identity_provider_id ); >+ $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >+ $tx->req->env( { REMOTE_ADDR => $remote_address } ); > >- $t->request_ok($tx) >- ->json_has('/code', 'some_code'); >+ $t->request_ok($tx)->json_has( '/code', 'some_code' ); > >- $tx = $t->ua->build_tx( DELETE => "/api/v1/auth/identity_providers/".$provider->identity_provider_id); >- $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >- $tx->req->env( { REMOTE_ADDR => $remote_address } ); >+ $tx = $t->ua->build_tx( DELETE => "/api/v1/auth/identity_providers/" . $provider->identity_provider_id ); >+ $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >+ $tx->req->env( { REMOTE_ADDR => $remote_address } ); > >- $t->request_ok($tx) >- ->status_is(204); >- # p $t->tx->res; >+ $t->request_ok($tx)->status_is(204); > >- $provider = Koha::Auth::Identity::Providers->search->next; >- is ($provider, undef, 'All providers deleted'); >+ $provider = Koha::Auth::Identity::Providers->search->next; >+ is( $provider, undef, 'All providers deleted' ); > >- $schema->storage->txn_rollback; >+ $schema->storage->txn_rollback; > }; > > subtest 'domain endpoint tests' => sub { >- plan tests => 12; > >- $schema->storage->txn_begin; >+ plan tests => 12; > >- Koha::Auth::Identity::Provider::Domains->delete; >- Koha::Auth::Identity::Providers->delete; >+ $schema->storage->txn_begin; > >- my ( $borrowernumber, $session_id ) = create_user_and_session({ authorized => 1 }); >+ Koha::Auth::Identity::Provider::Domains->delete; >+ Koha::Auth::Identity::Providers->delete; > >- my $t = Test::Mojo->new('Koha::REST::V1'); >+ my ( $borrowernumber, $session_id ) = create_user_and_session( { authorized => 1 } ); > >- my $provider = $builder->build_object({class => 'Koha::Auth::Identity::Providers'}); >+ my $t = Test::Mojo->new('Koha::REST::V1'); > >- my $tx = $t->ua->build_tx( POST => "/api/v1/auth/identity_providers/".$provider->identity_provider_id."/domains", json => $domain_not_matching ); >- $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >- $tx->req->env( { REMOTE_ADDR => $remote_address } ); >+ my $provider = $builder->build_object( { class => 'Koha::Auth::Identity::Providers' } ); > >- $t->request_ok($tx) >- ->status_is(201); >+ my $tx = $t->ua->build_tx( POST => "/api/v1/auth/identity_providers/" . $provider->identity_provider_id . "/domains", json => $domain_not_matching ); >+ $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >+ $tx->req->env( { REMOTE_ADDR => $remote_address } ); > >- my $domain = Koha::Auth::Identity::Provider::Domains->search({domain => 'gmail.com'})->next; >- is ($domain->domain, 'gmail.com', 'Provider was created'); >+ $t->request_ok($tx)->status_is(201); > >- $tx = $t->ua->build_tx( GET => "/api/v1/auth/identity_providers/".$provider->identity_provider_id."/domains" ); >- $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >- $tx->req->env( { REMOTE_ADDR => $remote_address } ); >+ my $domain = Koha::Auth::Identity::Provider::Domains->search( { domain => 'gmail.com' } )->next; >+ is( $domain->domain, 'gmail.com', 'Provider was created' ); > >- $t->request_ok($tx) >- ->json_has('/0/domain', 'gmail.com'); >+ $tx = $t->ua->build_tx( GET => "/api/v1/auth/identity_providers/" . $provider->identity_provider_id . "/domains" ); >+ $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >+ $tx->req->env( { REMOTE_ADDR => $remote_address } ); > >- my %modified_domain_data_hash = %{$domain_not_matching}; >- my $modified_domain_data = \%modified_domain_data_hash; >- $modified_domain_data->{domain} = 'some.domain.com'; >+ $t->request_ok($tx)->json_has( '/0/domain', 'gmail.com' ); > >- $tx = $t->ua->build_tx( PUT => "/api/v1/auth/identity_providers/".$provider->identity_provider_id."/domains/".$domain->identity_provider_domain_id, json => $modified_domain_data); >- $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >- $tx->req->env( { REMOTE_ADDR => $remote_address } ); >+ my %modified_domain_data_hash = %{$domain_not_matching}; >+ my $modified_domain_data = \%modified_domain_data_hash; >+ $modified_domain_data->{domain} = 'some.domain.com'; > >- $t->request_ok($tx) >- ->status_is(200); >+ $tx = $t->ua->build_tx( >+ PUT => "/api/v1/auth/identity_providers/" . $provider->identity_provider_id . "/domains/" . $domain->identity_provider_domain_id, >+ json => $modified_domain_data >+ ); >+ $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >+ $tx->req->env( { REMOTE_ADDR => $remote_address } ); > >- $tx = $t->ua->build_tx( GET => "/api/v1/auth/identity_providers/".$provider->identity_provider_id."/domains/".$domain->identity_provider_domain_id); >- $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >- $tx->req->env( { REMOTE_ADDR => $remote_address } ); >+ $t->request_ok($tx)->status_is(200); > >- $t->request_ok($tx) >- ->json_has('/domain', 'some.domain.com'); >+ $tx = $t->ua->build_tx( GET => "/api/v1/auth/identity_providers/" . $provider->identity_provider_id . "/domains/" . $domain->identity_provider_domain_id ); >+ $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >+ $tx->req->env( { REMOTE_ADDR => $remote_address } ); > >- $tx = $t->ua->build_tx( DELETE => "/api/v1/auth/identity_providers/".$provider->identity_provider_id."/domains/".$domain->identity_provider_domain_id); >- $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >- $tx->req->env( { REMOTE_ADDR => $remote_address } ); >+ $t->request_ok($tx)->json_has( '/domain', 'some.domain.com' ); > >- $t->request_ok($tx) >- ->status_is(204); >- # p $t->tx->res; >+ $tx = $t->ua->build_tx( DELETE => "/api/v1/auth/identity_providers/" . $provider->identity_provider_id . "/domains/" . $domain->identity_provider_domain_id ); >+ $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); >+ $tx->req->env( { REMOTE_ADDR => $remote_address } ); > >- $domain = Koha::Auth::Identity::Provider::Domains->search->next; >- is ($domain, undef, 'All domains deleted'); >+ $t->request_ok($tx)->status_is(204); > >- $schema->storage->txn_rollback; >+ $domain = Koha::Auth::Identity::Provider::Domains->search->next; >+ is( $domain, undef, 'All domains deleted' ); >+ >+ $schema->storage->txn_rollback; > }; > > # subtest 'oauth login tests' => sub { >@@ -316,11 +307,8 @@ sub create_user_and_session { > my $flags = ( $args->{authorized} ) ? 1 : 0; > > my $user = $builder->build( >- { >- source => 'Borrower', >- value => { >- flags => $flags >- } >+ { source => 'Borrower', >+ value => { flags => $flags } > } > ); > >@@ -334,5 +322,3 @@ sub create_user_and_session { > > return ( $user->{borrowernumber}, $session->id ); > } >- >-1; >\ No newline at end of file >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31378
:
141362
|
141363
|
141364
|
141365
|
141366
|
141367
|
141368
|
141369
|
141370
|
141371
|
141372
|
141373
|
141374
|
141375
|
141376
|
141377
|
141378
|
141514
|
141771
|
141772
|
141773
|
141774
|
141775
|
141776
|
141777
|
141778
|
141779
|
141780
|
141781
|
141782
|
141783
|
141784
|
141785
|
141786
|
141787
|
141788
|
141801
|
141802
|
141803
|
141804
|
141805
|
141806
|
141807
|
141808
|
141809
|
141810
|
141811
|
141812
|
141813
|
141814
|
141815
|
141816
|
141817
|
141818
|
141853
|
143056
|
143087
|
143088
|
143089
|
143090
|
143091
|
143092
|
143093
|
143094
|
143095
|
143096
|
143097
|
143098
|
143099
|
143100
|
143101
|
143102
|
143103
|
143104
|
143105
|
143106
|
143107
|
143186
|
143187
|
143188
|
143189
|
143190
|
143191
|
143192
|
143193
|
143194
|
143195
|
143196
|
143197
|
143198
|
143199
|
143200
|
143202
|
143204
|
143205
|
143206
|
143207
|
143208
|
143215
|
143216
|
143217
|
143218
|
143219
|
143220
|
143221
|
143222
|
143223
|
143224
|
143225
|
143226
|
143227
|
143228
|
143229
|
143230
|
143231
|
143232
|
143233
|
143234
|
143235
|
143236
|
143266
|
143267
|
143268
|
143269
|
143270
|
143271
|
143272
|
143273
|
143274
|
143275
|
143277
|
143278
|
143279
|
143280
|
143281
|
143282
|
143283
|
143284
|
143285
|
143286
|
143287
|
143288
|
143396
|
143397
|
143398
|
143399
|
143400
|
143401
|
143402
|
143403
|
143404
|
143405
|
143406
|
143407
|
143408
|
143409
|
143410
|
143411
|
143412
|
143413
|
143414
|
143415
|
143416
|
143417
|
143418
|
143420
|
143421
|
143422
|
143423
|
143424
|
143425
|
143426
|
143427
|
143428
|
143429
|
143430
|
143431
|
143432
|
143433
|
143434
|
143435
|
143436
|
143437
|
143438
|
143439
|
143440
|
143441
|
143442
|
143443
|
143450
|
144071
|
144175