Bugzilla – Attachment 95228 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: Add a failing test for missing userenv for REST basic auth
Bug-24003-Add-a-failing-test-for-missing-userenv-f.patch (text/plain), 2.74 KB, created by
Lari Taskula
on 2019-11-08 14:50:45 UTC
(
hide
)
Description:
Bug 24003: Add a failing test for missing userenv for REST basic auth
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2019-11-08 14:50:45 UTC
Size:
2.74 KB
patch
obsolete
>From cc7ba3ccfb4d000e745eab835e0fac42dc958dd5 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@hypernova.fi> >Date: Fri, 8 Nov 2019 14:43:21 +0000 >Subject: [PATCH] Bug 24003: Add a failing test for missing userenv for REST > basic auth > >When using REST API via basic authentication method, C4::Context->userenv >returns undef. > >This patch adds a failing test to prove it. > >To test: >1. prove t/db_dependent/api/v1/auth_basic.t >2. Observe failures: > > not ok 5 - exact match for JSON Pointer "/userenv/number" > Failed test 'exact match for JSON Pointer "/userenv/number"' > at t/db_dependent/api/v1/auth_basic.t line 52. > got: undef > expected: '1054' > not ok 6 - exact match for JSON Pointer "/userenv/id" > Failed test 'exact match for JSON Pointer "/userenv/id"' > at t/db_dependent/api/v1/auth_basic.t line 52. > got: undef > expected: 'tomasito' >--- > t/db_dependent/api/v1/auth_basic.t | 22 +++++++++++++++++++++- > 1 file changed, 21 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/api/v1/auth_basic.t b/t/db_dependent/api/v1/auth_basic.t >index 4fb48f0277..c077988e4b 100644 >--- a/t/db_dependent/api/v1/auth_basic.t >+++ b/t/db_dependent/api/v1/auth_basic.t >@@ -19,6 +19,7 @@ use Modern::Perl; > > use Test::More tests => 2; > use Test::Mojo; >+use Test::MockModule; > > use t::lib::TestBuilder; > use t::lib::Mocks; >@@ -26,11 +27,13 @@ use t::lib::Mocks; > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > >+my $mock = create_a_test_endpoint(); >+ > my $t = Test::Mojo->new('Koha::REST::V1'); > > subtest 'success tests' => sub { > >- plan tests => 5; >+ plan tests => 9; > > $schema->storage->txn_begin; > >@@ -46,6 +49,11 @@ subtest 'success tests' => sub { > $t->get_ok("//$userid:$password@/api/v1/patrons") > ->status_is( 200, 'Successful authentication and permissions check' ); > >+ $t->post_ok("//$userid:$password@/api/v1/oauth/token") >+ ->status_is( 418, 'Successful authentication and not enough permissions' ) >+ ->json_is('/userenv/number' => $patron->borrowernumber) >+ ->json_is('/userenv/id' => $userid); >+ > $patron->flags(undef)->store; > > $t->get_ok("//$userid:$password@/api/v1/patrons") >@@ -90,4 +98,16 @@ subtest 'failure tests' => sub { > $schema->storage->txn_rollback; > }; > >+sub create_a_test_endpoint { >+ # Mock POST /oauth/token endpoint to return userenv >+ # (it could be any other endpoint that doesn't require authentication too) >+ my $mock = Test::MockModule->new('Koha::REST::V1::OAuth'); >+ $mock->mock(token => sub { >+ my $c = shift; >+ return $c->render( status => 418, >+ json => { userenv => C4::Context->userenv }); >+ }); >+ return $mock; >+} >+ > 1; >-- >2.17.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