Fixing tests to be executable by cpanm . -v and adding password login to user with tests.
This commit is contained in:
parent
b58c989910
commit
33431ec290
@ -5,7 +5,7 @@ WriteMakefile(
|
||||
VERSION => '0.1',
|
||||
INST_SCRIPT => './bin',
|
||||
INST_BIN => './bin',
|
||||
test => { TESTS => 't/*.t' },
|
||||
test => { TESTS => 't/*.t t/*/*.t' },
|
||||
);
|
||||
|
||||
package MY {
|
||||
|
@ -10,6 +10,7 @@ use Types::Standard qw/Str Bool Int/;
|
||||
|
||||
use BeastBB::Types qw/$MATRIX_ADDRESS_TYPE IsClassTypeGenerator/;
|
||||
use BeastBB::Response;
|
||||
use Crypt::Bcrypt::Easy;
|
||||
|
||||
{
|
||||
my $validator = validation_for(
|
||||
@ -42,7 +43,7 @@ use BeastBB::Response;
|
||||
}
|
||||
|
||||
sub Hash {
|
||||
my $self = shift;
|
||||
my $self = shift;
|
||||
return {
|
||||
(
|
||||
( !$self->IdUser->IsError )
|
||||
@ -214,4 +215,20 @@ sub Username {
|
||||
return $self->{last_connection};
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
my $validator = validation_for(
|
||||
params => {
|
||||
password => { type => Str },
|
||||
}
|
||||
);
|
||||
|
||||
sub CheckPasswordLogin {
|
||||
my $self = shift;
|
||||
my %params = $validator->(@_);
|
||||
my $password = $params{password};
|
||||
return bcrypt->compare( text => $password,
|
||||
crypt => $self->PasswordBcrypt );
|
||||
}
|
||||
}
|
||||
1;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use 5.32.1;
|
||||
|
||||
use Test::Most tests => 7;
|
||||
use Test::Most tests => 8;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
@ -10,10 +10,11 @@ use Crypt::Bcrypt::Easy;
|
||||
use DateTime;
|
||||
use Scalar::Util 'blessed';
|
||||
|
||||
const my $PASSWORD => 'example_password';
|
||||
const my %REQUIRED_FIELDS_USER => (
|
||||
username => 'example_username',
|
||||
matrix_address => '@example_username:example_host.com',
|
||||
password_bcrypt => bcrypt->crypt('example_password'),
|
||||
password_bcrypt => bcrypt->crypt($PASSWORD),
|
||||
is_confirmed => 1,
|
||||
creation_date => DateTime->new( year => 2021, month => 06, day => 3 ),
|
||||
last_connection => DateTime->now,
|
||||
@ -61,3 +62,7 @@ const my %REQUIRED_FIELDS_USER => (
|
||||
is_deeply $user_hash, { %REQUIRED_FIELDS_USER, id_user => 1 },
|
||||
'User has the expected hash with id set after creation.';
|
||||
}
|
||||
{
|
||||
my $user = BeastBB::Model::User->new(%REQUIRED_FIELDS_USER);
|
||||
ok $user->CheckPasswordLogin(password => $PASSWORD ), q{User can login with it's password};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user