Auto update user's DN if it changes on the LDAP server. Fixes bug #11217

This commit is contained in:
Colin Kuskie 2009-11-13 16:17:18 -08:00
parent b88a7bc190
commit c4e63dfef0
5 changed files with 110 additions and 22 deletions

View file

@ -19,6 +19,7 @@ use lib "$FindBin::Bin/../lib";
use Test::More;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use Test::Deep;
use Scope::Guard;
#----------------------------------------------------------------------------
@ -36,7 +37,8 @@ my $ldapProps = {
ldapLinkId => sprintf( '%022s', "testlink" ),
};
$session->db->setRow("ldapLink","ldapLinkId",$ldapProps, $ldapProps->{ldapLinkId});
my $ldap = WebGUI::LDAPLink->new( $session, $ldapProps->{ldapLinkId} );
my $ldapLink = WebGUI::LDAPLink->new( $session, $ldapProps->{ldapLinkId} );
my $ldap = $ldapLink->bind;
$session->setting->set('ldapConnection', $ldapProps->{ldapLinkId} );
# Cleanup
@ -50,7 +52,7 @@ my @cleanup = (
#----------------------------------------------------------------------------
# Tests
plan tests => 3; # Increment this number for each test you create
plan tests => 8; # Increment this number for each test you create
#----------------------------------------------------------------------------
# Test Login of existing user
@ -110,5 +112,76 @@ is( $session->user->get('username'), 'Bogs Diamond', 'Bogs was created' )
or diag( $auth->error );
WebGUI::Test->addToCleanup( $session->user );
$session->user({ userId => 1 }); # Restore Visitor
$session->setting->set('automaticLDAPRegistration', 0);
$session->user({ userId => 1 }); # Restore Visitor
#----------------------------------------------------------------------------
# Test DN reset from LDAP
$session->setting->set('automaticLDAPRegistration', 1);
my $result = $ldap->add( 'cn=Brooks Hatley,ou=Convicts,o=shawshank',
attr => [
cn => 'Brooks Hatley',
givenName => 'Brooks',
sn => 'Hatley',
ou => 'Convicts',
o => 'shawshank',
objectClass => [ qw( top inetOrgPerson ) ],
userPassword => 'BrooksHatley',
]
);
$session->request->setup_body({
username => 'Brooks Hatley',
identifier => 'BrooksHatley',
});
$auth = WebGUI::Auth::LDAP->new( $session, 'LDAP' );
$out = $auth->login;
is $session->user->get('username'), 'Brooks Hatley', 'Brooks was created';
cmp_deeply(
$auth->getParams,
{
connectDN => 'cn=Brooks Hatley,ou=Convicts,o=shawshank',
ldapConnection => '00000000000000testlink',
ldapUrl => 'ldaps://smoke.plainblack.com/ou=Convicts,o=shawshank',
},
'authentication information set after creating account'
);
WebGUI::Test->addToCleanup( $session->user, );
$out = $auth->logout;
is $session->user->get('username'), 'Visitor', 'Brooks was logged out';
$ldap->moddn( 'cn=Brooks Hatley,ou=Convicts,o=shawshank',
newrdn => 'cn=Brooks Hatlen',
);
$ldap->modify( 'cn=Brooks Hatlen,ou=Convicts,o=shawshank',
replace => {
sn => 'Hatlen',
userPassword => 'BrooksHatlen',
},
);
$session->request->setup_body({
username => 'Brooks Hatley',
identifier => 'BrooksHatlen',
});
$auth = WebGUI::Auth::LDAP->new( $session, 'LDAP' );
$out = $auth->login;
is $session->user->get('username'), 'Brooks Hatley', 'Brooks was logged in after name change';
cmp_deeply(
$auth->getParams,
{
connectDN => 'cn=Brooks Hatlen,ou=Convicts,o=shawshank',
ldapConnection => '00000000000000testlink',
ldapUrl => 'ldaps://smoke.plainblack.com/ou=Convicts,o=shawshank',
},
'authentication information updated after name change'
);
$ldap->delete( 'cn=Brooks Hatlen,ou=Convicts,o=shawshank' );
$ldap->delete( 'cn=Brooks Hatley,ou=Convicts,o=shawshank' );
$session->setting->set('automaticLDAPRegistration', 0);