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
55
56
57
58
|
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use Test::More tests => 13;
use Test::Exception;
my $pw;
my $salt = 'abcdefghijklmnop';
my $pass = 'something';
use_ok('App::Raps2::Password');
throws_ok { App::Raps2::Password->new() } qr{incorrect salt length},
'new() missing salt and passphrase';
throws_ok { App::Raps2::Password->new(salt => $salt) } qr{no passphrase given},
'new() missing passphrase';
throws_ok { App::Raps2::Password->new(passphrase => $pass) } qr{incorrect salt length},
'new() missing salt';
throws_ok { App::Raps2::Password->new(
passphrase => $pass,
salt => 'abcdefghijklmno',
) } qr{incorrect salt length}, 'new() salt one too short';
throws_ok { App::Raps2::Password->new(
passphrase => $pass,
salt => $salt . 'z',
) } qr{incorrect salt length}, 'new() salt one too long';
$pw = App::Raps2::Password->new(
passphrase => $pass,
salt => $salt,
);
isa_ok($pw, 'App::Raps2::Password');
$pw = App::Raps2::Password->new(
cost => 8,
salt => $salt,
passphrase => $pass,
);
isa_ok($pw, 'App::Raps2::Password');
is($pw->decrypt('53616c7465645f5f80d8c367e15980d43ec9a6eabc5390b4'), 'quux',
'decrypt okay');
is($pw->decrypt($pw->encrypt('foo')), 'foo', 'encrypt->decrypt okay');
ok($pw->verify('3lJRlaRuOGWv/z3g1DAOlcH.u9vS8Wm'), 'verify: verifies correct hash');
throws_ok { $pw->verify('3lJRlaRuOGWv/z3g1DAOlcH.u9vS8WM') } qr{Passwords did not match},
'verify: does not verify invalid hash';
ok($pw->verify($pw->crypt('truth')), 'crypt->verify okay')
|