s4:torture rework LDAP sort test
authorAndrew Bartlett <abartlet@samba.org>
Tue, 4 Aug 2009 02:52:11 +0000 (12:52 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 4 Aug 2009 03:11:07 +0000 (13:11 +1000)
This reworks the test to be part of the LDAP tests, to make better use
of the torture API and the ldb API (in particular around adding
controls), and a general cleanup.

This also adds the test to the 'make test' run.

Andrew Bartlett

source4/selftest/tests.sh
source4/torture/ldap/common.c
source4/torture/ldap/ldap_sort.c [moved from source4/torture/ldb/modules/ldb_module.c with 53% similarity]
source4/torture/torture.c

index 1b575a978b3f1bd3944ce14e1ed96f60f47d803b..6c6a09fbbdb683f382c8f1399497802a15d13331 100755 (executable)
@@ -120,7 +120,7 @@ if grep ENABLE_GNUTLS.1 include/config.h > /dev/null; then
     done
 fi
 plantest "ldb.ldapi with options $options" dc $bbdir/test_ldb.sh ldapi \$PREFIX_ABS/dc/private/ldapi $options
     done
 fi
 plantest "ldb.ldapi with options $options" dc $bbdir/test_ldb.sh ldapi \$PREFIX_ABS/dc/private/ldapi $options
-for t in LDAP-CLDAP LDAP-BASIC LDAP-SCHEMA LDAP-UPTODATEVECTOR
+for t in `$smb4torture --list | grep "^LDAP-"`
 do
        plansmbtorturetest "$t" dc "-U\$USERNAME%\$PASSWORD" //\$SERVER_IP/_none_
 done
 do
        plansmbtorturetest "$t" dc "-U\$USERNAME%\$PASSWORD" //\$SERVER_IP/_none_
 done
index 2c11de729c23f625dfee5ee03c1bc681f935769e..4a2bc2e3916d455bc661a1aa55d435ba4c93fdc0 100644 (file)
@@ -105,6 +105,7 @@ NTSTATUS torture_ldap_init(void)
        struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "LDAP");
        torture_suite_add_simple_test(suite, "BENCH-CLDAP", torture_bench_cldap);
        torture_suite_add_simple_test(suite, "BASIC", torture_ldap_basic);
        struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "LDAP");
        torture_suite_add_simple_test(suite, "BENCH-CLDAP", torture_bench_cldap);
        torture_suite_add_simple_test(suite, "BASIC", torture_ldap_basic);
+       torture_suite_add_simple_test(suite, "SORT", torture_ldap_sort);
        torture_suite_add_simple_test(suite, "CLDAP", torture_cldap);
        torture_suite_add_simple_test(suite, "SCHEMA", torture_ldap_schema);
        torture_suite_add_simple_test(suite, "UPTODATEVECTOR", torture_ldap_uptodatevector);
        torture_suite_add_simple_test(suite, "CLDAP", torture_cldap);
        torture_suite_add_simple_test(suite, "SCHEMA", torture_ldap_schema);
        torture_suite_add_simple_test(suite, "UPTODATEVECTOR", torture_ldap_uptodatevector);
similarity index 53%
rename from source4/torture/ldb/modules/ldb_module.c
rename to source4/torture/ldap/ldap_sort.c
index 64f95f7619c7dfd6d6c3bf398cfaeeda7ac26bb4..4d732cf997183d59349e250c174890b8c3c2e41e 100644 (file)
@@ -1,23 +1,23 @@
 /* 
 /* 
-        Unix SMB/CIFS implementation.
-
-        Test LDB attribute functions
-
-        Copyright (C) Andrew Bartlet <abartlet@samba.org> 2008
-        Copyright (C) Matthieu Patou <mat@matws.net> 2009
-        
-        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/>.
+   Unix SMB/CIFS implementation.
+   
+   Test LDB attribute functions
+   
+   Copyright (C) Andrew Bartlet <abartlet@samba.org> 2008-2009
+   Copyright (C) Matthieu Patou <mat@matws.net> 2009
+   
+   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 "includes.h"
@@ -29,8 +29,8 @@
 #include "lib/cmdline/popt_common.h" 
 #include "torture/smbtorture.h"
 #include "torture/local/proto.h"
 #include "lib/cmdline/popt_common.h" 
 #include "torture/smbtorture.h"
 #include "torture/local/proto.h"
-
-static bool torture_ldb_mod_sort(struct torture_context *torture)
+#include <ctype.h>
+bool torture_ldap_sort(struct torture_context *torture)
 {
 
        struct ldb_context *ldb;
 {
 
        struct ldb_context *ldb;
@@ -38,25 +38,21 @@ static bool torture_ldb_mod_sort(struct torture_context *torture)
        bool ret = false;
        const char *host = torture_setting_string(torture, "host", NULL);
        char *url;
        bool ret = false;
        const char *host = torture_setting_string(torture, "host", NULL);
        char *url;
-       char *basedn;
        int i;
        int i;
-       int j;
+       codepoint_t j;
        struct ldb_message_element *elem;
        struct ldb_message *msg;
        struct ldb_message_element *elem;
        struct ldb_message *msg;
-       struct dsdb_schema *schema = NULL;
-       struct ldb_control **ctrl;
 
 
-       struct ldb_server_sort_control ** control;
+       struct ldb_server_sort_control **control;
        struct ldb_request *req;
        struct ldb_result *ctx;
        struct ldb_val* prev = NULL;
        struct ldb_request *req;
        struct ldb_result *ctx;
        struct ldb_val* prev = NULL;
-       char *prev_txt = NULL;
+       const char *prev_txt = NULL;
        int prev_len = 0;
        struct ldb_val* cur = NULL;
        int prev_len = 0;
        struct ldb_val* cur = NULL;
-       char *cur_txt = NULL;
+       const char *cur_txt = NULL;
        int cur_len = 0;
        struct ldb_dn* dn;
        int cur_len = 0;
        struct ldb_dn* dn;
-       char* user_cn = "Users";
                 
                 
        /* TALLOC_CTX* ctx;*/
                 
                 
        /* TALLOC_CTX* ctx;*/
@@ -67,56 +63,43 @@ static bool torture_ldb_mod_sort(struct torture_context *torture)
                                                 NULL,
                                                 cmdline_credentials,
                                                 0, NULL);
                                                 NULL,
                                                 cmdline_credentials,
                                                 0, NULL);
-       if (!ldb) goto failed;
-       ret = false;
-       fprintf(stderr,"Ici \n");
+       torture_assert(torture, ldb, "Failed to make LDB connection to target");
 
        ctx = talloc_zero(ldb, struct ldb_result);
 
 
        ctx = talloc_zero(ldb, struct ldb_result);
 
-       ctrl = talloc_array(ctx, struct ldb_control *, 2);
-       ctrl[0] = talloc(ctrl, struct ldb_control);
-       ctrl[0]->oid = LDB_CONTROL_SERVER_SORT_OID;
-       ctrl[0]->critical = true;
-
-       control = talloc_array(ctrl[0], struct ldb_server_sort_control *, 2);
+       control = talloc_array(ctx, struct ldb_server_sort_control *, 2);
        control[0] = talloc(control, struct ldb_server_sort_control);
        control[0]->attributeName = talloc_strdup(control, "cn");
        control[0]->orderingRule = NULL;
        control[0]->reverse = 0;
        control[1] = NULL;
        control[0] = talloc(control, struct ldb_server_sort_control);
        control[0]->attributeName = talloc_strdup(control, "cn");
        control[0]->orderingRule = NULL;
        control[0]->reverse = 0;
        control[1] = NULL;
-       ctrl[0]->data = control;
-       ctrl[1] = NULL;
 
        dn = ldb_get_root_basedn(ldb);
 
        dn = ldb_get_root_basedn(ldb);
-       ldb_dn_add_child_fmt(dn, "cn=%s", user_cn);
+       ldb_dn_add_child_fmt(dn, "cn=users");
        ret = ldb_build_search_req(&req, ldb, ctx,
        ret = ldb_build_search_req(&req, ldb, ctx,
-                                        dn,
-                                        LDB_SCOPE_SUBTREE,
-                                        "(objectClass=*)", NULL,
-                                        ctrl,
-                                        ctx, ldb_search_default_callback, NULL);
+                                  dn,
+                                  LDB_SCOPE_SUBTREE,
+                                  "(objectClass=*)", NULL,
+                                  NULL,
+                                  ctx, ldb_search_default_callback, NULL);
+       torture_assert(torture, ret == LDB_SUCCESS, "Failed to build search request");
+
+       ret = ldb_request_add_control(req, LDB_CONTROL_SERVER_SORT_OID, true, control);
+       torture_assert(torture, ret == LDB_SUCCESS, "Failed to add control to search request");
 
        ret = ldb_request(ldb, req);
 
        ret = ldb_request(ldb, req);
-       if (ret != LDB_SUCCESS) {
-               d_printf("search failed - %s\n", ldb_errstring(ldb));
-               talloc_free(req);
-               return false;
-       }
+       torture_assert(torture, ret == LDB_SUCCESS, ldb_errstring(ldb));
 
        ret = ldb_wait(req->handle, LDB_WAIT_ALL);
 
        ret = ldb_wait(req->handle, LDB_WAIT_ALL);
+       torture_assert(torture, ret == LDB_SUCCESS, ldb_errstring(ldb));
 
 
-       if (ret != LDB_SUCCESS) {
-               d_printf("search error - %s\n", ldb_errstring(ldb));
-               talloc_free(req);
-               return false;
-       }
-       ret = 1;
+       ret = true;
        if (ctx->count > 1) {
                for (i=0;i<ctx->count;i++) {
                        msg = ctx->msgs[i];
                        elem = ldb_msg_find_element(msg,"cn");
                        cur = elem->values;
        if (ctx->count > 1) {
                for (i=0;i<ctx->count;i++) {
                        msg = ctx->msgs[i];
                        elem = ldb_msg_find_element(msg,"cn");
                        cur = elem->values;
-                       d_printf("cn: %s\n",cur->data);
+                       torture_comment(torture, "cn: %s\n",cur->data);
                        if (prev != NULL)
                        {
                                /* Do only the ascii case right now ... */
                        if (prev != NULL)
                        {
                                /* Do only the ascii case right now ... */
@@ -128,7 +111,7 @@ static bool torture_ldb_mod_sort(struct torture_context *torture)
                                while ( cur_txt[0] == cur_txt[1] ) { cur_txt++; cur_len--;}
                                while ( prev_txt[0] == prev_txt[1] ) { prev_txt++; prev_len--;}
                                while( *(cur_txt) && *(prev_txt) && cur_len && prev_len ) {
                                while ( cur_txt[0] == cur_txt[1] ) { cur_txt++; cur_len--;}
                                while ( prev_txt[0] == prev_txt[1] ) { prev_txt++; prev_len--;}
                                while( *(cur_txt) && *(prev_txt) && cur_len && prev_len ) {
-                                       j = (int)toupper(*(prev_txt))-(int)toupper(*(cur_txt));
+                                       j = toupper_m(*(prev_txt))-toupper_m(*(cur_txt));
                                        if ( j > 0 ) {
                                                /* Just check that is not due to trailling white space in prev_txt 
                                                 * That is to say *cur_txt = 0 and prev_txt = 20 */
                                        if ( j > 0 ) {
                                                /* Just check that is not due to trailling white space in prev_txt 
                                                 * That is to say *cur_txt = 0 and prev_txt = 20 */
@@ -138,10 +121,7 @@ static bool torture_ldb_mod_sort(struct torture_context *torture)
                                                /* Now that potential whitespace are removed if we are at the end 
                                                 * of the cur_txt then it means that in fact strings were identical
                                                 */
                                                /* Now that potential whitespace are removed if we are at the end 
                                                 * of the cur_txt then it means that in fact strings were identical
                                                 */
-                                               if ( *cur_txt || *prev_txt ) {
-                                                       ret = 0;
-                                                       torture->last_reason = talloc_strdup(torture, "Data wrongly sorted");
-                                               }
+                                               torture_assert(torture, *cur_txt && *prev_txt, "Data wrongly sorted");
                                                break;
                                        }
                                        else
                                                break;
                                        }
                                        else
@@ -172,19 +152,5 @@ static bool torture_ldb_mod_sort(struct torture_context *torture)
 
        }
 
 
        }
 
-failed:
        return ret;
 }
        return ret;
 }
-
-
-NTSTATUS torture_ldb_module_init(void)
-{
-       struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "LDB_MODULE");
-       torture_suite_add_simple_test(suite, "SORT", torture_ldb_mod_sort);
-       suite->description = talloc_strdup(suite, "LDB MODULES (samba-specific behaviour) tests");
-
-       torture_register_suite(suite);
-
-       return NT_STATUS_OK;
-}
-
index 1dce12adb084d9ce52abe065291b5d66cda100cf..a7296e62db51b37aad8f2ab4e27891d66db02259 100644 (file)
@@ -56,7 +56,6 @@ _PUBLIC_ int torture_init(void)
 {
        extern NTSTATUS torture_base_init(void);
        extern NTSTATUS torture_ldap_init(void);
 {
        extern NTSTATUS torture_base_init(void);
        extern NTSTATUS torture_ldap_init(void);
-       extern NTSTATUS torture_ldb_module_init(void);
        extern NTSTATUS torture_local_init(void);
        extern NTSTATUS torture_nbt_init(void);
        extern NTSTATUS torture_nbench_init(void);
        extern NTSTATUS torture_local_init(void);
        extern NTSTATUS torture_nbt_init(void);
        extern NTSTATUS torture_nbench_init(void);