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/Handler/AddID.pm »
1 package Mail::Milter::Authentication::Handler::Auth;
2 29 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use Mail::Milter::Authentication::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: Handler class for SMTP Auth
7 29 our $VERSION = '4.20261111'; # VERSION
8 29 ▶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 28 ▶sub register_metrics {
Subroutine register_metrics: called CC=1 SCAR=0.0
Pod documented
22 return {
23 28 'authenticated_connect_total' => 'The number of connections from an authenticated host',
24 };
25 }
26  
27 28 ▶sub pre_loop_setup {
Subroutine pre_loop_setup: called CC=2 SCAR=6.9
Pod undocumented
28 28 my ( $self ) = @_;
29 28 my $protocol = Mail::Milter::Authentication::Config::get_config()->{'protocol'};
30 28 ▶ if ( $protocol ne 'milter' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol ne "milter") 15 13 28
31 15 warn 'The Auth handler only works with the milter protocol';
32 }
33 }
34  
35 74 ▶sub get_auth_name {
Subroutine get_auth_name: called CC=1 SCAR=0.0
Pod undocumented
36 74 my ($self) = @_;
37 74 my $name = $self->get_symbol('{auth_authen}');
38 74 return $name;
39 }
40  
41 74 ▶sub connect_callback {
Subroutine connect_callback: called CC=1 SCAR=0.0
Pod undocumented
42 74 my ( $self, $hostname, $ip ) = @_;
43 74 $self->{'is_authenticated'} = 0;
44 }
45  
46 74 ▶sub envfrom_callback {
Subroutine envfrom_callback: called CC=4 SCAR=14.0
Pod undocumented
47 74 my ( $self, $env_from ) = @_;
48 74 my $auth_name = $self->get_auth_name();
49 74 ▶ if ($auth_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auth_name) 1 73 74
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 104 ▶sub close_callback {
Subroutine close_callback: called CC=1 SCAR=0.0
Pod undocumented
68 104 my ( $self ) = @_;
69 104 delete $self->{'is_authenticated'};
70 }
71  
72 29 1;
73  
74 __END__
« Authentication/Handler/Logger.pm ↑ Summary Authentication/Handler/AddID.pm »