File: 004_all_algorithm_matching.t

package info (click to toggle)
libdancer2-plugin-passphrase-perl 3.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 168 kB
  • sloc: perl: 190; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 837 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use Test::More tests => 26;

use strict;
use warnings;

use Dancer2;
use Dancer2::Plugin::Passphrase;

my $secret = "Super Secret Squirrel";

for (qw(MD5 SHA-1 SHA-224 SHA-256 SHA-384 SHA-512 Bcrypt)) {
    my $rfc2307 = passphrase($secret)->generate({ algorithm => $_ })->rfc2307;

    ok(passphrase($secret)->matches($rfc2307),  "With Salt - Match plaintext to hash => $_");
    ok(!passphrase('WRONG')->matches($rfc2307), "With Salt - Incorrect passwords should be rejected => $_");
}


for (qw(MD5 SHA-1 SHA-224 SHA-256 SHA-384 SHA-512)) {
    my $rfc2307 = passphrase($secret)->generate({ algorithm => $_, salt => '' })->rfc2307;

    ok(passphrase($secret)->matches($rfc2307),  "No Salt - Match plaintext to hash => $_");
    ok(!passphrase('WRONG')->matches($rfc2307), "No Salt - Incorrect passwords should be rejected => $_");
}