| 1 | package Bot::ChatBots::Auth; | ||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 2 | { our $VERSION = '0.014'; } | |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Log::Any qw< $log >; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 2 | with 'Bot::ChatBots::Role::Processor'; | |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | has channels => (is => 'rw', default => sub { return {} }); | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | has name => (is => 'ro', default => sub { return ref($_[0]) || $_[0] }); | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
Condition33%1/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | has users => (is => 'rw', default => sub { return {} }); | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | sub process { | ||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 16 | 9 | my ($self, $record) = @_; | |||||||||||||||||||||||||||||||||
| 17 | 9 | my $name = $self->name; | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 9 | my $users = $self->users; | |||||||||||||||||||||||||||||||||
| 20 | 9 | ▶ | if (keys %$users) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 21 | 9 | ▶ | my $id = $record->{sender}{id} // do { | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$record->{"sender"}{"id"} // do {
$Bot::ChatBots::Auth::log->info("${name}: sender id is not present");
return
}
MC/DC0%0/2
$record->{"sender"}{"id"} // do {
$Bot::ChatBots::Auth::log->info("${name}: sender id is not present");
return
}
$record->{"sender"}{"id"}
do {
$Bot::ChatBots::Auth::log->info("${name}: sender id is not present");
return
}
Truth table33%1/3
A // B
A= $record->{"sender"}{"id"}B= do {
$Bot::ChatBots::Auth::log->info("${name}: sender id is not present");
return
}
| |||||||||||||||||||||||||||||||||||
| 22 | 2 | $log->info("$name: sender id is not present"); | |||||||||||||||||||||||||||||||||
| 23 | 2 | return; | |||||||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||||||||
| 25 | 7 | ▶ | if (exists $users->{blacklist}{$id}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 26 | 1 | $log->info("$name: sender '$id' is blacklisted, blocking"); | |||||||||||||||||||||||||||||||||
| 27 | 1 | return; | |||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||
| 29 | 6 | ▶ | if (scalar(keys %{$users->{whitelist}}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar keys %{$$users{"whitelist"};} and not exists $users->{"whitelist"}{$id}
MC/DC100%2/2
scalar keys %{$$users{"whitelist"};} and not exists $users->{"whitelist"}{$id}
scalar keys %{$$users{"whitelist"};}
not exists $users->{"whitelist"}{$id}
Truth table100%3/3
A and not(B)
A= scalar keys %{$$users{"whitelist"};}B= not exists $users->{"whitelist"}{$id}
| |||||||||||||||||||||||||||||||||||
| 30 | && (!exists($users->{whitelist}{$id}))) | ||||||||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||||||||
| 32 | 1 | $log->info("$name: sender '$id' not whitelisted, blocking"); | |||||||||||||||||||||||||||||||||
| 33 | 1 | return; | |||||||||||||||||||||||||||||||||
| 34 | } ## end if (scalar(keys %{$users...})) | ||||||||||||||||||||||||||||||||||
| 35 | } ## end if (keys %$users) | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 5 | my $channels = $self->channels; | |||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | if (keys %$channels) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 39 | 5 | ▶ | my $id = $record->{channel}{fqid} // $record->{channel}{id} // do { | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
($record->{"channel"}{"fqid"} // $record->{"channel"}{"id"}) // do {
$Bot::ChatBots::Auth::log->info("${name}: chat id is not present");
return
}
$record->{"channel"}{"fqid"} // $record->{"channel"}{"id"}
MC/DC0%0/3
($record->{"channel"}{"fqid"} // $record->{"channel"}{"id"}) // do {
$Bot::ChatBots::Auth::log->info("${name}: chat id is not present");
return
}
$record->{"channel"}{"fqid"}
$record->{"channel"}{"id"}
do {
$Bot::ChatBots::Auth::log->info("${name}: chat id is not present");
return
}
Truth table25%1/4
A // B // C
A= $record->{"channel"}{"fqid"}B= $record->{"channel"}{"id"}C= do {
$Bot::ChatBots::Auth::log->info("${name}: chat id is not present");
return
}
| |||||||||||||||||||||||||||||||||||
| 40 | 1 | $log->info("$name: chat id is not present"); | |||||||||||||||||||||||||||||||||
| 41 | 1 | return; | |||||||||||||||||||||||||||||||||
| 42 | }; | ||||||||||||||||||||||||||||||||||
| 43 | 4 | ▶ | if (exists $channels->{blacklist}{$id}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 44 | 1 | $log->info("$name: chat '$id' is blacklisted, blocking"); | |||||||||||||||||||||||||||||||||
| 45 | 1 | return; | |||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | if (scalar(keys %{$channels->{whitelist}}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar keys %{$$channels{"whitelist"};} and not exists $channels->{"whitelist"}{$id}
MC/DC100%2/2
scalar keys %{$$channels{"whitelist"};} and not exists $channels->{"whitelist"}{$id}
scalar keys %{$$channels{"whitelist"};}
not exists $channels->{"whitelist"}{$id}
Truth table100%3/3
A and not(B)
A= scalar keys %{$$channels{"whitelist"};}B= not exists $channels->{"whitelist"}{$id}
| |||||||||||||||||||||||||||||||||||
| 48 | && (!exists($channels->{whitelist}{$id}))) | ||||||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||||||
| 50 | 1 | $log->info("$name: chat '$id' not whitelisted, blocking"); | |||||||||||||||||||||||||||||||||
| 51 | 1 | return; | |||||||||||||||||||||||||||||||||
| 52 | } ## end if (scalar(keys %{$channels...})) | ||||||||||||||||||||||||||||||||||
| 53 | } ## end if (keys %$channels) | ||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | 2 | $log->info("$name: no reason to block, allowing"); | |||||||||||||||||||||||||||||||||
| 56 | 2 | return $record; | |||||||||||||||||||||||||||||||||
| 57 | } ## end sub process | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 2 | 42; | |||||||||||||||||||||||||||||||||