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

(-)a/Koha/Auth/TwoFactorAuth.pm (-1 / +1 lines)
Lines 72-78 sub new { Link Here
72
    } elsif( $secret ) {
72
    } elsif( $secret ) {
73
        $type = 'secret';
73
        $type = 'secret';
74
    } elsif( $patron->secret ) {
74
    } elsif( $patron->secret ) {
75
        $secret32 = $patron->secret; # saved already in base32
75
        $secret32 = $patron->decoded_secret; # saved already in base32
76
    } else {
76
    } else {
77
        Koha::Exceptions::MissingParameter->throw("No secret passed or patron has no secret");
77
        Koha::Exceptions::MissingParameter->throw("No secret passed or patron has no secret");
78
    }
78
    }
(-)a/members/two_factor_auth.pl (-1 / +1 lines)
Lines 69-75 if ( $op eq 'register-2FA' ) { Link Here
69
69
70
    if ($verified) {
70
    if ($verified) {
71
        # FIXME Generate a (new?) secret
71
        # FIXME Generate a (new?) secret
72
        $logged_in_user->secret($secret32);
72
        $logged_in_user->encode_secret($secret32);
73
        $logged_in_user->auth_method('two-factor')->store;
73
        $logged_in_user->auth_method('two-factor')->store;
74
        $op = 'registered';
74
        $op = 'registered';
75
        if( $logged_in_user->notice_email_address ) {
75
        if( $logged_in_user->notice_email_address ) {
(-)a/t/db_dependent/Koha/Auth/TwoFactorAuth.t (-7 / +6 lines)
Lines 42-51 subtest 'new' => sub { Link Here
42
        'Croaked on wrong encoding';
42
        'Croaked on wrong encoding';
43
43
44
    # Test passing secret or secret32 (converted to base32)
44
    # Test passing secret or secret32 (converted to base32)
45
    $patron->secret('nv4v65dpobpxgzldojsxiii'); # this is base32 already for 'my_top_secret!'
45
    $patron->encode_secret('nv4v65dpobpxgzldojsxiii'); # this is base32 already for 'my_top_secret!'
46
    my $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron });
46
    my $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron });
47
    is( $auth->secret32, $patron->secret, 'Base32 secret as expected' );
47
    is( $auth->secret32, $patron->decoded_secret, 'Base32 secret as expected' );
48
    $auth->code( $patron->secret ); # trigger conversion by passing base32 to code
48
    $auth->code( $patron->decoded_secret ); # trigger conversion by passing base32 to code
49
    is( $auth->secret, 'my_top_secret!', 'Decoded secret fine too' );
49
    is( $auth->secret, 'my_top_secret!', 'Decoded secret fine too' );
50
    # The other way around
50
    # The other way around
51
    $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron, secret => 'my_top_secret!' });
51
    $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron, secret => 'my_top_secret!' });
Lines 64-70 subtest 'qr_code' => sub { Link Here
64
64
65
    t::lib::Mocks::mock_preference('TwoFactorAuthentication', 1);
65
    t::lib::Mocks::mock_preference('TwoFactorAuthentication', 1);
66
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
66
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
67
    $patron->secret('you2wont2guess2it'); # this is base32 btw
67
    $patron->encode_secret('you2wont2guess2it'); # this is base32 btw
68
    $patron->auth_method('two-factor');
68
    $patron->auth_method('two-factor');
69
    $patron->store;
69
    $patron->store;
70
70
Lines 76-82 subtest 'qr_code' => sub { Link Here
76
    $auth->clear;
76
    $auth->clear;
77
77
78
    # Changing the secret should generate different data, right?
78
    # Changing the secret should generate different data, right?
79
    $patron->secret('no3really3not3cracked'); # base32
79
    $patron->encode_secret('no3really3not3cracked'); # base32
80
    $patron->store;
80
    $patron->store;
81
    $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron });
81
    $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron });
82
    my $img_data02 = $auth->qr_code;
82
    my $img_data02 = $auth->qr_code;
Lines 92-98 subtest 'send_confirm_notice' => sub { Link Here
92
92
93
    t::lib::Mocks::mock_preference('TwoFactorAuthentication', 1);
93
    t::lib::Mocks::mock_preference('TwoFactorAuthentication', 1);
94
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
94
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
95
    $patron->secret('you2wont2guess2it'); # this is base32 btw
95
    $patron->encode_secret('you2wont2guess2it'); # this is base32 btw
96
    $patron->auth_method('two-factor');
96
    $patron->auth_method('two-factor');
97
    $patron->store;
97
    $patron->store;
98
    my $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron });
98
    my $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron });
99
- 

Return to bug 28998