Bugzilla – Attachment 133524 Details for
Bug 28998
Encrypt borrowers.secret
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28998: (follow-up) Add Patron->encode_secret and ->decoded_secret
Bug-28998-follow-up-Add-Patron-encodesecret-and--d.patch (text/plain), 2.80 KB, created by
Marcel de Rooy
on 2022-04-21 08:41:17 UTC
(
hide
)
Description:
Bug 28998: (follow-up) Add Patron->encode_secret and ->decoded_secret
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2022-04-21 08:41:17 UTC
Size:
2.80 KB
patch
obsolete
>From 54b4c51fe6d051e399cfef67e3627e602f001e42 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 14 Apr 2022 12:35:30 +0000 >Subject: [PATCH] Bug 28998: (follow-up) Add Patron->encode_secret and > ->decoded_secret >Content-Type: text/plain; charset=utf-8 > >Test plan: >Run t/db_dependent/Koha/Patron.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/Patron.pm | 35 +++++++++++++++++++++++++++++++++++ > t/db_dependent/Koha/Patron.t | 19 +++++++++++++++++++ > 2 files changed, 54 insertions(+) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 3a26db0d6a..d1c7e01d37 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -36,6 +36,7 @@ use Koha::CirculationRules; > use Koha::Club::Enrollments; > use Koha::Database; > use Koha::DateUtils qw( dt_from_string ); >+use Koha::Encryption; > use Koha::Exceptions::Password; > use Koha::Holds; > use Koha::Old::Checkouts; >@@ -2131,6 +2132,40 @@ sub can_patron_change_staff_only_lists { > return 0; > } > >+=head3 >+ >+ $patron->encode_secret($secret32); >+ >+ Secret (TwoFactorAuth expects it in base32 format) is encrypted. >+ You still need to call ->store. >+ >+=cut >+ >+sub encode_secret { >+ my ( $self, $secret ) = @_; >+ if( $secret ) { >+ return $self->secret( Koha::Encryption->new->encrypt_hex($secret) ); >+ } >+ return $self->secret($secret); >+} >+ >+=head3 >+ >+ my $secret32 = $patron->decoded_secret; >+ >+ Decode the patron secret. We expect to get back a base32 string, but this >+ is not checked here. Caller of encode_secret is responsible for that. >+ >+=cut >+ >+sub decoded_secret { >+ my ( $self ) = @_; >+ if( $self->secret ) { >+ return Koha::Encryption->new->decrypt_hex( $self->secret ); >+ } >+ return $self->secret; >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t >index 6418d6066f..d77a4ae17e 100755 >--- a/t/db_dependent/Koha/Patron.t >+++ b/t/db_dependent/Koha/Patron.t >@@ -1137,3 +1137,22 @@ subtest 'recalls() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'encode_secret and decoded_secret' => sub { >+ plan tests => 5; >+ $schema->storage->txn_begin; >+ >+ t::lib::Mocks::mock_config('encryption_key', 't0P_secret'); >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ is( $patron->decoded_secret, undef, 'TestBuilder does not initialize it' ); >+ $patron->secret(q{}); >+ is( $patron->decoded_secret, q{}, 'Empty string case' ); >+ >+ $patron->encode_secret('encrypt_me'); # Note: lazy testing; should be base32 string normally. >+ is( length($patron->secret) > 0, 1, 'Secret length' ); >+ isnt( $patron->secret, 'encrypt_me', 'Encrypted column' ); >+ is( $patron->decoded_secret, 'encrypt_me', 'Decrypted column' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >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 28998
:
124772
|
124773
|
124774
|
133291
|
133317
|
133318
|
133319
|
133320
|
133321
|
133322
|
133323
|
133523
|
133524
|
133525
|
133526
|
133527
|
133528
|
133529
|
133580
|
133581
|
133582
|
133583
|
133584
|
133585
|
133586
|
133588
|
133619
|
133620
|
133621
|
133622
|
133623
|
133624
|
133625
|
133626
|
133627
|
133628
|
133629
|
133631
|
133632
|
133633
|
133634
|
133635
|
133636
|
133637
|
133638
|
133639
|
133640
|
133641
|
133642
|
133645
|
133646
|
133647
|
133648
|
133649
|
133650
|
133651
|
133652
|
133653
|
133654
|
133655
|
134636
|
134637
|
134671