View | Details | Raw Unified | Return to bug 28998
Collapse All | Expand All

(-)a/Koha/Patron.pm (+35 lines)
Lines 36-41 use Koha::CirculationRules; Link Here
36
use Koha::Club::Enrollments;
36
use Koha::Club::Enrollments;
37
use Koha::Database;
37
use Koha::Database;
38
use Koha::DateUtils qw( dt_from_string );
38
use Koha::DateUtils qw( dt_from_string );
39
use Koha::Encryption;
39
use Koha::Exceptions::Password;
40
use Koha::Exceptions::Password;
40
use Koha::Holds;
41
use Koha::Holds;
41
use Koha::Old::Checkouts;
42
use Koha::Old::Checkouts;
Lines 2131-2136 sub can_patron_change_staff_only_lists { Link Here
2131
    return 0;
2132
    return 0;
2132
}
2133
}
2133
2134
2135
=head3
2136
2137
    $patron->encode_secret($secret32);
2138
2139
    Secret (TwoFactorAuth expects it in base32 format) is encrypted.
2140
    You still need to call ->store.
2141
2142
=cut
2143
2144
sub encode_secret {
2145
    my ( $self, $secret ) = @_;
2146
    if( $secret ) {
2147
        return $self->secret( Koha::Encryption->new->encrypt_hex($secret) );
2148
    }
2149
    return $self->secret($secret);
2150
}
2151
2152
=head3
2153
2154
    my $secret32 = $patron->decoded_secret;
2155
2156
    Decode the patron secret. We expect to get back a base32 string, but this
2157
    is not checked here. Caller of encode_secret is responsible for that.
2158
2159
=cut
2160
2161
sub decoded_secret {
2162
    my ( $self ) = @_;
2163
    if( $self->secret ) {
2164
        return Koha::Encryption->new->decrypt_hex( $self->secret );
2165
    }
2166
    return $self->secret;
2167
}
2168
2134
=head2 Internal methods
2169
=head2 Internal methods
2135
2170
2136
=head3 _type
2171
=head3 _type
(-)a/t/db_dependent/Koha/Patron.t (-2 / +20 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 16;
22
use Test::More tests => 17;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
25
Lines 1137-1139 subtest 'recalls() tests' => sub { Link Here
1137
1137
1138
    $schema->storage->txn_rollback;
1138
    $schema->storage->txn_rollback;
1139
};
1139
};
1140
- 
1140
1141
subtest 'encode_secret and decoded_secret' => sub {
1142
    plan tests => 5;
1143
    $schema->storage->txn_begin;
1144
1145
    t::lib::Mocks::mock_config('encryption_key', 't0P_secret');
1146
1147
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
1148
    is( $patron->decoded_secret, undef, 'TestBuilder does not initialize it' );
1149
    $patron->secret(q{});
1150
    is( $patron->decoded_secret, q{}, 'Empty string case' );
1151
1152
    $patron->encode_secret('encrypt_me'); # Note: lazy testing; should be base32 string normally.
1153
    is( length($patron->secret) > 0, 1, 'Secret length' );
1154
    isnt( $patron->secret, 'encrypt_me', 'Encrypted column' );
1155
    is( $patron->decoded_secret, 'encrypt_me', 'Decrypted column' );
1156
1157
    $schema->storage->txn_rollback;
1158
};

Return to bug 28998