File: module.t

package info (click to toggle)
libauth-googleauth-perl 1.07-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 152 kB
  • sloc: perl: 129; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 2,340 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use Test2::V0;
use Auth::GoogleAuth;

my $obj;
ok( $obj = Auth::GoogleAuth->new, 'new' );
is( ref $obj, 'Auth::GoogleAuth', 'ref $object' );

my $secret32 = $obj->generate_secret32;
ok( $secret32 =~ /^[a-z2-7]{16}$/, 'generate_secret32() length and content' );
is( $secret32, $obj->secret32, 'generate_secret32() stored as secret32()' );

ok(
    lives { $obj = Auth::GoogleAuth->new( { map { $_ => 'data' } qw( secret secret32 issuer key_id ) } ) },
    'new({...})',
) or note $@;
is( $obj->$_, 'data', "$_ set in instantiator" ) for ( qw( secret secret32 issuer key_id ) );

ok( lives { $obj->clear }, 'clear' ) or note $@;
is( $obj->$_, undef, "$_ unset after clear" ) for ( qw( secret secret32 issuer key_id ) );

ok( $obj->qr_code =~ m|
    https://quickchart.io/chart
    \?
    chs=200x200&cht=qr&chl=
    otpauth%3A%2F%2Ftotp%2FUndefined%3AUndefined%3Fsecret%3D
    [a-z0-9]{16}
    %26issuer%3DUndefined
|x, 'qr_code from clear state' );

ok( $obj->qr_code( 'bv5o3disbutz4tl3', 'gryphon@cpan.org', 'Gryphon Shafer' ) =~ m|
    https://quickchart.io/chart
    \?
    chs=200x200&cht=qr&chl=
    otpauth%3A%2F%2Ftotp%2FGryphon%2520Shafer%3Agryphon%2540cpan.org%3Fsecret%3D
    bv5o3disbutz4tl3
    %26issuer%3DGryphon%2520Shafer
|x, 'qr_code from specific state' );

ok( $obj->qr_code( 'bv5o3disbutz4tl3', 'gryphon@cpan.org', 'Gryphon Shafer', 1 ) =~ m|
    otpauth://totp/Gryphon%20Shafer:gryphon%40cpan.org\?secret=bv5o3disbutz4tl3&issuer=Gryphon%20Shafer
|x, 'qr_code otpauth from specific state' );

is( $obj->code( undef, 1438643789 ), '007176', 'code()' );
is( $obj->code( 'utz4tl3bv5o3disb', 1438643789 ), '879364', 'code( $s32, $time )' );
is( $obj->code( 'utz4tl3bv5o3disb', 1438643789, 30 ), '879364', 'code( $s32, $time, 30 )' );
is( $obj->code( undef, 1438643789 ), '879364', 'code() again' );

is( $obj->verify( '879364', 0, 'utz4tl3bv5o3disb', 1438643789 ), 1, 'verify(tight) works' );
is( $obj->verify( '879364', 0, 'utz4tl3bv5o3disb', 1438643790 ), 0, 'verify(tight, mis-time) fails' );
is( $obj->verify( '879364', 1, 'utz4tl3bv5o3disb', 1438643790 ), 1, 'verify(loose, mis-time) works' );
is( $obj->verify( '879364', 1, 'utz4tl3bv5o3disb', 1438643820 ), 0, 'verify(loose, mis-time++) fails' );
is( $obj->verify( '879364', 2, 'utz4tl3bv5o3disb', 1438643820 ), 1, 'verify(looser, mis-time++) works' );

done_testing;