tests: libsmbclient: Add a readdirplus() test suite.
authorJeremy Allison <jra@samba.org>
Tue, 24 Apr 2018 20:47:54 +0000 (13:47 -0700)
committerJeremy Allison <jra@samba.org>
Sat, 5 May 2018 02:31:18 +0000 (04:31 +0200)
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sat May  5 04:31:18 CEST 2018 on sn-devel-144

source3/selftest/tests.py
source4/selftest/tests.py
source4/torture/libsmbclient/libsmbclient.c

index 810cb5e4f7103a848a5d40f09d04c51d69e418b2..c234679b1cdd1132feaf71db4551246064f59326 100755 (executable)
@@ -551,8 +551,12 @@ for t in tests:
         plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD --option=torture:wksname=samba3rpctest')
         plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD --option=torture:wksname=samba3rpctest')
     elif t == "libsmbclient":
-        plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%%$PASSWORD --option=torture:replace_smbconf=%s' % os.path.join(srcdir(), "testdata/samba3/smb_new.conf"))
-        plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%%$PASSWORD --option=torture:replace_smbconf=%s' % os.path.join(srcdir(), "testdata/samba3/smb_new.conf"))
+        plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%%$PASSWORD '
+                                    '--option=torture:smburl=smb://$USERNAME:$PASSWORD@$SERVER/tmp '
+                                    '--option=torture:replace_smbconf=%s' % os.path.join(srcdir(), "testdata/samba3/smb_new.conf"))
+        plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%%$PASSWORD '
+                                    '--option=torture:smburl=smb://$USERNAME:$PASSWORD@$SERVER/tmp '
+                                    '--option=torture:replace_smbconf=%s' % os.path.join(srcdir(), "testdata/samba3/smb_new.conf"))
     else:
         plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD')
         plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD')
index ecf2c2146fb81a9c166d1ee07913a09da27dadb9..b1483aa5585177c7793f54d343ff8e74d70a6fa5 100755 (executable)
@@ -313,7 +313,8 @@ base = smbtorture4_testsuites("base.")
 netapi = smbtorture4_testsuites("netapi.")
 
 libsmbclient = smbtorture4_testsuites("libsmbclient.")
-libsmbclient_testargs = ["--option=torture:replace_smbconf=%s/testdata/samba3/smb_new.conf" % srcdir()]
+libsmbclient_testargs = ["--option=torture:smburl=smb://$USERNAME:$PASSWORD@$SERVER/tmp",
+                         "--option=torture:replace_smbconf=%s/testdata/samba3/smb_new.conf" % srcdir()]
 
 for t in base + raw + smb2 + netapi + libsmbclient:
     plansmbtorture4testsuite(t, "ad_dc_ntvfs", ['//$SERVER/tmp', '-U$USERNAME%$PASSWORD'] + ntvfsargs + libsmbclient_testargs)
index 00e766c488a66e9944a1385d1b14f8f3f4888e69..91579f4b1b763dc61c2f3d76e3c61f308099fa16 100644 (file)
@@ -223,6 +223,100 @@ static bool torture_libsmbclient_opendir(struct torture_context *tctx)
        return ret;
 }
 
+static bool torture_libsmbclient_readdirplus(struct torture_context *tctx)
+{
+       SMBCCTX *ctx;
+       int ret = -1;
+       int dhandle = -1;
+       int fhandle = -1;
+       bool found = false;
+       const char *filename = NULL;
+       const char *smburl = torture_setting_string(tctx, "smburl", NULL);
+
+       if (smburl == NULL) {
+               torture_fail(tctx,
+                       "option --option=torture:smburl="
+                       "smb://user:password@server/share missing\n");
+       }
+
+       torture_assert(tctx, torture_libsmbclient_init_context(tctx, &ctx), "");
+       smbc_set_context(ctx);
+
+       filename = talloc_asprintf(tctx,
+                               "%s/test_readdirplus.txt",
+                               smburl);
+       if (filename == NULL) {
+               torture_fail(tctx,
+                       "talloc fail\n");
+       }
+       /* Ensure the file doesn't exist. */
+       smbc_unlink(filename);
+
+       /* Create it. */
+       fhandle = smbc_creat(filename, 0666);
+       if (fhandle < 0) {
+               torture_fail(tctx,
+                       talloc_asprintf(tctx,
+                               "failed to create file '%s': %s",
+                               filename,
+                               strerror(errno)));
+       }
+       ret = smbc_close(fhandle);
+       torture_assert_int_equal(tctx,
+               ret,
+               0,
+               talloc_asprintf(tctx,
+                       "failed to close handle for '%s'",
+                       filename));
+
+       dhandle = smbc_opendir(smburl);
+       if (dhandle < 0) {
+               int saved_errno = errno;
+               smbc_unlink(filename);
+               torture_fail(tctx,
+                       talloc_asprintf(tctx,
+                               "failed to obtain "
+                               "directory handle for '%s' : %s",
+                               smburl,
+                               strerror(saved_errno)));
+       }
+
+       /* Readdirplus to ensure we see the new file. */
+       for (;;) {
+               const struct libsmb_file_info *exstat =
+                       smbc_readdirplus(dhandle);
+               if (exstat == NULL) {
+                       break;
+               }
+               if (strcmp(exstat->name, "test_readdirplus.txt") == 0) {
+                       found = true;
+                       break;
+               }
+       }
+
+       /* Remove it again. */
+       smbc_unlink(filename);
+       ret = smbc_closedir(dhandle);
+       torture_assert_int_equal(tctx,
+               ret,
+               0,
+               talloc_asprintf(tctx,
+                       "failed to close directory handle for '%s'",
+                       smburl));
+
+       smbc_free_context(ctx, 1);
+
+       if (!found) {
+               torture_fail(tctx,
+                       talloc_asprintf(tctx,
+                               "failed to find file '%s'",
+                               filename));
+       }
+
+       return true;
+}
+
+
 /* note the strdup for string options on smbc_set calls. I think libsmbclient is
  * really doing something wrong here: in smbc_free_context libsmbclient just
  * calls free() on the string options so it assumes the callers have malloced
@@ -298,6 +392,8 @@ NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx)
        torture_suite_add_simple_test(suite, "setConfiguration", torture_libsmbclient_setConfiguration);
        torture_suite_add_simple_test(suite, "options", torture_libsmbclient_options);
        torture_suite_add_simple_test(suite, "opendir", torture_libsmbclient_opendir);
+       torture_suite_add_simple_test(suite, "readdirplus",
+               torture_libsmbclient_readdirplus);
 
        suite->description = talloc_strdup(suite, "libsmbclient interface tests");