summaryrefslogtreecommitdiff
path: root/t/20-app-raps2-password.t
blob: 7e36358f8af0d3f19fd3cd8cb14b942109b5c16b (plain)
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;

my $pw;
my $salt = 'abcdefghijklmnop';
my $pass = 'something';

use_ok('App::Raps2::Password');

$pw = App::Raps2::Password->new();
is($pw, undef, 'new() missing salt and passphrase');

$pw = App::Raps2::Password->new(salt => $salt);
is($pw, undef, 'new() missing passphrase');

$pw = App::Raps2::Password->new(passphrase => $pass);
is($pw, undef, 'new() missing salt');

$pw = App::Raps2::Password->new(
	passphrase => $pass,
	salt => 'abcdefghijklmno',
);
is($pw, undef, 'new() salt one too short');

$pw = App::Raps2::Password->new(
	passphrase => $pass,
	salt => $salt . 'z',
);
is($pw, undef, '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');

ok(!$pw->verify('3lJRlaRuOGWv/z3g1DAOlcH.u9vS8WM'), 'verify: does not verify invalid hash');

ok($pw->verify($pw->crypt('truth')), 'crypt->verify okay')