Permalink
Browse files

Translate scopes of 0, 1, and 2 into base, one, and sub, as expected

Scope is enumerated as 0, 1, or 2 in the request data, but the
auto_schema search method expected words.

Additionally, when writing tests I discovered that a scope of 'one'
doesn't work when the DN has spaces in it due to an incomplete regex
pattern.  Fix to follow.
  • Loading branch information...
1 parent b080573 commit b70362045e3a4745a21d8b0fe4ba0310010bb263 @tsibley tsibley committed Jul 27, 2012
Showing with 56 additions and 1 deletion.
  1. +3 −1 lib/Net/LDAP/Server/Test.pm
  2. +53 −0 t/05-scope.t
View
4 lib/Net/LDAP/Server/Test.pm
@@ -74,6 +74,7 @@ Only one user-level method is implemented: new().
our %Data; # package data lasts as long as $$ does.
our $Cookies = 0;
our %Searches;
+ my @Scopes = qw(base one sub);
# constructor
sub new {
@@ -128,7 +129,8 @@ Only one user-level method is implemented: new().
my @results;
my $base = $reqData->{baseObject};
- my $scope = $reqData->{scope} || 'sub';
+ # $reqData->{scope} is a enum but we want a word
+ my $scope = $Scopes[defined $reqData->{scope} ? $reqData->{scope} : 0];
my @attrs = @{$reqData->{attributes} || []};
my @filters = ();
View
53 t/05-scope.t
@@ -0,0 +1,53 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use Net::LDAP;
+use Net::LDAP::Server::Test;
+
+my $port = 1024 + int rand(10000) + $$ % 1024;
+
+ok( my $server = Net::LDAP::Server::Test->new( $port, auto_schema => 1 ), "spawn new server" );
+ok( my $ldap = Net::LDAP->new("localhost:$port"), "new LDAP connection" );
+ok( my $rc = $ldap->bind(), "LDAP bind()" );
+
+my @scopes = qw(base one sub);
+
+# Add our nested DNs
+my $dn = my $base = "dc=example,dc=com";
+for my $level (@scopes) {
+ $dn = "cn=$level group,$dn";
+ $ldap->add(
+ $dn,
+ attr => [
+ cn => "$level group",
+ objectClass => 'Group',
+ ],
+ );
+}
+
+# Do scopes work?
+my %expected = (
+ 'base' => 1,
+ 'one' => 2,
+ 'sub' => 3,
+);
+
+for my $scope (@scopes) {
+ my $count = $expected{$scope};
+ my $msg = $ldap->search(
+ base => "cn=base group,$base",
+ scope => $scope,
+ filter => '(objectClass=group)',
+ );
+ ok $msg, "searched with scope $scope";
+ TODO: {
+ local $TODO = "scope of 'one' doesn't work with spaces in the DN (yet)"
+ if $scope eq 'one';
+ is $msg->count, $count, "found $count";
+ }
+}
+
+ok $ldap->unbind, "unbound";
+done_testing;

0 comments on commit b703620

Please sign in to comment.