Permalink
Browse files

patch from https://rt.cpan.org/Ticket/Display.html?id=80360 credit to…

… Joni Salonen
  • Loading branch information...
1 parent 7830a11 commit 4896a0418ecf704723d91b9d8efae662c0260e79 @karpet committed Oct 25, 2012
Showing with 71 additions and 0 deletions.
  1. +10 −0 lib/Net/LDAP/Server/Test.pm
  2. +61 −0 t/06-no-such-entry.t
@@ -51,6 +51,7 @@ Only one user-level method is implemented: new().
use Carp;
use Net::LDAP::Constant qw(
LDAP_SUCCESS
+ LDAP_NO_SUCH_OBJECT
LDAP_CONTROL_PAGED
LDAP_OPERATIONS_ERROR
LDAP_UNWILLING_TO_PERFORM
@@ -145,6 +146,15 @@ Only one user-level method is implemented: new().
}
+ # Return LDAP_NO_SUCH_OBJECT if base does not exist
+ unless ( exists $Data{$base} ) {
+ return {
+ matchedDN => '',
+ errorMessage => 'No such object: ' . $base,
+ resultCode => LDAP_NO_SUCH_OBJECT
+ };
+ }
+
#warn "stored Data: " . Data::Dump::dump \%Data;
#warn "searching for " . Data::Dump::dump \@filters;
View
@@ -0,0 +1,61 @@
+use strict;
+use warnings;
+use Test::More;
+use Net::LDAP::Server::Test;
+use Net::LDAP;
+use Net::LDAP::LDIF;
+use File::Temp qw(tempfile);
+
+# Create ldif
+my $ldif_entries = <<EOL;
+dn: app=test
+app: test
+objectClass: top
+objectClass: application
+
+dn: msisdn=34610123123,app=test
+objectClass: msisdn
+msisdn: 34610123123
+
+EOL
+
+my ( $fh, $filename ) = tempfile();
+print $fh $ldif_entries;
+close $fh;
+
+# Create and connect to server
+ok( my $server = Net::LDAP::Server::Test->new( 12389, auto_schema => 1 ),
+ "test LDAP server spawned" );
+ok( my $ldap = Net::LDAP->new( 'localhost', port => 12389 ),
+ "new LDAP connection" );
+
+# Load ldif
+my $ldif = Net::LDAP::LDIF->new( $filename, 'r', onerror => 'die',
+ lowercase => 1 );
+while ( not $ldif->eof ) {
+ my $entry = $ldif->read_entry or die "Unable to parse entry";
+ my $mesg = $ldap->add($entry);
+ $mesg->code
+ and die sprintf "Error adding entry [%s]: [%s]", $entry->dn,
+ $mesg->error;
+}
+$ldif->done;
+
+# Just make sure everything is ok :)
+my $mesg = $ldap->search(
+ base => 'msisdn=34610123123,app=test',
+ scope => 'base',
+ filter => 'objectClass=*'
+);
+is( $mesg->code, 0, 'msisdn found' );
+
+# This should work. A base search to a non-existing entry should return 32
+$mesg = $ldap->search(
+ base => 'msisdn=123456789,app=test',
+ scope => 'base',
+ filter => 'objectClass=*'
+);
+is( $mesg->code, 32, 'msisdn not found' );
+is( scalar( $mesg->entries ), 0, 'number of entries equals zero' );
+
+done_testing;

0 comments on commit 4896a04

Please sign in to comment.