Fixing tests to be executable by cpanm . -v and adding password login to user with tests.

This commit is contained in:
sergiotarxz 2021-06-05 14:38:15 +02:00
parent b58c989910
commit 33431ec290
Signed by: sergiotarxz
GPG Key ID: E5903508B6510AC2
5 changed files with 26 additions and 4 deletions

View File

@ -5,7 +5,7 @@ WriteMakefile(
VERSION => '0.1', VERSION => '0.1',
INST_SCRIPT => './bin', INST_SCRIPT => './bin',
INST_BIN => './bin', INST_BIN => './bin',
test => { TESTS => 't/*.t' }, test => { TESTS => 't/*.t t/*/*.t' },
); );
package MY { package MY {

View File

@ -10,6 +10,7 @@ use Types::Standard qw/Str Bool Int/;
use BeastBB::Types qw/$MATRIX_ADDRESS_TYPE IsClassTypeGenerator/; use BeastBB::Types qw/$MATRIX_ADDRESS_TYPE IsClassTypeGenerator/;
use BeastBB::Response; use BeastBB::Response;
use Crypt::Bcrypt::Easy;
{ {
my $validator = validation_for( my $validator = validation_for(
@ -42,7 +43,7 @@ use BeastBB::Response;
} }
sub Hash { sub Hash {
my $self = shift; my $self = shift;
return { return {
( (
( !$self->IdUser->IsError ) ( !$self->IdUser->IsError )
@ -214,4 +215,20 @@ sub Username {
return $self->{last_connection}; 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;

View File

@ -1,6 +1,6 @@
use 5.32.1; use 5.32.1;
use Test::Most tests => 7; use Test::Most tests => 8;
use strict; use strict;
use warnings; use warnings;
@ -10,10 +10,11 @@ use Crypt::Bcrypt::Easy;
use DateTime; use DateTime;
use Scalar::Util 'blessed'; use Scalar::Util 'blessed';
const my $PASSWORD => 'example_password';
const my %REQUIRED_FIELDS_USER => ( const my %REQUIRED_FIELDS_USER => (
username => 'example_username', username => 'example_username',
matrix_address => '@example_username:example_host.com', matrix_address => '@example_username:example_host.com',
password_bcrypt => bcrypt->crypt('example_password'), password_bcrypt => bcrypt->crypt($PASSWORD),
is_confirmed => 1, is_confirmed => 1,
creation_date => DateTime->new( year => 2021, month => 06, day => 3 ), creation_date => DateTime->new( year => 2021, month => 06, day => 3 ),
last_connection => DateTime->now, last_connection => DateTime->now,
@ -61,3 +62,7 @@ const my %REQUIRED_FIELDS_USER => (
is_deeply $user_hash, { %REQUIRED_FIELDS_USER, id_user => 1 }, is_deeply $user_hash, { %REQUIRED_FIELDS_USER, id_user => 1 },
'User has the expected hash with id set after creation.'; '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};
}