Add tests to prove correctness of LDB attribute handlers
authorAndrew Bartlett <abartlet@samba.org>
Wed, 5 Nov 2008 01:01:10 +0000 (12:01 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 5 Nov 2008 01:01:10 +0000 (12:01 +1100)
This is not in the LDB testsuite, as it tests the extra code in
lib/ldb-samba, not the core of LDB.

Andrew Bartlett

source4/torture/config.mk
source4/torture/ldb/ldb.c [new file with mode: 0644]
source4/torture/torture.c

index 8b12f36f952defc5854ed70028ac56ae4a587077..069b0c95cd561ba9ea504e404c2e535f703ebfb0 100644 (file)
@@ -106,7 +106,7 @@ PRIVATE_DEPENDENCIES = \
                RPC_NDR_LSA RPC_NDR_EPMAPPER RPC_NDR_DFS RPC_NDR_FRSAPI RPC_NDR_SPOOLSS \
                RPC_NDR_SRVSVC RPC_NDR_WKSSVC RPC_NDR_ROT RPC_NDR_DSSETUP \
                RPC_NDR_REMACT RPC_NDR_OXIDRESOLVER WB_HELPER LIBSAMBA-NET \
-               LIBCLI_AUTH POPT_CREDENTIALS TORTURE_LDAP TORTURE_UTIL TORTURE_RAP \
+               LIBCLI_AUTH POPT_CREDENTIALS TORTURE_LDAP TORTURE_LDB TORTURE_UTIL TORTURE_RAP \
                dcerpc_server service process_model ntvfs SERVICE_SMB
 
 torture_rpc_OBJ_FILES = $(addprefix $(torturesrcdir)/rpc/, \
@@ -189,6 +189,20 @@ TORTURE_LDAP_OBJ_FILES = $(addprefix $(torturesrcdir)/ldap/, common.o basic.o sc
 
 $(eval $(call proto_header_template,$(torturesrcdir)/ldap/proto.h,$(TORTURE_LDAP_OBJ_FILES:.o=.c)))
 
+#################################
+# Start SUBSYSTEM TORTURE_LDB
+[MODULE::TORTURE_LDB]
+SUBSYSTEM = smbtorture
+INIT_FUNCTION = torture_ldb_init
+PRIVATE_DEPENDENCIES = \
+               LDB_WRAP
+# End SUBSYSTEM TORTURE_LDB
+#################################
+
+TORTURE_LDB_OBJ_FILES = $(addprefix $(torturesrcdir)/ldb/, ldb.o)
+
+$(eval $(call proto_header_template,$(torturesrcdir)/ldb/proto.h,$(TORTURE_LDB_OBJ_FILES:.o=.c)))
+
 #################################
 # Start SUBSYSTEM TORTURE_NBT
 [MODULE::TORTURE_NBT]
diff --git a/source4/torture/ldb/ldb.c b/source4/torture/ldb/ldb.c
new file mode 100644 (file)
index 0000000..ebb63ab
--- /dev/null
@@ -0,0 +1,183 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   Test LDB attribute functions
+
+   Copyright (C) Andrew Bartlet <abartlet@samba.org> 2008
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "lib/events/events.h"
+#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
+#include "lib/ldb-samba/ldif_handlers.h"
+#include "ldb_wrap.h"
+#include "dsdb/samdb/samdb.h"
+#include "param/param.h"
+#include "torture/smbtorture.h"
+#include "torture/ldb/proto.h"
+
+static bool torture_ldb_attrs(struct torture_context *torture)
+{
+       TALLOC_CTX *mem_ctx = talloc_new(torture);
+       int ret;
+       struct ldb_context *ldb;
+       const struct ldb_schema_attribute *attr;
+       struct ldb_dn *dn;
+       struct ldb_val string_sid_blob, binary_sid_blob;
+       struct ldb_val string_guid_blob, string_guid_blob2, binary_guid_blob;
+
+       const char *sid = "S-1-5-21-4177067393-1453636373-93818737";
+       const char *hex_sid = "01040000000000051500000081FDF8F815BBA456718F9705";
+       DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid);
+       const char *guid = "975ac5fa-35d9-431d-b86a-845bcd34fff9";
+       const char *guid2 = "{975ac5fa-35d9-431d-b86a-845bcd34fff9}";
+       const char *hex_guid = "FAC55A97D9351D43B86A845BCD34FFF9";
+       DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid);
+
+       ldb = ldb_init(mem_ctx, torture->ev);
+       if (ldb == NULL) {
+               return NULL;
+       }
+
+       ret = ldb_register_samba_handlers(ldb);
+       if (ret == -1) {
+               talloc_free(ldb);
+               return NULL;
+       }
+
+       ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
+
+       /* Test SID behaviour */
+       torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "objectSid"), 
+                      "Failed to get objectSid schema attribute");
+       
+       string_sid_blob = data_blob_string_const(sid);
+
+       torture_assert_int_equal(torture, 
+                                attr->syntax->ldif_read_fn(ldb, mem_ctx, 
+                                                           &string_sid_blob, &binary_sid_blob), 0,
+                                "Failed to parse string SID");
+       
+       torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob, 
+                                      "Read SID into blob form failed");
+       
+       torture_assert_int_equal(torture, 
+                                attr->syntax->ldif_read_fn(ldb, mem_ctx, 
+                                                           &sid_blob, &binary_sid_blob), -1,
+                                "Should have failed to parse binary SID");
+       
+       torture_assert_int_equal(torture, 
+                                attr->syntax->ldif_write_fn(ldb, mem_ctx, &binary_sid_blob, &string_sid_blob), 0,
+                                "Failed to parse binary SID");
+       
+       torture_assert_data_blob_equal(torture, 
+                                      string_sid_blob, data_blob_string_const(sid),
+                                      "Write SID into string form failed");
+       
+       torture_assert_int_equal(torture, 
+                                attr->syntax->comparison_fn(ldb, mem_ctx, &binary_sid_blob, &string_sid_blob), 0,
+                                "Failed to compare binary and string SID");
+       
+       torture_assert_int_equal(torture, 
+                                attr->syntax->comparison_fn(ldb, mem_ctx, &string_sid_blob, &binary_sid_blob), 0,
+                                "Failed to compare string and binary binary SID");
+       
+       torture_assert_int_equal(torture, 
+                                attr->syntax->comparison_fn(ldb, mem_ctx, &string_sid_blob, &string_sid_blob), 0,
+                                "Failed to compare string and string SID");
+       
+       torture_assert_int_equal(torture, 
+                                attr->syntax->comparison_fn(ldb, mem_ctx, &binary_sid_blob, &binary_sid_blob), 0,
+                                "Failed to compare binary and binary SID");
+       
+       torture_assert(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &guid_blob, &binary_sid_blob) != 0,
+                      "Failed to distinguish binary GUID and binary SID");
+
+
+       /* Test GUID behaviour */
+       torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "objectGUID"), 
+                      "Failed to get objectGUID schema attribute");
+       
+       string_guid_blob = data_blob_string_const(guid);
+
+       torture_assert_int_equal(torture, 
+                                attr->syntax->ldif_read_fn(ldb, mem_ctx, 
+                                                           &string_guid_blob, &binary_guid_blob), 0,
+                                "Failed to parse string GUID");
+       
+       torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob, 
+                                      "Read GUID into blob form failed");
+       
+       string_guid_blob2 = data_blob_string_const(guid2);
+       
+       torture_assert_int_equal(torture, 
+                                attr->syntax->ldif_read_fn(ldb, mem_ctx, 
+                                                           &string_guid_blob2, &binary_guid_blob), 0,
+                                "Failed to parse string GUID");
+       
+       torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob, 
+                                      "Read GUID into blob form failed");
+       
+       torture_assert_int_equal(torture, 
+                                attr->syntax->ldif_read_fn(ldb, mem_ctx, 
+                                                           &guid_blob, &binary_guid_blob), -1,
+                                "Should have failed to parse binary SID");
+       
+       torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob, 
+                                      "Read GUID into blob form failed");
+       
+       torture_assert_int_equal(torture, 
+                                attr->syntax->ldif_write_fn(ldb, mem_ctx, &binary_guid_blob, &string_guid_blob), 0,
+                                "Failed to print binary GUID as string");
+
+       torture_assert_data_blob_equal(torture, string_sid_blob, data_blob_string_const(sid),
+                                      "Write SID into string form failed");
+       
+       torture_assert_int_equal(torture, 
+                                attr->syntax->comparison_fn(ldb, mem_ctx, &binary_guid_blob, &string_guid_blob), 0,
+                                "Failed to compare binary and string GUID");
+       
+       torture_assert_int_equal(torture, 
+                                attr->syntax->comparison_fn(ldb, mem_ctx, &string_guid_blob, &binary_guid_blob), 0,
+                                "Failed to compare string and binary binary GUID");
+       
+       torture_assert_int_equal(torture, 
+                                attr->syntax->comparison_fn(ldb, mem_ctx, &string_guid_blob, &string_guid_blob), 0,
+                                "Failed to compare string and string GUID");
+       
+       torture_assert_int_equal(torture, 
+                                attr->syntax->comparison_fn(ldb, mem_ctx, &binary_guid_blob, &binary_guid_blob), 0,
+                                "Failed to compare binary and binary GUID");
+       
+       
+       
+       talloc_free(mem_ctx);
+       return true;
+}
+
+
+NTSTATUS torture_ldb_init(void)
+{
+       struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "LDB");
+       torture_suite_add_simple_test(suite, "ATTRS", torture_ldb_attrs);
+
+       suite->description = talloc_strdup(suite, "LDB (samba-specific behaviour) tests");
+
+       torture_register_suite(suite);
+
+       return NT_STATUS_OK;
+}
index dc98c2cc9a7f752d4e050f09b09684e148d9d998..3f9a6607cf57acd03c5e5167233e92bdca9db7ab 100644 (file)
@@ -50,6 +50,7 @@ _PUBLIC_ int torture_init(void)
 {
        extern NTSTATUS torture_base_init(void);
        extern NTSTATUS torture_ldap_init(void);
+       extern NTSTATUS torture_ldb_init(void);
        extern NTSTATUS torture_local_init(void);
        extern NTSTATUS torture_nbt_init(void);
        extern NTSTATUS torture_nbench_init(void);