Skip to content

Commit

Permalink
test password hasher
Browse files Browse the repository at this point in the history
  • Loading branch information
vti committed May 4, 2017
1 parent 49713b5 commit 5dc2ff1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions t/password.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use strict;
use warnings;

use Test::More;
use Test::Fatal;

use_ok 'Crafty::Password';

subtest 'hash: hashes password' => sub {
my $password = _build(hashing => 'md5', salt => 'hello');

is $password->hash('username', 'password'), 'a616e69e90cb180bdc8aa7c303836451';
};

subtest 'hash: throws on unknown hashing' => sub {
my $password = _build(hashing => 'unknown');

like exception { $password->hash('username', 'password') }, qr/unknown hashing/i;
};

subtest 'equals: checks password' => sub {
my $password = _build(hashing => 'md5', salt => 'hello');

my $correct_hash = $password->hash('username', 'password');

ok $password->equals('username', 'password', $correct_hash);
ok !$password->equals('username', 'password', 'wrong');
};

done_testing;

sub _build {
return Crafty::Password->new(@_);
}

0 comments on commit 5dc2ff1

Please sign in to comment.