1#! /bin/sh 2# $OpenLDAP$ 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 1998-2011 The OpenLDAP Foundation. 6## All rights reserved. 7## 8## Redistribution and use in source and binary forms, with or without 9## modification, are permitted only as authorized by the OpenLDAP 10## Public License. 11## 12## A copy of this license is available in the file LICENSE in the 13## top-level directory of the distribution or, alternatively, at 14## <http://www.OpenLDAP.org/license.html>. 15 16echo "running defines.sh" 17. $SRCDIR/scripts/defines.sh 18 19if test $BACKSQL = "sqlno" ; then 20 echo "SQL backend not available, test skipped" 21 exit 0 22fi 23 24if test $RDBMS = "rdbmsno" ; then 25 echo "SQL test not requested, test skipped" 26 exit 0 27fi 28 29mkdir -p $TESTDIR 30 31echo "Starting slapd on TCP/IP port $PORT1..." 32. $CONFFILTER $BACKEND $MONITORDB < $SQLCONF > $CONF1 33$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 & 34PID=$! 35if test $WAIT != 0 ; then 36 echo PID $PID 37 read foo 38fi 39KILLPIDS="$PID" 40 41echo "Testing SQL backend read operations..." 42for i in 0 1 2 3 4 5; do 43 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \ 44 'objectclass=*' > /dev/null 2>&1 45 RC=$? 46 if test $RC = 0 ; then 47 break 48 fi 49 echo "Waiting 5 seconds for slapd to start..." 50 sleep 5 51done 52 53if test $RC != 0 ; then 54 echo "ldapsearch failed ($RC)!" 55 test $KILLSERVERS != no && kill -HUP $KILLPIDS 56 exit $RC 57fi 58 59BASEDN="dc=example,dc=com" 60BINDDN="cn=Mitya Kovalev,${BASEDN}" 61BINDPW="mit" 62echo -n "Testing correct bind... " 63$LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW 64RC=$? 65if test $RC != 0 ; then 66 echo "ldapwhoami failed ($RC)!" 67 test $KILLSERVERS != no && kill -HUP $KILLPIDS 68 exit $RC 69fi 70 71echo -n "Testing incorrect bind (should fail)... " 72$LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w "XXX" 73RC=$? 74if test $RC = 0 ; then 75 echo "ldapwhoami should have failed ($RC)!" 76 test $KILLSERVERS != no && kill -HUP $KILLPIDS 77 exit 1 78fi 79 80echo "Testing baseobject search..." 81echo "# Testing baseobject search..." >> $SEARCHOUT 82$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -s base -S "" \ 83 >> $SEARCHOUT 2>&1 84 85RC=$? 86if test $RC != 0 ; then 87 echo "ldapsearch failed ($RC)!" 88 test $KILLSERVERS != no && kill -HUP $KILLPIDS 89 exit $RC 90fi 91 92echo "Testing onelevel search..." 93echo "# Testing onelevel search..." >> $SEARCHOUT 94$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -s one -S "" \ 95 >> $SEARCHOUT 2>&1 96 97RC=$? 98if test $RC != 0 ; then 99 echo "ldapsearch failed ($RC)!" 100 test $KILLSERVERS != no && kill -HUP $KILLPIDS 101 exit $RC 102fi 103 104echo "Testing subtree search..." 105echo "# Testing subtree search..." >> $SEARCHOUT 106$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 107 >> $SEARCHOUT 2>&1 108 109RC=$? 110if test $RC != 0 ; then 111 echo "ldapsearch failed ($RC)!" 112 test $KILLSERVERS != no && kill -HUP $KILLPIDS 113 exit $RC 114fi 115 116echo "Testing subtree search with manageDSAit..." 117echo "# Testing subtree search with manageDSAit..." >> $SEARCHOUT 118$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -M -S "" '*' ref \ 119 >> $SEARCHOUT 2>&1 120 121RC=$? 122if test $RC != 0 ; then 123 echo "ldapsearch failed ($RC)!" 124 test $KILLSERVERS != no && kill -HUP $KILLPIDS 125 exit $RC 126fi 127 128echo "Testing invalid filter..." 129echo "# Testing invalid filter..." >> $SEARCHOUT 130$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(foo=)" \ 131 >> $SEARCHOUT 2>&1 132 133RC=$? 134if test $RC != 0 ; then 135 echo "ldapsearch failed ($RC)!" 136 test $KILLSERVERS != no && kill -HUP $KILLPIDS 137 exit $RC 138fi 139 140echo "Testing exact search..." 141echo "# Testing exact search..." >> $SEARCHOUT 142$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(sn=Kovalev)" \ 143 >> $SEARCHOUT 2>&1 144 145RC=$? 146if test $RC != 0 ; then 147 echo "ldapsearch failed ($RC)!" 148 test $KILLSERVERS != no && kill -HUP $KILLPIDS 149 exit $RC 150fi 151 152echo "Testing substrings initial search..." 153echo "# Testing substrings initial search..." >> $SEARCHOUT 154$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(cn=m*)" \ 155 >> $SEARCHOUT 2>&1 156 157RC=$? 158if test $RC != 0 ; then 159 echo "ldapsearch failed ($RC)!" 160 test $KILLSERVERS != no && kill -HUP $KILLPIDS 161 exit $RC 162fi 163 164echo "Testing substrings any search..." 165echo "# Testing substrings any search..." >> $SEARCHOUT 166$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(cn=*m*)" \ 167 >> $SEARCHOUT 2>&1 168 169RC=$? 170if test $RC != 0 ; then 171 echo "ldapsearch failed ($RC)!" 172 test $KILLSERVERS != no && kill -HUP $KILLPIDS 173 exit $RC 174fi 175 176echo "Testing substrings final search..." 177echo "# Testing substrings final search..." >> $SEARCHOUT 178$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(cn=*v)" \ 179 >> $SEARCHOUT 2>&1 180 181RC=$? 182if test $RC != 0 ; then 183 echo "ldapsearch failed ($RC)!" 184 test $KILLSERVERS != no && kill -HUP $KILLPIDS 185 exit $RC 186fi 187 188echo "Testing approx search..." 189echo "# Testing approx search..." >> $SEARCHOUT 190$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(sn~=kovalev)" \ 191 >> $SEARCHOUT 2>&1 192 193RC=$? 194if test $RC != 0 ; then 195 echo "ldapsearch failed ($RC)!" 196 test $KILLSERVERS != no && kill -HUP $KILLPIDS 197 exit $RC 198fi 199 200echo "Testing extensible filter search..." 201echo "# Testing extensible filter search..." >> $SEARCHOUT 202$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 203 "(sn:caseExactMatch:=Kovalev)" >> $SEARCHOUT 2>&1 204 205RC=$? 206if test $RC != 0 ; then 207 echo "ldapsearch failed ($RC)!" 208 test $KILLSERVERS != no && kill -HUP $KILLPIDS 209 exit $RC 210fi 211 212echo "Testing search for telephoneNumber..." 213echo "# Testing search for telephoneNumber..." >> $SEARCHOUT 214$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 215 "(telephoneNumber=3322334)" >> $SEARCHOUT 2>&1 216 217RC=$? 218if test $RC != 0 ; then 219 echo "ldapsearch failed ($RC)!" 220 test $KILLSERVERS != no && kill -HUP $KILLPIDS 221 exit $RC 222fi 223 224echo "Testing AND search..." 225echo "# Testing AND search..." >> $SEARCHOUT 226$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 227 "(&(sn=kovalev)(givenName=mitya))" >> $SEARCHOUT 2>&1 228 229RC=$? 230if test $RC != 0 ; then 231 echo "ldapsearch failed ($RC)!" 232 test $KILLSERVERS != no && kill -HUP $KILLPIDS 233 exit $RC 234fi 235 236echo "Testing AND search on objectClass..." 237echo "# Testing AND search on objectClass..." >> $SEARCHOUT 238$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 239 "(&(objectClass=organization)(objectClass=dcObject))" >> $SEARCHOUT 2>&1 240 241RC=$? 242if test $RC != 0 ; then 243 echo "ldapsearch failed ($RC)!" 244 test $KILLSERVERS != no && kill -HUP $KILLPIDS 245 exit $RC 246fi 247 248echo "Testing OR search..." 249echo "# Testing OR search..." >> $SEARCHOUT 250$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 251 "(|(sn=kovalev)(givenName=mitya))" >> $SEARCHOUT 2>&1 252 253RC=$? 254if test $RC != 0 ; then 255 echo "ldapsearch failed ($RC)!" 256 test $KILLSERVERS != no && kill -HUP $KILLPIDS 257 exit $RC 258fi 259 260echo "Testing OR search on objectClass..." 261echo "# Testing OR search on objectClass..." >> $SEARCHOUT 262$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 263 "(|(objectClass=document)(objectClass=organization))" \ 264 >> $SEARCHOUT 2>&1 265 266RC=$? 267if test $RC != 0 ; then 268 echo "ldapsearch failed ($RC)!" 269 test $KILLSERVERS != no && kill -HUP $KILLPIDS 270 exit $RC 271fi 272 273echo "Testing NOT search..." 274echo "# Testing NOT search..." >> $SEARCHOUT 275$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 276 '(!(sn=kovalev))' >> $SEARCHOUT 2>&1 277 278RC=$? 279if test $RC != 0 ; then 280 echo "ldapsearch failed ($RC)!" 281 test $KILLSERVERS != no && kill -HUP $KILLPIDS 282 exit $RC 283fi 284 285echo "Testing NOT search on objectClass..." 286echo "# Testing NOT search on objectClass..." >> $SEARCHOUT 287$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 288 '(!(objectClass=inetOrgPerson))' >> $SEARCHOUT 2>&1 289 290RC=$? 291if test $RC != 0 ; then 292 echo "ldapsearch failed ($RC)!" 293 test $KILLSERVERS != no && kill -HUP $KILLPIDS 294 exit $RC 295fi 296 297echo "Testing NOT search on \"auxiliary\" objectClass..." 298echo "# Testing NOT search on \"auxiliary\" objectClass..." >> $SEARCHOUT 299$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 300 '(!(objectClass=dcObject))' >> $SEARCHOUT 2>&1 301 302RC=$? 303if test $RC != 0 ; then 304 echo "ldapsearch failed ($RC)!" 305 test $KILLSERVERS != no && kill -HUP $KILLPIDS 306 exit $RC 307fi 308 309#### Needs work... 310echo "Testing NOT presence search... (disabled)" 311###echo "# Testing NOT presence search..." >> $SEARCHOUT 312###$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 313### '(!(sn=*))' >> $SEARCHOUT 2>&1 314### 315###RC=$? 316###if test $RC != 0 ; then 317### echo "ldapsearch failed ($RC)!" 318### test $KILLSERVERS != no && kill -HUP $KILLPIDS 319### exit $RC 320###fi 321 322echo "Testing attribute inheritance in filter..." 323echo "# Testing attribute inheritance in filter..." >> $SEARCHOUT 324$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 325 "(name=example)" >> $SEARCHOUT 2>&1 326 327RC=$? 328if test $RC != 0 ; then 329 echo "ldapsearch failed ($RC)!" 330 test $KILLSERVERS != no && kill -HUP $KILLPIDS 331 exit $RC 332fi 333 334# ITS#4604 335echo "Testing undefined attribute in filter..." 336echo "# Testing undefined attribute in filter..." >> $SEARCHOUT 337$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 338 "(|(o=example)(foobar=x))" >> $SEARCHOUT 2>&1 339 340RC=$? 341if test $RC != 0 ; then 342 echo "ldapsearch failed ($RC)!" 343 test $KILLSERVERS != no && kill -HUP $KILLPIDS 344 exit $RC 345fi 346 347echo "Testing objectClass inheritance in filter..." 348echo "# Testing objectClass inheritance in filter..." >> $SEARCHOUT 349$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 350 "(objectClass=person)" >> $SEARCHOUT 2>&1 351 352RC=$? 353if test $RC != 0 ; then 354 echo "ldapsearch failed ($RC)!" 355 test $KILLSERVERS != no && kill -HUP $KILLPIDS 356 exit $RC 357fi 358 359echo "Testing \"auxiliary\" objectClass in filter..." 360echo "# Testing \"auxiliary\" objectClass in filter..." >> $SEARCHOUT 361$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 362 "(objectClass=dcObject)" >> $SEARCHOUT 2>&1 363 364RC=$? 365if test $RC != 0 ; then 366 echo "ldapsearch failed ($RC)!" 367 test $KILLSERVERS != no && kill -HUP $KILLPIDS 368 exit $RC 369fi 370 371echo "Testing hasSubordinates in filter..." 372echo "# Testing hasSubordinates in filter..." >> $SEARCHOUT 373$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 374 "(hasSubordinates=TRUE)" >> $SEARCHOUT 2>&1 375 376RC=$? 377if test $RC != 0 ; then 378 echo "ldapsearch failed ($RC)!" 379 test $KILLSERVERS != no && kill -HUP $KILLPIDS 380 exit $RC 381fi 382 383echo "Testing entryUUID in filter..." 384echo "# Testing entryUUID in filter..." >> $SEARCHOUT 385$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 386 "(entryUUID=00000001-0000-0001-0000-000000000000)" >> $SEARCHOUT 2>&1 387 388RC=$? 389if test $RC != 0 ; then 390 echo "ldapsearch failed ($RC)!" 391 test $KILLSERVERS != no && kill -HUP $KILLPIDS 392 exit $RC 393fi 394 395echo "Testing attribute inheritance in requested attributes..." 396echo "# Testing attribute inheritance in requested attributes..." >> $SEARCHOUT 397$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 398 "(sn=kovalev)" name >> $SEARCHOUT 2>&1 399 400RC=$? 401if test $RC != 0 ; then 402 echo "ldapsearch failed ($RC)!" 403 test $KILLSERVERS != no && kill -HUP $KILLPIDS 404 exit $RC 405fi 406 407echo "Testing objectClass in requested attributes..." 408echo "# Testing objectClass in requested attributes..." >> $SEARCHOUT 409$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 410 objectClass >> $SEARCHOUT 2>&1 411 412RC=$? 413if test $RC != 0 ; then 414 echo "ldapsearch failed ($RC)!" 415 test $KILLSERVERS != no && kill -HUP $KILLPIDS 416 exit $RC 417fi 418 419echo "Testing operational attributes in request..." 420echo "# Testing operational attributes in request..." >> $SEARCHOUT 421$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \ 422 '+' 2>&1 > $SEARCHFLT 423 424RC=$? 425if test $RC != 0 ; then 426 echo "ldapsearch failed ($RC)!" 427 test $KILLSERVERS != no && kill -HUP $KILLPIDS 428 exit $RC 429fi 430 431grep -v '^entryCSN:' $SEARCHFLT >> $SEARCHOUT 432 433SIZELIMIT=4 434echo "Testing size limit..." 435$LDAPRSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \ 436 -z $SIZELIMIT -S "" '(objectClass=*)' >$SEARCHFLT 2>&1 437RC=$? 438COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHFLT` 439case $RC in 440 0) 441 if test x"$COUNT" != x ; then 442 if test "$COUNT" -gt "$SIZELIMIT" ; then 443 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT" 444 test $KILLSERVERS != no && kill -HUP $KILLPIDS 445 exit 1 446 fi 447 echo "...didn't bump into the requested size limit ($SIZELIMIT; got $COUNT entries)" 448 else 449 echo "...error: did not expect ldapsearch success ($RC)!" 450 test $KILLSERVERS != no && kill -HUP $KILLPIDS 451 exit 1 452 fi 453 ;; 454 4) 455 if test x"$COUNT" != x ; then 456 if test "$COUNT" = "$SIZELIMIT" ; then 457 echo "...bumped into requested size limit ($SIZELIMIT)" 458 else 459 echo "...error: got $COUNT entries with a requested sizelimit of $SIZELIMIT" 460 test $KILLSERVERS != no && kill -HUP $KILLPIDS 461 exit $RC 462 fi 463 else 464 echo "...error: bumped into server-side size limit, but got no entries!" 465 test $KILLSERVERS != no && kill -HUP $KILLPIDS 466 exit $RC 467 fi 468 ;; 469 *) 470 echo "ldapsearch failed ($RC)!" 471 test $KILLSERVERS != no && kill -HUP $KILLPIDS 472 exit $RC 473 ;; 474esac 475 476echo -n "Testing compare (should be TRUE)... " 477$LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \ 478 "sn:kovalev" >> $TESTOUT 2>&1 479 480RC=$? 481case $RC in 4826) 483 echo "TRUE" 484 ;; 4855) echo "FALSE!" 486 test $KILLSERVERS != no && kill -HUP $KILLPIDS 487 exit $RC 488 ;; 489*) echo "failed ($RC)!" 490 test $KILLSERVERS != no && kill -HUP $KILLPIDS 491 exit 1 492 ;; 493esac 494 495echo -n "Testing compare (should be FALSE)... " 496$LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \ 497 "cn:foobar" >> $TESTOUT 2>&1 498 499RC=$? 500case $RC in 5016) 502 echo "TRUE!" 503 test $KILLSERVERS != no && kill -HUP $KILLPIDS 504 exit $RC 505 ;; 5065) echo "FALSE" 507 ;; 508*) echo "failed ($RC)!" 509 test $KILLSERVERS != no && kill -HUP $KILLPIDS 510 exit 1 511 ;; 512esac 513 514echo -n "Testing compare (should be UNDEFINED)... " 515$LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \ 516 "o:example" >> $TESTOUT 2>&1 517 518RC=$? 519case $RC in 5206) 521 echo "TRUE!" 522 test $KILLSERVERS != no && kill -HUP $KILLPIDS 523 exit $RC 524 ;; 5255) echo "FALSE!" 526 test $KILLSERVERS != no && kill -HUP $KILLPIDS 527 exit $RC 528 ;; 529*) echo "failed ($RC)" 530 ;; 531esac 532 533echo -n "Testing compare on hasSubordinates (should be TRUE)... " 534$LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BASEDN" \ 535 "hasSubordinates:TRUE" >> $TESTOUT 2>&1 536 537RC=$? 538case $RC in 5396) 540 echo "TRUE" 541 ;; 5425) echo "FALSE!" 543 test $KILLSERVERS != no && kill -HUP $KILLPIDS 544 exit $RC 545 ;; 546*) echo "failed ($RC)!" 547 test $KILLSERVERS != no && kill -HUP $KILLPIDS 548 exit 1 549 ;; 550esac 551 552echo "Filtering ldapsearch results..." 553$LDIFFILTER < $SEARCHOUT > $SEARCHFLT 554echo "Filtering original ldif..." 555$LDIFFILTER < $SQLREAD > $LDIFFLT 556echo "Comparing filter output..." 557$CMP $SEARCHFLT $LDIFFLT > $CMPOUT 558 559if test $? != 0 ; then 560 echo "comparison failed - SQL search didn't succeed" 561 test $KILLSERVERS != no && kill -HUP $KILLPIDS 562 exit 1 563fi 564 565test $KILLSERVERS != no && kill -HUP $KILLPIDS 566 567echo ">>>>> Test succeeded" 568exit 0 569