s4: tests controls parsing and using for ldbadd/ldbedit/ldbmodify
authorMatthieu Patou <mat@matws.net>
Sat, 5 Dec 2009 14:56:35 +0000 (17:56 +0300)
committerSimo Sorce <idra@samba.org>
Wed, 23 Dec 2009 13:09:19 +0000 (08:09 -0500)
source4/lib/ldb/config.mk
source4/lib/ldb/tests/sample_module.c
source4/lib/ldb/tests/test-controls.sh [new file with mode: 0755]
source4/lib/ldb/tests/test-tdb.sh

index 4a1f814baacd01e32d40ec487537d974b3ef78c5..7d110fc618e8ee47fbc36d01e4962e3da786fa6e 100644 (file)
@@ -10,6 +10,19 @@ ldb_asq_OBJ_FILES = $(ldbsrcdir)/modules/asq.o
 # End MODULE ldb_asq
 ################################################
 
+################################################
+# Start MODULE sample_module
+[MODULE::sample]
+PRIVATE_DEPENDENCIES = LIBTALLOC LIBTEVENT
+CFLAGS = -I$(ldbsrcdir)/include
+INIT_FUNCTION = LDB_MODULE(sample)
+SUBSYSTEM = LIBTESTLDB
+
+# End MODULE sample_module
+################################################
+sample_OBJ_FILES = $(ldbsrcdir)/tests/sample_module.o
+
+
 ################################################
 # Start MODULE ldb_server_sort
 [MODULE::ldb_server_sort]
index bbe4419b598c0188fc642c917eada5f232fb12cd..bb7906e7ba0219183fb747e17c142cd24a66142e 100644 (file)
 
 int sample_add(struct ldb_module *mod, struct ldb_request *req)
 {
+       struct ldb_control *control;
+       struct ldb_control *controls;
        ldb_msg_add_fmt(req->op.add.message, "touchedBy", "sample");
 
-       return ldb_next_request(mod, req);
+
+       /* check if there's a relax control */
+       control = ldb_request_get_control(req, LDB_CONTROL_RELAX_OID);
+       if (control == NULL) {
+               /* not found go on */
+               return ldb_next_request(mod, req);
+       } else {
+               return LDB_ERR_UNWILLING_TO_PERFORM;
+       }
+}
+
+int sample_modify(struct ldb_module *mod, struct ldb_request *req)
+{
+       struct ldb_control *control;
+       struct ldb_control *controls;
+
+       /* check if there's a relax control */
+       control = ldb_request_get_control(req, LDB_CONTROL_RELAX_OID);
+       if (control == NULL) {
+               /* not found go on */
+               return ldb_next_request(mod, req);
+       } else {
+               return LDB_ERR_UNWILLING_TO_PERFORM;
+       }
 }
 
+
 const struct ldb_module_ops ldb_sample_module_ops = {
        .name              = "sample",
        .add               = sample_add,
+       .del               = sample_modify,
+       .modify            = sample_modify,
 };
diff --git a/source4/lib/ldb/tests/test-controls.sh b/source4/lib/ldb/tests/test-controls.sh
new file mode 100755 (executable)
index 0000000..db139bb
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+if [ -n "$TEST_DATA_PREFIX" ]; then
+       LDB_URL="$TEST_DATA_PREFIX/tdbtest.ldb"
+else
+       LDB_URL="tdbtest.ldb"
+fi
+export LDB_URL
+
+PATH=bin:$PATH
+export PATH
+
+rm -f $LDB_URL*
+LDB_MODULES_PATH=`dirname $0`/../../../bin/modules/testldb
+echo $LDB_MODULES_PATH
+
+echo "LDB_URL: $LDB_URL"
+cat <<EOF | $VALGRIND ldbadd || exit 1
+dn: @MODULES
+@LIST: sample
+EOF
+
+cat <<EOF | $VALGRIND ldbadd || exit 1
+dn: dc=bar
+dc: bar
+someThing: someThingElse
+EOF
+
+$VALGRIND ldbsearch "(touchedBy=sample)" | grep "touchedBy: sample" || exit 1
+# This action are expected to fails because the sample module return an error when presented the relax control
+
+cat <<EOF | $VALGRIND ldbadd --controls "relax:0" && exit 1
+dn: dc=foobar
+dc: foobar
+someThing: someThingElse
+EOF
+
+cat <<EOF | $VALGRIND ldbmodify --controls "relax:0" && exit 1
+dn: dc=bar
+changetype: replace
+replace someThing
+someThing: someThingElseBetter
+EOF
+
+
+set
index 1c3545196259b6c019f78e7a73bbe6262984ee0a..9da1e57060a8f8bfdbfd51a0b3fbb8997b66651c 100755 (executable)
@@ -29,3 +29,5 @@ $VALGRIND ldbadd$EXEEXT $LDBDIR/tests/init.ldif || exit 1
 . $LDBDIR/tests/test-extended.sh
 
 . $LDBDIR/tests/test-tdb-features.sh
+
+. $LDBDIR/tests/test-controls.sh