File: 10-logic.t

package info (click to toggle)
libmojolicious-plugin-bcrypt-perl 0.14-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 108 kB
  • sloc: perl: 100; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,465 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl

use strict;
use warnings;
use utf8;

use Test::More tests => 17;
use Test::Mojo;
use Mojolicious::Lite;
use Mojolicious::Plugin::Bcrypt;
use Encode;

plugin bcrypt => { cost => 6 };

get '/bc' => sub {
    my $self = shift;
    my ( $p, $s ) = map { $self->param($_) } qw/p s/;
    $self->render( text => $self->bcrypt( $p, $s ) );
};

get '/bv' => sub {
    my $self = shift;
    my ( $p, $c ) = map { $self->param($_) } qw/p c/;
    my $ok = $self->bcrypt_validate( $p, $c );
    $self->render( text => ($ok ? 'Pass' : 'Fail') );
};

my $t = Test::Mojo->new();
my @A = <DATA>;

for (@A) {
    chomp;
    s/([^ ]+) ([^ ]+) *//;
    my ( $settings, $hash ) = ( $1, $2 );
    my $encoded = encode("utf-8", $_);
    $t->get_ok("/bc?p=$encoded&s=$settings")->content_is( $settings . $hash );
    $t->get_ok( "/bv?p=$encoded&c=" . $settings . $hash, encode("utf-8", $_) );
}

my $password = 'big secret';
my $bcrypted = app->bcrypt($password);
ok( app->bcrypt_validate( $password, $bcrypted ), 'accept ok' );
ok( !app->bcrypt_validate( 'meow!', $bcrypted ), 'deny ok' );

__DATA__
$2a$06$cDTyXCPyZ0npLBTSbVTSTe 7GWMx9.3G/fpj8oDiyuQdsa2iqpFGmO
$2a$06$OxDCTUayLyPtLRWxbhPoPe r8io68QbDErcImQ1oQKuFgO5Vkawfuu password
$2a$06$LULFY1a3ZyXTLhLqRDb/Qe kyfCo7Mcdq3yim3Qvkcwt3j6WkGkotu 0
$2a$06$YDDSKEnPLDi0MRDxTU3zKu iGlbH4EazT7YiiSSbAGONYfPYZLfm3m short skirt and long jacket
$2a$06$TRTxb0bYKRbxLB/2SiX0PO NmMUp3S1PE0XxrPCOIyF9Y01irLMmgi нова загора