Bugzilla – Attachment 133559 Details for
Bug 29873
2FA: Generate QR code without exposing secret via HTTP GET
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29873: Add unit test
Bug-29873-Add-unit-test.patch (text/plain), 2.71 KB, created by
Martin Renvoize
on 2022-04-21 13:15:49 UTC
(
hide
)
Description:
Bug 29873: Add unit test
Filename:
MIME Type:
Creator:
Martin Renvoize
Created:
2022-04-21 13:15:49 UTC
Size:
2.71 KB
patch
obsolete
>From cbf5e3a309a8bff410049ad02aade332da9240a4 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 13 Jan 2022 15:33:42 +0000 >Subject: [PATCH] Bug 29873: Add unit test > >Test plan: >Run t/db_dependent/Koha/Auth/TwoFactorAuth.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Amended to reflect requested changes. >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/Koha/Auth/TwoFactorAuth.t | 52 ++++++++++++++++++++++++ > 1 file changed, 52 insertions(+) > create mode 100755 t/db_dependent/Koha/Auth/TwoFactorAuth.t > >diff --git a/t/db_dependent/Koha/Auth/TwoFactorAuth.t b/t/db_dependent/Koha/Auth/TwoFactorAuth.t >new file mode 100755 >index 0000000000..6f76cd0749 >--- /dev/null >+++ b/t/db_dependent/Koha/Auth/TwoFactorAuth.t >@@ -0,0 +1,52 @@ >+use Modern::Perl; >+use Test::More tests => 1; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+use Koha::Database; >+use Koha::Auth::TwoFactorAuth; >+ >+our $schema = Koha::Database->new->schema; >+our $builder = t::lib::TestBuilder->new; >+ >+subtest 'qr_code' => sub { >+ plan tests => 9; >+ >+ $schema->storage->txn_begin; >+ >+ t::lib::Mocks::mock_preference('TwoFactorAuthentication', 1); >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ >+ # Testing without secret (might change later on) >+ is( $patron->secret, undef, 'Secret still undefined' ); >+ my $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron }); >+ is( $auth->secret, undef, 'Still no secret yet as expected' ); >+ # Auth::GoogleAuth will generate a secret when calling qr_code >+ my $img_data = $auth->qr_code; >+ is( length($auth->secret32), 16, 'Secret of 16 base32 chars expected' ); >+ is( length($img_data) > 22, 1, 'Dataurl not empty too' ); # prefix is 22 >+ $auth->clear; >+ >+ # Update patron data >+ $patron->secret('you2wont2guess2it'); # this is base32 btw >+ $patron->auth_method('two-factor'); >+ $patron->store; >+ >+ $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron }); >+ $img_data = $auth->qr_code; >+ is( substr($img_data, 0, 22), 'data:image/png;base64,', 'Checking prefix of dataurl' ); >+ like( substr($img_data, 22), qr/^[a-zA-Z0-9\/=+]+$/, 'Contains base64 chars' ); >+ is( $auth->qr_code, $img_data, 'Repeated call' ); >+ $auth->clear; >+ >+ # Changing the secret should generate different data, right? >+ $patron->secret('no3really3not3cracked'); # base32 >+ $patron->store; >+ $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron }); >+ my $img_data02 = $auth->qr_code; >+ is( length($img_data02) > 22, 1, 'More characters than prefix' ); >+ isnt( $img_data02, $img_data, 'Another secret, another image' ); >+ >+ $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 29873
:
129402
|
129576
|
129577
|
129578
|
129579
|
129580
|
129581
|
129605
|
133216
|
133217
|
133558
|
133559
|
133659
|
133660