|
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 |
- |
|
|