Skip to content
Browse files

Some testcase tweaks

  • Loading branch information...
1 parent 844289b commit ccae27f0e4fb6dfb2dcf00dcf774bbb6475438b3 @gbarr gbarr committed Feb 4, 2002
Showing with 147 additions and 107 deletions.
  1. +1 −0 data/00-in.ldif
  2. +17 −6 data/core.schema
  3. +5 −1 data/slapd2-conf.in
  4. +34 −24 t/00ldif-entry.t
  5. +6 −8 t/50populate.t
  6. +7 −12 t/51search.t
  7. +5 −8 t/52modify.t
  8. +11 −8 t/53schema.t
  9. +3 −3 t/54dse.t
  10. +12 −19 t/55ssl.t
  11. +46 −18 t/common.pl
View
1 data/00-in.ldif
@@ -1,3 +1,4 @@
+version: 1
dn: o=University of Michigan, c=US
objectclass: top
objectclass: organization
View
23 data/core.schema
@@ -1,4 +1,4 @@
-# $OpenLDAP: pkg/ldap/servers/slapd/schema/core.schema,v 1.7.2.8 2000/08/26 17:58:18 kurt Exp $
+# $OpenLDAP: pkg/ldap/servers/slapd/schema/core.schema,v 1.7.2.12 2001/09/18 18:34:22 kurt Exp $
#
# OpenLDAP Core schema
#
@@ -77,8 +77,9 @@ attributetype ( 2.5.21.8 NAME 'matchingRuleUse'
EQUALITY objectIdentifierFirstComponentMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.31 USAGE directoryOperation )
-# From X.500(97?)
+# From X.500(93)
attributetype ( 2.5.21.9 NAME 'structuralObjectClass'
+ DESC 'X.500(93) structural object class'
EQUALITY objectIdentifierMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.38
NO-USER-MODIFICATION SINGLE-VALUE USAGE directoryOperation )
@@ -456,8 +457,8 @@ objectclass ( 1.3.6.1.4.1.1466.101.120.111 NAME 'extensibleObject'
#
attributetype ( 1.3.6.1.4.1.250.1.57 NAME 'labeledURI'
DESC 'RFC2079: Uniform Resource Identifier with optional label'
- EQUALITY caseExactIA5Match
- SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
+ EQUALITY caseExactMatch
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
objectclass ( 1.3.6.1.4.1.250.3.15 NAME 'labeledURIObject'
DESC 'RFC2079: object that contains the URI attribute type'
@@ -528,8 +529,8 @@ objectclass ( 1.3.6.1.1.3.1 NAME 'uidObject'
#
attributetype ( 2.16.840.1.113730.3.1.34 NAME 'ref'
DESC 'Named referral'
- EQUALITY caseExactIA5Match
- SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
+ EQUALITY caseExactMatch
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
USAGE distributedOperation )
objectclass ( 2.16.840.1.113730.3.2.6 NAME 'referral'
@@ -570,6 +571,16 @@ attributetype ( 1.3.6.1.4.1.250.1.32
SINGLE-VALUE )
#
+# draft-zeilenga-ldap-features-xx.txt (supportedFeatures)
+#
+attributetype ( 1.3.6.1.4.1.4203.1.3.5
+ NAME 'supportedFeatures'
+ DESC 'features supported by the server'
+ EQUALITY objectIdentifierMatch
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.38
+ USAGE dSAOperation )
+
+#
# OpenLDAP specific schema items
#
attributetype ( 1.3.6.1.4.1.4203.1.3.1
View
6 data/slapd2-conf.in
@@ -20,4 +20,8 @@ rootpw $PASSWD
TLSCertificateFile ./data/cert.pem
TLSCertificateKeyFile ./data/key.pem
-
+#sasl-host localhost
+#sasl-realm testing
+#sasl-secprops passcred
+#sasl-secprops noanonymous
+sasl-secprops none
View
58 t/00ldif-entry.t
@@ -5,20 +5,28 @@ BEGIN {
}
-print "1..9\n";
+print "1..11\n";
use Net::LDAP::LDIF;
-my $infile = "data/00-in.ldif";
-my $outfile = "$TEMPDIR/00-out1.ldif";
-my $cmpfile = $infile;
+my $infile = "data/00-in.ldif";
+my $outfile1 = "$TEMPDIR/00-out1.ldif";
+my $outfile2 = "$TEMPDIR/00-out2.ldif";
+my $cmpfile1 = "data/00-cmp.ldif";
+my $cmpfile2 = $infile;
-@entry = Net::LDAP::LDIF->new($infile,"r")->read;
+my $ldif = Net::LDAP::LDIF->new($infile,"r");
-Net::LDAP::LDIF->new($outfile,"w")->write(@entry);
+@entry = $ldif->read;
-print "not " if compare($cmpfile,$outfile);
-print "ok 1\n";
+ok($ldif->version == 1, "version == 1");
+
+Net::LDAP::LDIF->new($outfile1,"w")->write(@entry);
+Net::LDAP::LDIF->new($outfile2,"w", version => 1)->write(@entry);
+
+ok(!compare($cmpfile1,$outfile1), $cmpfile1);
+
+ok(!compare($cmpfile2,$outfile2), $cmpfile2);
$e = $entry[0];
@@ -36,33 +44,35 @@ $ldif = Net::LDAP::LDIF->new($outfile,"w");
$ldif->write($e);
$ldif->write_cmd($e);
$ldif->done;
-print "not " if compare($cmpfile,$outfile);
-print "ok 2\n";
+ok(!compare($cmpfile,$outfile), $cmpfile);
$e->add('name' => 'Graham Barr');
$e->add('name;en-us' => 'Bob');
-print "not " unless join(":",sort $e->attributes) eq "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:name;en-us:o:postaladdress:second:st:streetaddress:telephonenumber";
-print "ok 3\n";
+print "not " unless
+ok(
+ join(":",sort $e->attributes)
+ eq
+ "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:name;en-us:o:postaladdress:second:st:streetaddress:telephonenumber",
+ "attributes");
-print "not " unless join(":",sort $e->attributes(nooptions => 1)) eq "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:o:postaladdress:second:st:streetaddress:telephonenumber";
-print "ok 4\n";
+print "not " unless
+ok(
+ join(":",sort $e->attributes(nooptions => 1))
+ eq
+ "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:o:postaladdress:second:st:streetaddress:telephonenumber",
+ "attributes - nooptions");
$r = $e->get_value('name', asref => 1);
-print "not " unless $r and @$r == 1 and $r->[0] eq 'Graham Barr';
-print "ok 5\n";
+ok(($r and @$r == 1 and $r->[0] eq 'Graham Barr'), "name eq Graham Barr");
$r = $e->get_value('name;en-us', asref => 1);
-print "not " unless $r and @$r == 1 and $r->[0] eq 'Bob';
-print "ok 6\n";
+ok(($r and @$r == 1 and $r->[0] eq 'Bob'), "name;en-us eq Bob");
$r = $e->get_value('name', alloptions => 1, asref => 1);
-print "not " unless $r and join("*", sort keys %$r) eq "*;en-us";
-print "ok 7\n";
+ok(($r and join("*", sort keys %$r) eq "*;en-us"), "name keys");
-print "not " unless $r and $r->{''} and @{$r->{''}} == 1 and $r->{''}[0] eq 'Graham Barr';
-print "ok 8\n";
+ok(($r and $r->{''} and @{$r->{''}} == 1 and $r->{''}[0] eq 'Graham Barr'), "name alloptions");
-print "not " unless $r and $r->{';en-us'} and @{$r->{';en-us'}} == 1 and $r->{';en-us'}[0] eq 'Bob';
-print "ok 9\n";
+ok(($r and $r->{';en-us'} and @{$r->{';en-us'}} == 1 and $r->{';en-us'}[0] eq 'Bob'), "name alloptions Bob");
View
14 t/50populate.t
@@ -8,18 +8,16 @@ BEGIN {
print "1..7\n";
$ldap = client();
-print "ok 1\n";
+ok($ldap, "client");
$mesg = $ldap->bind($MANAGERDN, password => $PASSWD);
-print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code;
-print "ok 2\n";
+ok(!$mesg->code, "bind: " . $mesg->code . ": " . $mesg->error);
+
+ok(ldif_populate($ldap, "data/50-in.ldif"), "data/50-in.ldif");
-print "not " unless ldif_populate($ldap, "data/50-in.ldif");
-print "ok 3\n";
$mesg = $ldap->search(base => $BASEDN, filter => 'objectclass=*');
-print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code;
-print "ok 4\n";
+ok(!$mesg->code, "search: " . $mesg->code . ": " . $mesg->error);
-compare_ldif("50",5,$mesg,$mesg->sorted);
+compare_ldif("50",$mesg,$mesg->sorted);
View
19 t/51search.t
@@ -5,38 +5,33 @@ BEGIN {
start_server();
}
-my $i = 4;
-
-
print "1..15\n";
$ldap = client();
-print "ok 1\n";
+ok($ldap, "client");
$mesg = $ldap->bind($MANAGERDN, password => $PASSWD);
-print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code;
-print "ok 2\n";
+ok(!$mesg->code, "bind: " . $mesg->code . ": " . $mesg->error);
-print "not " unless ldif_populate($ldap, "data/51-in.ldif");
-print "ok 3\n";
+ok(ldif_populate($ldap, "data/51-in.ldif"), "data/51-in.ldif");
# now search the database
# Exact searching
$mesg = $ldap->search(base => $BASEDN, filter => 'sn=jensen');
-$i += compare_ldif("51a",$i,$mesg,$mesg->sorted);
+compare_ldif("51a",$mesg,$mesg->sorted);
# Or searching
$mesg = $ldap->search(base => $BASEDN, filter => '(|(objectclass=groupofnames)(sn=jones))');
-$i += compare_ldif("51b",$i,$mesg,$mesg->sorted);
+compare_ldif("51b",$mesg,$mesg->sorted);
# And searching
$mesg = $ldap->search(base => $BASEDN, filter => '(&(objectclass=groupofnames)(cn=A*))');
-$i += compare_ldif("51c",$i,$mesg,$mesg->sorted);
+compare_ldif("51c",$mesg,$mesg->sorted);
# Not searching
$mesg = $ldap->search(base => $BASEDN, filter => '(!(objectclass=person))');
-$i += compare_ldif("51d",$i,$mesg,$mesg->sorted);
+compare_ldif("51d",$mesg,$mesg->sorted);
View
13 t/52modify.t
@@ -8,23 +8,20 @@ BEGIN {
print "1..7\n";
$ldap = client();
-print "ok 1\n";
+ok($ldap, "client");
$mesg = $ldap->bind($MANAGERDN, password => $PASSWD);
-print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code;
-print "ok 2\n";
+ok(!$mesg->code, "bind: " . $mesg->code . ": " . $mesg->error);
-print "not " unless ldif_populate($ldap, "data/52-in.ldif");
-print "ok 3\n";
+ok(ldif_populate($ldap, "data/52-in.ldif"), "data/52-in.ldif");
# load modify LDIF
-print "not " unless ldif_populate($ldap, "data/52-mod.ldif", 'modify');
-print "ok 4\n";
+ok(ldif_populate($ldap, "data/52-mod.ldif", 'modify'), "data/52-mod.ldif");
# now search the database
$mesg = $ldap->search(base => $BASEDN, filter => 'objectclass=*');
-compare_ldif("52",5,$mesg,$mesg->sorted);
+compare_ldif("52",$mesg,$mesg->sorted);
View
19 t/53schema.t
@@ -6,32 +6,35 @@ print "1..7\n";
my $schema = Net::LDAP::Schema->new( "data/schema.in" ) or die "Cannot open schema";
print "ok 1\n";
-my @atts = sort $schema->attributes();
+my @atts = $schema->all_attributes();
print "not " unless @atts == 55;
print "ok 2\n";
print "The schema contains ", scalar @atts, " attributes\n";
-my @ocs = $schema->objectclasses();
+my @ocs = $schema->all_objectclasses();
print "not " unless @ocs == 22;
print "ok 3\n";
print "The schema contains ", scalar @ocs, " object classes\n";
@atts = $schema->must( "person" );
-print "not " unless join(' ',@atts) eq join(' ',qw(cn sn));
+print "not " unless join(' ', sort map $_->{name}, @atts) eq join(' ',sort qw(cn sn objectClass));
print "ok 4\n";
print "The 'person' OC must have these attributes [",
- join( ",", @atts ),
+ join( ",", map $_->{name}, @atts ),
"]\n";
@atts = $schema->may( "mhsOrganizationalUser" );
print "not " if @atts;
print "ok 5\n";
-print "The 'mhsOrganizationalUser' OC must have these attributes [",
- join( ",", @atts ),
+print "The 'mhsOrganizationalUser' OC may have these attributes [",
+ join( ",", map $_->{name}, @atts ),
"]\n";
-print "not " if defined $schema->item('distinguishedName','max_length');
+print "not " if defined $schema->attribute('distinguishedName')->{max_length};
print "ok 6\n";
-print "not " unless $schema->item('userPassword','max_length') == 128;
+print "not " unless $schema->attribute('userPassword')->{max_length} == 128;
print "ok 7\n";
+
+use Data::Dumper;
+print Dumper($schema);
View
6 t/54dse.t
@@ -8,10 +8,10 @@ BEGIN {
print "1..2\n";
$ldap = client();
-print "ok 1\n";
+ok($ldap, "client");
-$dse = $ldap->root_dse or print "not ";
-print "ok 2\n";
+$dse = $ldap->root_dse;
+ok($dse, "dse");
use Net::LDAP::LDIF;
Net::LDAP::LDIF->new(qw(- w))->write_entry($dse) if $dse;
View
31 t/55ssl.t
@@ -8,40 +8,33 @@ BEGIN {
print "1..15\n";
$ldap = client();
-print "ok 1\n";
+ok($ldap, "client");
$mesg = $ldap->bind($MANAGERDN, password => $PASSWD, version => 3);
-print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code;
-print "ok 2\n";
+ok(!$mesg->code, "bind: " . $mesg->code . ": " . $mesg->error);
-print "not " unless ldif_populate($ldap, "data/50-in.ldif");
-print "ok 3\n";
+ok(ldif_populate($ldap, "data/50-in.ldif"), "data/50-in.ldif");
$mesg = $ldap->start_tls;
-print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code;
-print "ok 4\n";
+ok(!$mesg->code, "start_stl: " . $mesg->code . ": " . $mesg->error);
$mesg = $ldap->start_tls;
-print "# ",$mesg->code,": ",$mesg->error,"\nnot " unless $mesg->code;
-print "ok 5\n";
+ok($mesg->code, "start_stl: " . $mesg->code . ": " . $mesg->error);
$mesg = $ldap->search(base => $BASEDN, filter => 'objectclass=*');
-print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code;
-print "ok 6\n";
+ok(!$mesg->code, "search: " . $mesg->code . ": " . $mesg->error);
-compare_ldif("50",7,$mesg,$mesg->sorted);
+compare_ldif("50",$mesg,$mesg->sorted);
-$ldap = client(ssl => 1) or print "not ";
-print "ok 10\n";
+$ldap = client(ssl => 1);
+ok($ldap, "ssl client");
$mesg = $ldap->start_tls;
-print "# ",$mesg->code,": ",$mesg->error,"\nnot " unless $mesg->code;
-print "ok 11\n";
+ok($mesg->code, "start_stl: " . $mesg->code . ": " . $mesg->error);
$mesg = $ldap->search(base => $BASEDN, filter => 'objectclass=*');
-print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code;
-print "ok 12\n";
+ok(!$mesg->code, "search: " . $mesg->code . ": " . $mesg->error);
-compare_ldif("50",13,$mesg,$mesg->sorted);
+compare_ldif("50",$mesg,$mesg->sorted);
View
64 t/common.pl
@@ -88,7 +88,7 @@ sub start_server {
open(STDOUT,">&STDERR");
close(STDIN);
- exec(@LDAPD);
+ exec(@LDAPD) or die "cannot exec @LDAPD";
}
sleep 2; # wait for server to start
@@ -128,24 +128,18 @@ sub client {
}
sub compare_ldif {
- my($test,$test_num,$mesg) = splice(@_,0,3);
-
- if ($mesg->code) {
- print $mesg->error,"\n";
- print "not ok ",$test_num++,"\n";
- print "not ok ",$test_num++,"\n";
- print "not ok ",$test_num++,"\n";
- return 3;
+ my($test,$mesg) = splice(@_,0,2);
+
+ unless (ok(!$mesg->code, $mesg->error)) {
+ skip(2, $mesg->error);
+ return;
}
- print "ok ",$test_num++,"\n";
my $ldif = Net::LDAP::LDIF->new("$TEMPDIR/${test}-out.ldif","w", lowercase => 1);
- unless ($ldif) {
- print "not ok",$test_num++,"\n";
- print "not ok",$test_num++,"\n";
- return 3;
+ unless (ok($ldif, "Read ${test}-out.ldif")) {
+ skip(1,"Read error");
+ return;
}
- print "ok ",$test_num++,"\n";
foreach $entry (@_) {
foreach $attr ($entry->attributes) {
@@ -156,9 +150,7 @@ sub compare_ldif {
$ldif->done; # close the file;
- compare("$TEMPDIR/${test}-out.ldif","data/${test}-cmp.ldif") && print "not ";
- print "ok ",$test_num++,"\n";
- 3;
+ ok(!compare("$TEMPDIR/${test}-out.ldif","data/${test}-cmp.ldif"), "data/${test}-cmp.ldif");
}
require File::Compare;
@@ -189,4 +181,40 @@ sub ldif_populate {
$ok;
}
+my $number = 0;
+sub ok {
+ my ($condition, $name) = @_;
+
+ my $message = $condition ? "ok " : "not ok ";
+ $message .= ++$number;
+ $message .= " # $name" if defined $name;
+ print $message, "\n";
+ return $condition;
+}
+
+sub is {
+ my ($got, $expected, $name) = @_;
+
+ for ($got, $expected) {
+ $_ = 'undef' unless defined $_;
+ }
+
+ unless (ok($got eq $expected, $name)) {
+ warn "Got: '$got'\nExpected: '$expected'\n" . join(' ', caller) . "\n";
+ }
+}
+
+sub skip {
+ my ($reason, $num) = @_;
+ $reason ||= '';
+ $number ||= 1;
+
+ for (1 .. $num) {
+ $number++;
+ print "ok $number # skip $reason\n";
+ }
+}
+
+1;
+
1;

0 comments on commit ccae27f

Please sign in to comment.
Something went wrong with that request. Please try again.