Bugzilla – Attachment 81475 Details for
Bug 21336
GDPR: Handle unsubscribe requests automatically by optional (administrative) lock, anonymize and remove
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21336: Small adjustment in Koha::Token
Bug-21336-Small-adjustment-in-KohaToken.patch (text/plain), 2.17 KB, created by
Marcel de Rooy
on 2018-10-29 12:34:42 UTC
(
hide
)
Description:
Bug 21336: Small adjustment in Koha::Token
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2018-10-29 12:34:42 UTC
Size:
2.17 KB
patch
obsolete
>From 9ec80413336d7be67fc02d4003e73357452af3ed Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 19 Sep 2018 15:36:36 +0200 >Subject: [PATCH] Bug 21336: Small adjustment in Koha::Token >Content-Type: text/plain; charset=utf-8 > >Allow a pattern too in Koha::Token->generate. Only supported length. >Does not affect CSRF calls. So tiny change without further impact. > >Test plan: >Run t/Token.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/Token.pm | 5 +++-- > t/Token.t | 12 +++++++++++- > 2 files changed, 14 insertions(+), 3 deletions(-) > >diff --git a/Koha/Token.pm b/Koha/Token.pm >index d0f7a54..7c31145 100644 >--- a/Koha/Token.pm >+++ b/Koha/Token.pm >@@ -79,6 +79,7 @@ sub new { > }); > > Generate several types of tokens. Now includes CSRF. >+ For non-CSRF tokens an optional pattern parameter overrides length. > Room for future extension. > > =cut >@@ -196,8 +197,8 @@ sub _gen_rand { > my ( $params ) = @_; > my $length = $params->{length} || 1; > $length = 1 unless $length > 0; >- >- return String::Random::random_string( '.' x $length ); >+ my $pattern = $params->{pattern} // '.{'.$length.'}'; # pattern overrides length parameter >+ return String::Random::random_regex( $pattern ); > } > > =head1 AUTHOR >diff --git a/t/Token.t b/t/Token.t >index 2314d2e..102579b 100644 >--- a/t/Token.t >+++ b/t/Token.t >@@ -20,7 +20,7 @@ > # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > > use Modern::Perl; >-use Test::More tests => 10; >+use Test::More tests => 11; > use Time::HiRes qw|usleep|; > use C4::Context; > use Koha::Token; >@@ -89,3 +89,13 @@ subtest 'Same logged in user with another session (cookie CGISESSID)' => sub { > }); > is( $result, '', "CSRF token is not verified if another session is used" ); > }; >+ >+subtest 'Pattern parameter' => sub { >+ plan tests => 4; >+ my $id = $tokenizer->generate({ pattern => '\d\d', length => 8 }); >+ is( length($id), 2, 'Pattern overrides length' ); >+ ok( $id =~ /\d{2}/, 'Two digits found' ); >+ $id = $tokenizer->generate({ pattern => '[A-Z]{10}' }); >+ is( length($id), 10, 'Check length again' ); >+ ok( $id !~ /[^A-Z]/, 'Only uppercase letters' ); >+}; >-- >2.1.4
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 21336
:
79165
|
79166
|
79167
|
79168
|
79169
|
79170
|
80201
|
80202
|
80203
|
80204
|
80205
|
80206
|
80207
|
80208
|
80213
|
80214
|
80386
|
80387
|
80403
|
81112
|
81113
|
81114
|
81115
|
81116
|
81117
|
81118
|
81119
|
81270
|
81474
|
81475
|
81476
|
81477
|
81478
|
81479
|
81480
|
81481
|
81482
|
81483
|
82051
|
82052
|
82053
|
82054
|
82055
|
82056
|
82057
|
82058
|
82059
|
83202
|
83203
|
83204
|
83205
|
83206
|
83207
|
83208
|
83209
|
83256
|
87158
|
87159
|
87160
|
87161
|
87162
|
87163
|
87164
|
87165
|
87166
|
87167
|
87168
|
87176
|
87177
|
87178
|
87179
|
87180
|
87181
|
87182
|
87183
|
87184
|
87185
|
87387
|
87388
|
87389
|
87390
|
87391
|
87392
|
87393
|
87394
|
87395
|
87396
|
87397
|
87400
|
87401
|
88198
|
88199
|
88217
|
88218