[Bps-public-commit] RT-Extension-LDAPImport branch, master, updated. 0.31_03-6-g56c4566
Alex Vandiver
alexmv at bestpractical.com
Thu Feb 17 17:40:12 EST 2011
The branch, master has been updated
via 56c45664c441043d7d8725903930cdd18ace5caf (commit)
from eb51c2cfb81580a0be2be2f1672ae90de28a4d45 (commit)
Summary of changes:
lib/RT/Extension/LDAPImport.pm | 8 ++++++++
t/group-import.t | 20 +++++++++++++++++++-
t/user-import.t | 20 +++++++++++++++++++-
3 files changed, 46 insertions(+), 2 deletions(-)
- Log -----------------------------------------------------------------
commit 56c45664c441043d7d8725903930cdd18ace5caf
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu Feb 17 17:40:05 2011 -0500
Warn and skip numeric users and groups
diff --git a/lib/RT/Extension/LDAPImport.pm b/lib/RT/Extension/LDAPImport.pm
index 6f70fe5..239753d 100644
--- a/lib/RT/Extension/LDAPImport.pm
+++ b/lib/RT/Extension/LDAPImport.pm
@@ -174,6 +174,10 @@ sub import_users {
$self->_warn("No Name or Emailaddress for user, skipping ".Dumper $user);
next;
}
+ if ( $user->{Name} =~ /^[0-9]+$/) {
+ $self->_warn("Skipping user '$user->{Name}', as it is numeric");
+ next;
+ }
$self->_import_user( user => $user, ldap_entry => $entry, import => $args{import} );
$done++;
$self->_debug("Imported $done/$count users");
@@ -562,6 +566,10 @@ sub import_groups {
$self->_warn("No Name for group, skipping ".Dumper $group);
next;
}
+ if ( $group->{Name} =~ /^[0-9]+$/) {
+ $self->_warn("Skipping group '$group->{Name}', as it is numeric");
+ next;
+ }
$self->_import_group( %args, group => $group, ldap_entry => $entry );
$done++;
$self->_debug("Imported $done/$count groups");
diff --git a/t/group-import.t b/t/group-import.t
index 84f0750..bc60565 100644
--- a/t/group-import.t
+++ b/t/group-import.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
use lib 't/lib';
-use RT::Extension::LDAPImport::Test tests => 41;
+use RT::Extension::LDAPImport::Test tests => 43;
eval { require Net::LDAP::Server::Test; 1; } or do {
plan skip_all => 'Unable to test without Net::Server::LDAP::Test';
};
@@ -45,6 +45,14 @@ for ( 1 .. 4 ) {
$ldap->add( $dn, attr => [%$entry] );
push @ldap_group_entries, $entry;
}
+$ldap->add(
+ "cn=42,ou=groups,dc=bestpractical,dc=com",
+ attr => [
+ cn => "42",
+ members => [ "uid=testuser1,ou=foo,dc=bestpractical,dc=com" ],
+ objectClass => 'Group',
+ ],
+);
RT->Config->Set('LDAPHost',"ldap://localhost:$ldap_port");
RT->Config->Set('LDAPMapping',
@@ -108,3 +116,13 @@ for my $entry (@ldap_group_entries) {
}
is(keys %$idlist,0,"No dangling users");
}
+
+my $group = RT::Group->new($RT::SystemUser);
+$group->LoadUserDefinedGroup( "42" );
+ok( !$group->Id );
+
+$group->LoadByCols(
+ Domain => 'UserDefined',
+ Name => "42",
+);
+ok( !$group->Id );
diff --git a/t/user-import.t b/t/user-import.t
index 71f9a11..2611818 100644
--- a/t/user-import.t
+++ b/t/user-import.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
use lib 't/lib';
-use RT::Extension::LDAPImport::Test tests => 8 + 13*2;
+use RT::Extension::LDAPImport::Test tests => 8 + 13*2 + 3;
eval { require Net::LDAP::Server::Test; 1; } or do {
plan skip_all => 'Unable to test without Net::Server::LDAP::Test';
};
@@ -31,6 +31,15 @@ for ( 1 .. 13 ) {
push @ldap_entries, $entry;
$ldap->add( $dn, attr => [%$entry] );
}
+$ldap->add(
+ "uid=42,ou=foo,dc=bestpractical,dc=com",
+ attr => [
+ cn => "Numeric user",
+ mail => "numeric\@invalid.tld",
+ uid => 42,
+ objectclass => 'User',
+ ],
+);
RT->Config->Set('LDAPHost',"ldap://localhost:$ldap_port");
@@ -64,5 +73,14 @@ for my $entry (@ldap_entries) {
ok(!$user->Privileged, "User created as Unprivileged");
}
+# Check that we skipped numeric usernames
+my $user = RT::User->new($RT::SystemUser);
+$user->LoadByCols( EmailAddress => "numeric\@invalid.tld" );
+ok(!$user->Id);
+$user->LoadByCols( Name => 42 );
+ok(!$user->Id);
+$user->Load( 42 );
+ok(!$user->Id);
+
# can't unbind earlier or the server will die
$ldap->unbind;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list