Bugzilla – Attachment 105659 Details for
Bug 22522
API authentication breaks with updated Mojolicious version
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22522: [19.11.x] Fix several REST API tests
Bug-22522-1911x-Fix-several-REST-API-tests.patch (text/plain), 6.00 KB, created by
Jonathan Druart
on 2020-06-09 09:32:01 UTC
(
hide
)
Description:
Bug 22522: [19.11.x] Fix several REST API tests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-06-09 09:32:01 UTC
Size:
6.00 KB
patch
obsolete
>From 2fce09f1b8487dcf60bd467d0c06e91143945a0c Mon Sep 17 00:00:00 2001 >From: Ere Maijala <ere.maijala@helsinki.fi> >Date: Fri, 7 Feb 2020 13:49:46 +0200 >Subject: [PATCH] Bug 22522: [19.11.x] Fix several REST API tests > >Fixes among others the invalid use of json_has() which caused broken tests to pass with older Mojolicious versions. > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > api/v1/swagger/x-primitives.json | 2 +- > t/db_dependent/api/v1/holds.t | 6 +++++- > t/db_dependent/api/v1/libraries.t | 13 ++++++++----- > t/db_dependent/api/v1/patrons.t | 18 ++++++++++++------ > t/db_dependent/api/v1/patrons_password.t | 4 +--- > 5 files changed, 27 insertions(+), 16 deletions(-) > >diff --git a/api/v1/swagger/x-primitives.json b/api/v1/swagger/x-primitives.json >index ee15fa6aa1..19bc8dc012 100644 >--- a/api/v1/swagger/x-primitives.json >+++ b/api/v1/swagger/x-primitives.json >@@ -35,7 +35,7 @@ > "description": "primary phone number for patron's primary address" > }, > "surname": { >- "type": "string", >+ "type": ["string", "null"], > "description": "patron's last name" > }, > "vendor_id": { >diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t >index 845a0b2078..15462c4780 100644 >--- a/t/db_dependent/api/v1/holds.t >+++ b/t/db_dependent/api/v1/holds.t >@@ -190,10 +190,14 @@ subtest "Test endpoints with permission" => sub { > ->json_is('/0/patron_id', $patron_2->borrowernumber) > ->json_hasnt('/1'); > >+ # While suspended_until is date-time, it's always set to midnight. >+ my $expected_suspended_until = $suspended_until->strftime('%FT00:00:00%z'); >+ substr($expected_suspended_until, -2, 0, ':'); >+ > $t->put_ok( "//$userid_1:$password@/api/v1/holds/$reserve_id" => json => $put_data ) > ->status_is(200) > ->json_is( '/hold_id', $reserve_id ) >- ->json_is( '/suspended_until', output_pref({ dt => $suspended_until, dateformat => 'rfc3339' }) ) >+ ->json_is( '/suspended_until', $expected_suspended_until ) > ->json_is( '/priority', 2 ); > > $t->delete_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" ) >diff --git a/t/db_dependent/api/v1/libraries.t b/t/db_dependent/api/v1/libraries.t >index 5ac8eccade..091da64d1c 100644 >--- a/t/db_dependent/api/v1/libraries.t >+++ b/t/db_dependent/api/v1/libraries.t >@@ -85,14 +85,17 @@ subtest 'list() tests' => sub { > > my $size = keys %{$fields}; > >- plan tests => $size * 3; >+ plan tests => $size * (2 + 2 * $size); > > foreach my $field ( keys %{$fields} ) { > my $model_field = $fields->{ $field }; >- my $result = >- $t->get_ok("//$userid:$password@/api/v1/libraries?$field=" . $library->$model_field) >- ->status_is(200) >- ->json_has( [ $library, $another_library ] ); >+ my $result = $t->get_ok("//$userid:$password@/api/v1/libraries?$field=" . $library->$model_field) >+ ->status_is(200); >+ foreach my $key ( keys %{$fields} ) { >+ my $key_field = $fields->{ $key }; >+ $result->json_is( "/0/$key", $library->$key_field ); >+ $result->json_is( "/1/$key", $another_library->$key_field ); >+ } > } > }; > >diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t >index 9579229bb4..b8037d05b1 100644 >--- a/t/db_dependent/api/v1/patrons.t >+++ b/t/db_dependent/api/v1/patrons.t >@@ -310,17 +310,23 @@ subtest 'update() tests' => sub { > warning_like { > $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->borrowernumber => json => $newpatron ) > ->status_is(409) >- ->json_has( '/error' => "Fails when trying to update to an existing cardnumber or userid") >- ->json_is( '/conflict', 'cardnumber' ); } >- qr/^DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key 'cardnumber'/; >+ ->json_has( '/error', "Fails when trying to update to an existing cardnumber or userid") >+ ->json_like( '/conflict' => qr/(borrowers\.)?cardnumber/ ); } >+ qr/^DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key '(borrowers\.)?cardnumber'/; > > $newpatron->{ cardnumber } = $patron_1->id . $patron_2->id; > $newpatron->{ userid } = "user" . $patron_1->id.$patron_2->id; > $newpatron->{ surname } = "user" . $patron_1->id.$patron_2->id; > >- $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->borrowernumber => json => $newpatron ) >- ->status_is(200, 'Patron updated successfully') >- ->json_has($newpatron); >+ my $result = $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->borrowernumber => json => $newpatron ) >+ ->status_is(200, 'Patron updated successfully'); >+ >+ # Put back the RO attributes >+ $newpatron->{patron_id} = $unauthorized_patron->to_api->{patron_id}; >+ $newpatron->{restricted} = $unauthorized_patron->to_api->{restricted}; >+ $newpatron->{anonymized} = $unauthorized_patron->to_api->{anonymized}; >+ is_deeply($result->tx->res->json, $newpatron, 'Returned patron from update matches expected'); >+ > is(Koha::Patrons->find( $patron_2->id )->cardnumber, > $newpatron->{ cardnumber }, 'Patron is really updated!'); > >diff --git a/t/db_dependent/api/v1/patrons_password.t b/t/db_dependent/api/v1/patrons_password.t >index 10b1821930..504fcbe64e 100644 >--- a/t/db_dependent/api/v1/patrons_password.t >+++ b/t/db_dependent/api/v1/patrons_password.t >@@ -175,9 +175,7 @@ subtest 'set_public() (unprivileged user tests)' => sub { > $tx->req->env( { REMOTE_ADDR => '127.0.0.1' } ); > $t->request_ok($tx) > ->status_is(403) >- ->json_has({ >- error => "Authorization failure. Missing required permission(s)." >- }); >+ ->json_is('/error', "Authorization failure. Missing required permission(s)."); > > $tx = $t->ua->build_tx( > POST => "/api/v1/public/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 22522
:
86756
|
93592
|
98061
|
98089
|
98372
|
98557
|
98558
|
98559
|
98665
|
98666
|
98667
|
99181
|
99182
|
99183
|
105591
|
105639
|
105657
|
105658
| 105659 |
105692