Bugzilla – Attachment 152230 Details for
Bug 33967
REMOTE_ADDR incorrect in plack.log when run behind a proxy
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33967: Add unit test to ensure SetEnv doesn't compromise $env
Bug-33967-Add-unit-test-to-ensure-SetEnv-doesnt-co.patch (text/plain), 3.22 KB, created by
David Cook
on 2023-06-09 06:49:44 UTC
(
hide
)
Description:
Bug 33967: Add unit test to ensure SetEnv doesn't compromise $env
Filename:
MIME Type:
Creator:
David Cook
Created:
2023-06-09 06:49:44 UTC
Size:
3.22 KB
patch
obsolete
>From f514f4c7a601ef46491ce4ee4cff0536847ec9e0 Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Fri, 9 Jun 2023 06:46:43 +0000 >Subject: [PATCH] Bug 33967: Add unit test to ensure SetEnv doesn't compromise > $env > >This patch includes a unit test which checks the memory address >of the $env hashref in middlewares before and after >Koha::Middleware::Env is applied. > >It succeeds when the same $env is maintained before and after >this middleware. It fails if the $env has been overwritten with >a new hashref (as evidenced by the new memory address for the >hash). >--- > t/Koha/Middleware/SetEnv.t | 85 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 85 insertions(+) > create mode 100755 t/Koha/Middleware/SetEnv.t > >diff --git a/t/Koha/Middleware/SetEnv.t b/t/Koha/Middleware/SetEnv.t >new file mode 100755 >index 0000000000..6872c2c3a5 >--- /dev/null >+++ b/t/Koha/Middleware/SetEnv.t >@@ -0,0 +1,85 @@ >+#!/usr/bin/perl >+ >+# >+# Copyright 2023 Prosentient Systems >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use strict; >+use warnings; >+use Test::More tests => 2; >+use Test::Warn; >+ >+use t::lib::Mocks; >+use_ok("Koha::Middleware::SetEnv"); >+use Plack::Builder; >+use Plack::Util; >+ >+subtest 'Test $env integrity' => sub { >+ plan tests => 2; >+ >+ my $app = sub { >+ my $resp = [ >+ 200, >+ [ >+ 'Content-Type', >+ 'text/plain', >+ 'Content-Length', >+ 12 >+ ], >+ ['Koha is cool'] >+ ]; >+ return $resp; >+ }; >+ my $env = {}; >+ my $correct_hash_addr = "$env"; >+ my @ref_to_test = (); >+ >+ $app = builder { >+ enable sub { >+ my $app = shift; >+ sub { >+ my $env = shift; >+ push( @ref_to_test, "$env" ); >+ >+ # do preprocessing >+ my $res = $app->($env); >+ >+ # do postprocessing >+ return $res; >+ }; >+ }; >+ enable "+Koha::Middleware::SetEnv"; >+ enable sub { >+ my $app = shift; >+ sub { >+ my $env = shift; >+ push( @ref_to_test, "$env" ); >+ >+ # do preprocessing >+ my $res = $app->($env); >+ >+ # do postprocessing >+ return $res; >+ }; >+ }; >+ $app; >+ }; >+ >+ my $res = Plack::Util::run_app( $app, $env ); >+ is( $correct_hash_addr, $ref_to_test[0], "First hash ref address correct before middleware applied" ); >+ is( $correct_hash_addr, $ref_to_test[1], "Second hash ref address correct after middleware applied" ); >+}; >-- >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 33967
:
152227
|
152228
|
152229
|
152230
|
152241
|
152242