| 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
Condition0%0/2
ref $datasource_config eq "HASH" and scalar keys %{$datasource_config;}
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | next unless ( $ds_conf->{type} eq 'LDAP' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my %s = ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$ldap and UNIVERSAL::isa($ldap, "Net::LDAP")
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")
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||