Bugzilla – Attachment 164256 Details for
Bug 36420
REST API Basic Auth does not support cardnumbers, only userid
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36420: Unit tests
Bug-36420-Unit-tests.patch (text/plain), 5.01 KB, created by
Nick Clemens (kidclamp)
on 2024-04-02 11:26:03 UTC
(
hide
)
Description:
Bug 36420: Unit tests
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-04-02 11:26:03 UTC
Size:
5.01 KB
patch
obsolete
>From 26562cd969f47f1b9e99d74cc6054f961f7e967a Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 27 Mar 2024 12:00:48 +0000 >Subject: [PATCH] Bug 36420: Unit tests > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > t/db_dependent/api/v1/auth_basic.t | 84 +++++++++++++++++++++--------- > 1 file changed, 59 insertions(+), 25 deletions(-) > >diff --git a/t/db_dependent/api/v1/auth_basic.t b/t/db_dependent/api/v1/auth_basic.t >index 78c75720410..808dc31bb9b 100755 >--- a/t/db_dependent/api/v1/auth_basic.t >+++ b/t/db_dependent/api/v1/auth_basic.t >@@ -32,7 +32,7 @@ my $t = Test::Mojo->new('Koha::REST::V1'); > > subtest 'success tests' => sub { > >- plan tests => 10; >+ plan tests => 2; > > $schema->storage->txn_begin; > >@@ -40,39 +40,73 @@ subtest 'success tests' => sub { > > my $password = 'AbcdEFG123'; > >- my $patron = $builder->build_object( >- { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 2**4 } } ); >- $patron->set_password({ password => $password }); >- my $userid = $patron->userid; >+ my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { userid => 'tomasito' } } ); >+ $patron->set_password( { password => $password } ); >+ >+ my $userid = $patron->userid; >+ my $cardnumber = $patron->cardnumber; > > my $stash; > my $interface; > my $userenv; > >- $t->app->hook(after_dispatch => sub { >- $stash = shift->stash; >- $interface = C4::Context->interface; >- $userenv = C4::Context->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' ); >+ subtest '`userid` login' => sub { > >- 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\'" ); >+ plan tests => 10; > >- $patron->flags(undef)->store; >+ $patron->flags( 2**4 )->store; > >- $t->get_ok("//$userid:$password@/api/v1/patrons") >- ->status_is( 403, 'Successful authentication and not enough permissions' ) >- ->json_is( >- '/error' => 'Authorization failure. Missing required permission(s).', >- 'Error message returned' >- ); >+ $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") >+ ->status_is( 403, 'Successful authentication and not enough permissions' )->json_is( >+ '/error' => 'Authorization failure. Missing required permission(s).', >+ 'Error message returned' >+ ); >+ }; >+ >+ subtest '`cardnumber` login' => sub { >+ >+ plan tests => 10; >+ >+ $patron->flags( 2**4 )->store; >+ >+ $t->get_ok("//$cardnumber:$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("//$cardnumber:$password@/api/v1/patrons") >+ ->status_is( 403, 'Successful authentication and not enough permissions' )->json_is( >+ '/error' => 'Authorization failure. Missing required permission(s).', >+ 'Error message returned' >+ ); >+ }; > > $schema->storage->txn_rollback; > }; >-- >2.30.2
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 36420
:
163984
|
163985
|
163991
|
163992
|
163993
|
164256
|
164257
|
165006
|
165007