Client/Auth.pm

filter: Statementstmt 46.4% 26 / 56 Branchbran 2.9% 1 / 34 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 6 / 8 Podpod n/a totaltotal 31.4% 34 / 108 SCAR 51.8
CC
21
Cov
29%
_setup
181.1
_chkauth
20.0
_connect_hook
20.0
CRAP 177.7
« Client/HeartBeat.pm ↑ Summary Client/Version.pm »
1 #+##############################################################################
2 # #
3 # File: Net/STOMP/Client/Auth.pm #
4 # #
5 # Description: Authentication support for Net::STOMP::Client #
6 # #
7 #-##############################################################################
8  
9 #
10 # module definition
11 #
12  
13 package Net::STOMP::Client::Auth;
14 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 our $VERSION = "2.4";
17 2 our $REVISION = sprintf("%d.%02d", q$Revision: 2.1 $ =~ /(\d+)\.(\d+)/);
18  
19 #
20 # used modules
21 #
22  
23 2 ▶use No::Worries::Die qw(dief);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use Params::Validate qw(validate_pos :types);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 #
27 # Authen::Credential is optional
28 #
29  
30 2 eval { require Authen::Credential };
31  
32 #
33 # check a single authentication
34 #
35  
36 sub _chkauth ($) {
37 0 ▶ my($auth) = @_;
Subroutine _chkauth: not called CC=4 SCAR=30.0
38  
39 0 ▶ return(Authen::Credential->parse($auth))
Branch: 1 branch
BranchTrueFalseTotal
if ref $auth eq "" 0 0 0
40 if ref($auth) eq "";
41 0 ▶ return($auth)
Branch: 1 branch
BranchTrueFalseTotal
if ref $auth and $auth->isa("Authen::Credential") 0 0 0
Condition0%0/3
ref $auth and $auth->isa("Authen::Credential")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $auth and $auth->isa("Authen::Credential")
ref $auth $auth->isa("Authen::Credential")
Truth table0%0/3
A and B
A= ref $authB= $auth->isa("Authen::Credential")
ABresult
0X0
100
111
42 if ref($auth) and $auth->isa("Authen::Credential");
43 0 dief("unexpected authentication: %s", $auth);
44 }
45  
46 #
47 # setup
48 #
49  
50 sub _setup ($) {
51 2 ▶ my($self) = @_;
Subroutine _setup: called CC=15 SCAR=52.0
52 2 my(@list, $scheme, $sslopts);
53  
54 # no additional options if Authen::Credential is not available!
55 2 ▶ return() unless $self or $Authen::Credential::VERSION;
Branch: 1 branch
BranchTrueFalseTotal
unless $self or $Authen::Credential::VERSION 2 0 2
Condition33%1/3
$self or $Authen::Credential::VERSION
l!l&&r!l&&!r
002
MC/DC0%0/2
$self or $Authen::Credential::VERSION
$self $Authen::Credential::VERSION
Truth table33%1/3
A or B
A= $selfB= $Authen::Credential::VERSION
ABresult
1X1
011
000
56 # additional options for new()
57 return(
58 0 ▶ "auth" => { optional => 1, type => SCALAR|ARRAYREF|OBJECT },
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 0 0
59 ) unless $self;
60 # check the given authentication
61 0 ▶ return() unless $self->{"auth"};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"auth"} 0 0 0
62 0 ▶ if (ref($self->{"auth"}) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'auth'} eq 'ARRAY') { } 0 0 0
63 0 @list = map(_chkauth($_), @{ $self->{"auth"} });
64 } else {
65 0 @list = (_chkauth($self->{"auth"}));
66 }
67 # make sure we have at most one X.509 and one plain|none
68 0 foreach my $auth (@list) {
69 0 $auth->check();
70 0 $scheme = $auth->scheme();
71 0 ▶ if ($scheme eq "x509") {
Branch: 3 branches
BranchTrueFalseTotal
if ($scheme eq 'x509') { } 0 0 0
elsif ($scheme eq 'none') { } 0 0 0
elsif ($scheme eq 'plain') { } 0 0 0
72 dief("duplicate authentication: %s", $auth->string())
73 0 ▶ if exists($self->{"x509_auth"});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"x509_auth"} 0 0 0
74 0 $self->{"x509_auth"} = $auth;
75 } elsif ($scheme eq "none") {
76 dief("duplicate authentication: %s", $auth->string())
77 0 ▶ if exists($self->{"plain_auth"});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"plain_auth"} 0 0 0
78 0 $self->{"plain_auth"} = ""; # special case...
79 } elsif ($scheme eq "plain") {
80 dief("duplicate authentication: %s", $auth->string())
81 0 ▶ if exists($self->{"plain_auth"});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"plain_auth"} 0 0 0
82 0 $self->{"plain_auth"} = $auth;
83 } else {
84 0 dief("unsupported authentication scheme: %s", $scheme);
85 }
86 }
87 # use the X.509 authentication via the socket options
88 0 ▶ if ($self->{"x509_auth"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"x509_auth"}) 0 0 0
89 0 $sslopts = $self->{"x509_auth"}->prepare("IO::Socket::SSL");
90 0 ▶ while (my($name, $value) = each(%{ $sslopts })) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$sslopts;}) 0 0 0
91 0 $self->{"sockopts"}{$name} = $value;
92 }
93 }
94 }
95  
96 #
97 # hook for the CONNECT frame
98 #
99  
100 sub _connect_hook ($$) {
101 0 ▶ my($self, $frame) = @_;
Subroutine _connect_hook: not called CC=4 SCAR=30.0
102  
103 0 ▶ return unless $self->{"plain_auth"};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"plain_auth"} 0 0 0
104 # do not override what the user did put in the frame
105 0 ▶ $frame->header("login", $self->{"plain_auth"}->name())
Branch: 1 branch
BranchTrueFalseTotal
unless defined $frame->header("login") 0 0 0
106 unless defined($frame->header("login"));
107 0 ▶ $frame->header("passcode", $self->{"plain_auth"}->pass())
Branch: 1 branch
BranchTrueFalseTotal
unless defined $frame->header("passcode") 0 0 0
108 unless defined($frame->header("passcode"));
109 }
110  
111 #
112 # register the setup and hook
113 #
114  
115 {
116 2 ▶ no warnings qw(once);
Subroutine BEGIN: called CC=1 SCAR=0.0
117 2 $Net::STOMP::Client::Setup{"auth"} = \&_setup;
118 2 $Net::STOMP::Client::Hook{"CONNECT"}{"auth"} = \&_connect_hook;
119 }
120  
121 2 1;
122  
123 __END__
« Client/HeartBeat.pm ↑ Summary Client/Version.pm »