Authentication/Handler/Auth.pm

filter: Statementstmt 95.6% 44 / 46 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 12.5% 1 / 8 totaltotal 87.3% 62 / 71 CC 5 SCAR 6.1
CC
5
Cov
96%
envfrom_callback
4.0
pre_loop_setup
2.0
BEGIN
1.0
CRAP 1.8
« Authentication/Handler/Logger.pm ↑ Summary Authentication/Pragmas.pm »
1 package Mail::Milter::Authentication::Handler::Auth;
2 30 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 30 ▶use Mail::Milter::Authentication::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: Handler class for SMTP Auth
7 30 our $VERSION = '4.20261116'; # VERSION
8 30 ▶use base 'Mail::Milter::Authentication::Handler';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶sub default_config {
Subroutine default_config: called CC=1 SCAR=0.0
Pod undocumented
11 1 return {};
12 }
13  
14 1 ▶sub grafana_rows {
Subroutine grafana_rows: called CC=1 SCAR=0.0
Pod undocumented
15 1 my ( $self ) = @_;
16 1 my @rows;
17 1 push @rows, $self->get_json( 'Auth_metrics' );
18 1 return \@rows;
19 }
20  
21 29 ▶sub register_metrics {
Subroutine register_metrics: called CC=1 SCAR=0.0
Pod documented
22 return {
23 29 'authenticated_connect_total' => 'The number of connections from an authenticated host',
24 };
25 }
26  
27 29 ▶sub pre_loop_setup {
Subroutine pre_loop_setup: called CC=2 SCAR=6.9
Pod undocumented
28 29 my ( $self ) = @_;
29 29 my $protocol = Mail::Milter::Authentication::Config::get_config()->{'protocol'};
30 29 ▶ if ( $protocol ne 'milter' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol ne "milter") 16 13 29
31 16 warn 'The Auth handler only works with the milter protocol';
32 }
33 }
34  
35 75 ▶sub get_auth_name {
Subroutine get_auth_name: called CC=1 SCAR=0.0
Pod undocumented
36 75 my ($self) = @_;
37 75 my $name = $self->get_symbol('{auth_authen}');
38 75 return $name;
39 }
40  
41 75 ▶sub connect_callback {
Subroutine connect_callback: called CC=1 SCAR=0.0
Pod undocumented
42 75 my ( $self, $hostname, $ip ) = @_;
43 75 $self->{'is_authenticated'} = 0;
44 }
45  
46 75 ▶sub envfrom_callback {
Subroutine envfrom_callback: called CC=4 SCAR=14.0
Pod undocumented
47 75 my ( $self, $env_from ) = @_;
48 75 my $auth_name = $self->get_auth_name();
49 75 ▶ if ($auth_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auth_name) 1 74 75
50 1 $self->dbgout( 'AuthenticatedAs', $auth_name, LOG_INFO );
51 # Clear the current auth headers ( iprev and helo may already be added )
52 # ToDo is this a good idea?
53 1 my $top_handler = $self->get_top_handler();
54 1 for my $type ( sort keys $top_handler->{'c_auth_headers'}->%* ) {
55 0 $top_handler->{'c_auth_headers'}->{$type} = [];
56 }
57 1 for my $type ( sort keys $top_handler->{'auth_headers'}->%* ) {
58 0 $top_handler->{'auth_headers'}->{$type} = [];
59 }
60 1 $self->{'is_authenticated'} = 1;
61 1 $self->metric_count( 'authenticated_connect_total' );
62 1 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'auth' )->safe_set_value( 'pass' );
63 1 $self->add_auth_header( $header );
64 }
65 }
66  
67 105 ▶sub close_callback {
Subroutine close_callback: called CC=1 SCAR=0.0
Pod undocumented
68 105 my ( $self ) = @_;
69 105 delete $self->{'is_authenticated'};
70 }
71  
72 30 1;
73  
74 __END__
« Authentication/Handler/Logger.pm ↑ Summary Authentication/Pragmas.pm »