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

(-)a/Koha/Auth/TwoFactorAuth.pm (-3 / +9 lines)
Lines 68-81 sub new { Link Here
68
    );
68
    );
69
}
69
}
70
70
71
=head3 qr_dataurl
71
=head3 qr_code
72
73
    my $image_src = $auth->qr_code;
74
75
    Wrapper around Auth::GoogleAuth::qr_code.
76
    Returns the data URL to fill the src attribute of the
77
    image tag on the registration form.
72
78
73
=cut
79
=cut
74
80
75
sub qr_dataurl {
81
sub qr_code {
76
    my ( $self ) = @_;
82
    my ( $self ) = @_;
77
83
78
    my $otpauth = $self->qr_code( undef, undef, undef, 1);
84
    my $otpauth = $self->SUPER::qr_code( undef, undef, undef, 1);
79
        # no need to pass secret, key and issuer again
85
        # no need to pass secret, key and issuer again
80
    my $qrcode = Imager::QRCode->new({
86
    my $qrcode = Imager::QRCode->new({
81
        size          => 4,
87
        size          => 4,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/two_factor_auth.tt (-1 / +1 lines)
Lines 55-61 Link Here
55
                            <ol>
55
                            <ol>
56
                                <li>
56
                                <li>
57
                                    <label for="qr_code">QR code: </label>
57
                                    <label for="qr_code">QR code: </label>
58
                                    <img id="qr_code" src="[% qr_dataurl | $raw %]" />
58
                                    <img id="qr_code" src="[% qr_code | $raw %]" />
59
                                </li>
59
                                </li>
60
                                <li>
60
                                <li>
61
                                    <label for="pin_code">Pin code: </label>
61
                                    <label for="pin_code">Pin code: </label>
(-)a/members/two_factor_auth.pl (-2 / +2 lines)
Lines 89-97 if ( $op eq 'enable-2FA' ) { Link Here
89
    $template->param(
89
    $template->param(
90
        issuer      => $auth->issuer,
90
        issuer      => $auth->issuer,
91
        key_id      => $auth->key_id,
91
        key_id      => $auth->key_id,
92
        qr_dataurl  => $auth->qr_dataurl,
92
        qr_code  => $auth->qr_code,
93
        secret32    => $auth->secret32,
93
        secret32    => $auth->secret32,
94
            # IMPORTANT: get secret32 after qr_dataurl call !
94
            # IMPORTANT: get secret32 after qr_code call !
95
    );
95
    );
96
    $auth->clear;
96
    $auth->clear;
97
    $op = 'register';
97
    $op = 'register';
(-)a/t/db_dependent/Koha/Auth/TwoFactorAuth.t (-7 / +6 lines)
Lines 10-16 use Koha::Auth::TwoFactorAuth; Link Here
10
our $schema = Koha::Database->new->schema;
10
our $schema = Koha::Database->new->schema;
11
our $builder = t::lib::TestBuilder->new;
11
our $builder = t::lib::TestBuilder->new;
12
12
13
subtest 'qr_dataurl' => sub {
13
subtest 'qr_code' => sub {
14
    plan tests => 9;
14
    plan tests => 9;
15
15
16
    $schema->storage->txn_begin;
16
    $schema->storage->txn_begin;
Lines 22-29 subtest 'qr_dataurl' => sub { Link Here
22
    is( $patron->secret, undef, 'Secret still undefined' );
22
    is( $patron->secret, undef, 'Secret still undefined' );
23
    my $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron });
23
    my $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron });
24
    is( $auth->secret, undef, 'Still no secret yet as expected' );
24
    is( $auth->secret, undef, 'Still no secret yet as expected' );
25
    # Auth::GoogleAuth will generate a secret when calling qr_dataurl
25
    # Auth::GoogleAuth will generate a secret when calling qr_code
26
    my $img_data = $auth->qr_dataurl;
26
    my $img_data = $auth->qr_code;
27
    is( length($auth->secret32), 16, 'Secret of 16 base32 chars expected' );
27
    is( length($auth->secret32), 16, 'Secret of 16 base32 chars expected' );
28
    is( length($img_data) > 22, 1, 'Dataurl not empty too' ); # prefix is 22
28
    is( length($img_data) > 22, 1, 'Dataurl not empty too' ); # prefix is 22
29
    $auth->clear;
29
    $auth->clear;
Lines 34-50 subtest 'qr_dataurl' => sub { Link Here
34
    $patron->store;
34
    $patron->store;
35
35
36
    $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron });
36
    $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron });
37
    $img_data = $auth->qr_dataurl;
37
    $img_data = $auth->qr_code;
38
    is( substr($img_data, 0, 22), 'data:image/png;base64,', 'Checking prefix of dataurl' );
38
    is( substr($img_data, 0, 22), 'data:image/png;base64,', 'Checking prefix of dataurl' );
39
    like( substr($img_data, 22), qr/^[a-zA-Z0-9\/=+]+$/, 'Contains base64 chars' );
39
    like( substr($img_data, 22), qr/^[a-zA-Z0-9\/=+]+$/, 'Contains base64 chars' );
40
    is( $auth->qr_dataurl, $img_data, 'Repeated call' );
40
    is( $auth->qr_code, $img_data, 'Repeated call' );
41
    $auth->clear;
41
    $auth->clear;
42
42
43
    # Changing the secret should generate different data, right?
43
    # Changing the secret should generate different data, right?
44
    $patron->secret('no3really3not3cracked'); # base32
44
    $patron->secret('no3really3not3cracked'); # base32
45
    $patron->store;
45
    $patron->store;
46
    $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron });
46
    $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron });
47
    my $img_data02 = $auth->qr_dataurl;
47
    my $img_data02 = $auth->qr_code;
48
    is( length($img_data02) > 22, 1, 'More characters than prefix' );
48
    is( length($img_data02) > 22, 1, 'More characters than prefix' );
49
    isnt( $img_data02, $img_data, 'Another secret, another image' );
49
    isnt( $img_data02, $img_data, 'Another secret, another image' );
50
50
51
- 

Return to bug 29873