lib/Test2/Harness/UI/Schema/Overlay/User.pm

filter: Statementstmt 51.9% 27 / 52 Branchbran 12.5% 1 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 61.5% 8 / 13 Podpod 20.0% 1 / 5 totaltotal 47.4% 37 / 78 CC 4 SCAR 11.0
CC
4
Cov
47%
new
6.0
gen_salt
6.0
gen_api_key
6.0
CRAP 3.0
« lib/Test2/Harness/UI/Controller.pm ↑ Summary lib/Test2/Harness/UI/Controller/Recent.pm »
1 package Test2::Harness::UI::Schema::Result::User;
2 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶confess "You must first load a Test2::Harness::UI::Schema::NAME module"
Branch: 1 branch
BranchTrueFalseTotal
unless $Test2::Harness::UI::Schema::LOADED 0 2 2
8 unless $Test2::Harness::UI::Schema::LOADED;
9  
10 2 our $VERSION = '0.000150';
11  
12 2 ▶use Test2::Harness::UI::UUID qw/gen_uuid/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use constant COST => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 ▶use Crypt::Eksblowfish::Bcrypt qw(bcrypt_hash en_base64 de_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
20 0 my $class = shift;
21 0 my ($attrs) = @_;
22  
23 0 ▶ if (my $pw = delete $attrs->{password}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pw = delete $attrs->{"password"}) 0 0 0
24 0 my $salt = $class->gen_salt;
25 0 my $hash = bcrypt_hash({key_nul => 1, cost => COST, salt => $salt}, $pw);
26  
27 0 $attrs->{pw_hash} = en_base64($hash);
28 0 $attrs->{pw_salt} = en_base64($salt);
29 }
30  
31 0 my $new = $class->next::method($attrs);
32  
33 0 return $new;
34 }
35  
36 0 ▶sub verify_password {
Subroutine verify_password: not called CC=1 SCAR=6.9
Pod undocumented
37 0 my $self = shift;
38 0 my ($pw) = @_;
39  
40 0 my $hash = en_base64(bcrypt_hash({key_nul => 1, cost => COST, salt => de_base64($self->pw_salt)}, $pw));
41 0 return $hash eq $self->pw_hash;
42 }
43  
44 0 ▶sub set_password {
Subroutine set_password: not called CC=1 SCAR=6.9
Pod undocumented
45 0 my $self = shift;
46 0 my ($pw) = @_;
47  
48 0 my $salt = $self->gen_salt;
49 0 my $hash = bcrypt_hash({key_nul => 1, cost => COST, salt => $salt}, $pw);
50  
51 0 $self->update({pw_hash => en_base64($hash), pw_salt => en_base64($salt)});
52 }
53  
54 0 ▶sub gen_salt {
Subroutine gen_salt: not called CC=2 SCAR=17.9
Pod undocumented
55 0 my $salt = '';
56 0 ▶ $salt .= chr(rand() * 256) while length($salt) < 16;
Branch: 1 branch
BranchTrueFalseTotal
length $salt < 16 and do { $salt .= chr((rand()) * 256) } 0 0 0
57 0 return $salt;
58 }
59  
60 0 ▶sub gen_api_key {
Subroutine gen_api_key: not called CC=2 SCAR=17.9
Pod undocumented
61 0 my $self = shift;
62 0 my ($name) = @_;
63  
64 0 ▶ croak "Must provide a key name"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
65 unless defined($name);
66  
67 0 return $self->result_source->schema->resultset('ApiKey')->create(
68 {
69 user_id => $self->user_id,
70 value => gen_uuid(),
71 status => 'active',
72 name => $name,
73 }
74 );
75 }
76  
77 2 1;
78  
79 __END__
« lib/Test2/Harness/UI/Controller.pm ↑ Summary lib/Test2/Harness/UI/Controller/Recent.pm »