Bugzilla – Attachment 105844 Details for
Bug 24003
REST API should set C4::Context->userenv
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24003: Regression tests
Bug-24003-Regression-tests.patch (text/plain), 5.28 KB, created by
Martin Renvoize (ashimema)
on 2020-06-12 15:46:00 UTC
(
hide
)
Description:
Bug 24003: Regression tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-06-12 15:46:00 UTC
Size:
5.28 KB
patch
obsolete
>From f09286a20472169c563a09202c95522817c0f049 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 5 Jun 2020 09:15:19 -0300 >Subject: [PATCH] Bug 24003: Regression tests > >This patch adds regression tests for the different authentication >mechanisms Koha supports. It highlights the fact that Koha expects >userenv to be set on authentication. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > .../api/v1/auth_authenticate_api_request.t | 32 +++++++++++++++---- > t/db_dependent/api/v1/auth_basic.t | 19 ++++++++++- > 2 files changed, 43 insertions(+), 8 deletions(-) > >diff --git a/t/db_dependent/api/v1/auth_authenticate_api_request.t b/t/db_dependent/api/v1/auth_authenticate_api_request.t >index de8578bfe0..5bb68d2570 100755 >--- a/t/db_dependent/api/v1/auth_authenticate_api_request.t >+++ b/t/db_dependent/api/v1/auth_authenticate_api_request.t >@@ -44,7 +44,7 @@ t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' ); > subtest 'token-based tests' => sub { > > if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) { >- plan tests => 12; >+ plan tests => 14; > } > else { > plan skip_all => 'Net::OAuth2::AuthorizationServer not available'; >@@ -74,22 +74,30 @@ subtest 'token-based tests' => sub { > > my $access_token = $t->tx->res->json->{access_token}; > >- # With access token and permissions, it returns 200 >- #$patron->flags(2**4)->store; >- > my $stash; >+ my $interface; >+ my $userenv; > > my $tx = $t->ua->build_tx(GET => '/api/v1/acquisitions/orders'); > $tx->req->headers->authorization("Bearer $access_token"); > $tx->req->headers->header( 'x-koha-embed' => 'fund' ); > >- $t->app->hook(after_dispatch => sub { $stash = shift->stash }); >+ $t->app->hook(after_dispatch => sub { >+ $stash = shift->stash; >+ $interface = C4::Context->interface; >+ $userenv = C4::Context->userenv; >+ }); >+ >+ # With access token and permissions, it returns 200 >+ #$patron->flags(2**4)->store; > $t->request_ok($tx)->status_is(200); > > my $user = $stash->{'koha.user'}; > ok( defined $user, 'The \'koha.user\' object is defined in the stash') and > is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and > is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' ); >+ is( $userenv->{number}, $patron->borrowernumber, 'userenv set correctly' ); >+ is( $interface, 'api', "Interface correctly set to \'api\'" ); > > my $embed = $stash->{'koha.embed'}; > ok( defined $embed, 'The embed hashref is generated and stashed' ); >@@ -100,7 +108,7 @@ subtest 'token-based tests' => sub { > > subtest 'cookie-based tests' => sub { > >- plan tests => 6; >+ plan tests => 8; > > $schema->storage->txn_begin; > >@@ -111,13 +119,23 @@ subtest 'cookie-based tests' => sub { > $tx->req->env( { REMOTE_ADDR => $remote_address } ); > > my $stash; >- $t->app->hook(after_dispatch => sub { $stash = shift->stash }); >+ my $interface; >+ my $userenv; >+ >+ $t->app->hook(after_dispatch => sub { >+ $stash = shift->stash; >+ $interface = C4::Context->interface; >+ $userenv = C4::Context->userenv; >+ }); >+ > $t->request_ok($tx)->status_is(200); > > my $user = $stash->{'koha.user'}; > ok( defined $user, 'The \'koha.user\' object is defined in the stash') and > is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and > is( $user->borrowernumber, $borrowernumber, 'The stashed user is the right one' ); >+ is( $userenv->{number}, $borrowernumber, 'userenv set correctly' ); >+ is( $interface, 'api', "Interface correctly set to \'api\'" ); > > subtest 'logged-out tests' => sub { > plan tests => 3; >diff --git a/t/db_dependent/api/v1/auth_basic.t b/t/db_dependent/api/v1/auth_basic.t >index ca5bb67214..49fdfe93d2 100644 >--- a/t/db_dependent/api/v1/auth_basic.t >+++ b/t/db_dependent/api/v1/auth_basic.t >@@ -30,7 +30,7 @@ my $t = Test::Mojo->new('Koha::REST::V1'); > > subtest 'success tests' => sub { > >- plan tests => 5; >+ plan tests => 10; > > $schema->storage->txn_begin; > >@@ -43,9 +43,26 @@ subtest 'success tests' => sub { > $patron->set_password({ password => $password }); > my $userid = $patron->userid; > >+ my $stash; >+ my $interface; >+ my $userenv; >+ >+ $t->app->hook(after_dispatch => sub { >+ $stash = shift->stash; >+ $interface = C4::Context->interface; >+ $userenv = C4::Context->userenv; >+ }); >+ > $t->get_ok("//$userid:$password@/api/v1/patrons") > ->status_is( 200, 'Successful authentication and permissions check' ); > >+ my $user = $stash->{'koha.user'}; >+ ok( defined $user, 'The \'koha.user\' object is defined in the stash') and >+ is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and >+ is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' ); >+ is( $userenv->{number}, $patron->borrowernumber, 'userenv set correctly' ); >+ is( $interface, 'api', "Interface correctly set to \'api\'" ); >+ > $patron->flags(undef)->store; > > $t->get_ok("//$userid:$password@/api/v1/patrons") >-- >2.20.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 24003
:
95228
|
95230
|
105579
|
105580
|
105581
|
105586
|
105587
|
105588
|
105633
|
105634
|
105635
|
105666
| 105844 |
105845
|
105846
|
105847
|
106087
|
106088
|
106089
|
106090