OpenInteract2/Manage/Website/TestLDAP.pm

filter: Statementstmt 31.3% 16 / 51 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 3 totaltotal 24.7% 21 / 85 CC 11 SCAR 44.5
CC
11
Cov
22%
run_task
132.0
get_brief_description
2.0
BEGIN
1.0
CRAP 85.8
« OpenInteract2/Observer.pm ↑ Summary OpenInteract2/I18N/Initializer.pm »
1 package OpenInteract2::Manage::Website::TestLDAP;
2  
3 # $Id: TestLDAP.pm,v 1.13 2005/03/17 14:58:04 sjn Exp $
4  
5 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 87 ▶use base qw( OpenInteract2::Manage::Website );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 87 ▶use OpenInteract2::Constants qw( :log );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 87 ▶use OpenInteract2::Context qw( CTX );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 87 $OpenInteract2::Manage::Website::TestLDAP::VERSION = sprintf("%d.%02d", q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/);
11  
12 87 ▶sub get_name {
Subroutine get_name: called CC=1 SCAR=0.0
Pod undocumented
13 87 return 'test_ldap';
14 }
15  
16 0 ▶sub get_brief_description {
Subroutine get_brief_description: not called CC=1 SCAR=6.9
Pod undocumented
17 0 return 'Test all configured LDAP connections in a website';
18 }
19  
20 # get_parameters() is inherited from parent
21  
22 0 ▶sub run_task {
Subroutine run_task: not called CC=11 SCAR=48.8
Pod undocumented
23 0 my ( $self ) = @_;
24 0 my $datasource_config = CTX->lookup_datasource_config;
25 0 my ( $error_msg );
26  
27 0 my $action = 'check LDAP connection';
28  
29 # Perform initial sanity checks
30  
31 0 ▶ unless ( ref $datasource_config eq 'HASH' and
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $datasource_config eq "HASH" and scalar keys %{$datasource_config;}) 0 0 0
Condition0%0/2
ref $datasource_config eq "HASH" and scalar keys %{$datasource_config;}
!ll
00
MC/DC0%0/1
ref $datasource_config eq "HASH" and scalar keys %{$datasource_config;}
ref $datasource_config eq "HASH"
Truth table0%0/2
A
A= ref $datasource_config eq "HASH"
Aresult
00
11
32 0 scalar keys %{ $datasource_config } ) {
33 0 $self->_ok( $action,
34 "No datasources defined; no connection attempted." );
35 0 return;
36 }
37  
38 0 my $default_ldap = CTX->lookup_default_ldap_datasource_name;
39  
40 # Initial checks are done, now scroll through each of the
41 # connection hashrefs and try to make a connection
42  
43 DATASOURCE:
44 0 ▶ while ( my ( $name, $ds_conf ) = each %{ $datasource_config } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$datasource_config;}) 0 0 0
45 0 ▶ next unless ( $ds_conf->{type} eq 'LDAP' );
Branch: 1 branch
BranchTrueFalseTotal
unless $ds_conf->{"type"} eq "LDAP" 0 0 0
46 0 ▶ my %s = (
Branch: 1 branch
BranchTrueFalseTotal
$default_ldap eq $name ? : 0 0 0
47 name => $name,
48 is_default => ( $default_ldap eq $name ) ? 'yes' : 'no'
49 );
50  
51 0 my $this_action = "$action '$name'";
52 0 ▶ unless ( $ds_conf->{host} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ds_conf->{"host"}) 0 0 0
53 0 my $msg = "You must define 'host' in the configuration";
54 0 $self->_fail( $this_action, $msg, %s );
55 0 next DATASOURCE;
56 }
57 0 ▶ unless ( $ds_conf->{base_dn} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ds_conf->{"base_dn"}) 0 0 0
58 0 my $msg = "You must define 'base_dn' in the configuration";
59 0 $self->_fail( $this_action, $msg, %s );
60 0 next DATASOURCE;
61 }
62 0 my $ldap = eval { CTX->datasource( $name ) };
63 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
64 0 $self->_fail( $this_action, "$@", %s );
65 0 next DATASOURCE;
66 }
67 0 ▶ unless ( $ldap and UNIVERSAL::isa( $ldap, 'Net::LDAP' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ldap and UNIVERSAL::isa($ldap, "Net::LDAP")) 0 0 0
Condition0%0/3
$ldap and UNIVERSAL::isa($ldap, "Net::LDAP")
!ll&&!rl&&r
000
MC/DC0%0/2
$ldap and UNIVERSAL::isa($ldap, "Net::LDAP")
$ldap UNIVERSAL::isa($ldap, "Net::LDAP")
Truth table0%0/3
A and B
A= $ldapB= UNIVERSAL::isa($ldap, "Net::LDAP")
ABresult
0X0
100
111
68 0 my $msg = "Connect failed (no error, but no LDAP handle returned)";
69 0 $self->_fail( $this_action, $msg, %s );
70 0 next DATASOURCE;
71 }
72 0 my $msg = "Connected and bound to directory ok";
73 0 $self->_ok( $this_action, $msg, %s );
74 }
75 0 return;
76 }
77  
78 87 OpenInteract2::Manage->register_factory_type( get_name() => __PACKAGE__ );
79  
80 87 1;
81  
82 __END__
« OpenInteract2/Observer.pm ↑ Summary OpenInteract2/I18N/Initializer.pm »