]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbtorture: add test vfs.fruit.case_insensitive_find
authorRalph Boehme <slow@samba.org>
Fri, 19 Sep 2025 04:43:57 +0000 (06:43 +0200)
committerJule Anger <janger@samba.org>
Wed, 15 Oct 2025 15:07:13 +0000 (15:07 +0000)
Verifies case insensitive directory scanning works.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15926

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
(cherry picked from commit 68ed6279335cfac13a624ae8a7738dac3d9b0d1a)

source4/torture/vfs/fruit.c

index 02f7acd0feadd0f1bef1bf6b2890769b94951def..a6f86cd5edf981e5a839e2e2de23ce9e6b6e94c6 100644 (file)
@@ -7930,6 +7930,89 @@ done:
        return ret;
 }
 
+/*
+ * Test case-insensitive file finding with AAPL extensions
+ * Add this function to source4/torture/vfs/fruit.c
+ */
+
+static bool test_case_insensitive_find(struct torture_context *tctx,
+                                      struct smb2_tree *tree)
+{
+       NTSTATUS status;
+       bool ret = true;
+       const char *fname = "TestFile.txt";
+       const char *fname_upper = "TESTFILE.TXT";
+       struct smb2_handle testdirh;
+       struct smb2_handle h1;
+       struct smb2_create create;
+       struct smb2_find f;
+       union smb_search_data *d;
+       uint_t count;
+
+       smb2_deltree(tree, BASEDIR);
+
+       status = torture_smb2_testdir(tree, BASEDIR, &testdirh);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "torture_smb2_testdir failed");
+
+       /* Enable AAPL extensions */
+       ret = enable_aapl(tctx, tree);
+       torture_assert_goto(tctx, ret, ret, done,
+                           "enable_aapl failed");
+
+       /* Create test file */
+       ZERO_STRUCT(create);
+       create.in.desired_access = SEC_RIGHTS_FILE_ALL;
+       create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+       create.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
+               NTCREATEX_SHARE_ACCESS_WRITE |
+               NTCREATEX_SHARE_ACCESS_DELETE;
+       create.in.create_disposition = NTCREATEX_DISP_CREATE;
+       create.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
+       create.in.fname = talloc_asprintf(tctx, "%s\\%s", BASEDIR, fname);
+
+       status = smb2_create(tree, tctx, &create);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       talloc_asprintf(tctx, "failed to create %s", fname));
+       h1 = create.out.file.handle;
+
+       /* Close the file */
+       status = smb2_util_close(tree, h1);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "failed to close test file");
+
+       /* Search for file using different case */
+       f = (struct smb2_find) {
+               .in.file.handle = testdirh,
+               .in.pattern = fname_upper,
+               .in.max_response_size = 0x1000,
+               .in.level = SMB2_FIND_ID_BOTH_DIRECTORY_INFO,
+       };
+
+       status = smb2_find_level(tree, tctx, &f, &count, &d);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       talloc_asprintf(tctx, "smb2_find_level failed searching for %s", fname_upper));
+
+       /* Verify we found exactly one file */
+       torture_assert_int_equal_goto(tctx, count, 1, ret, done,
+                                     talloc_asprintf(tctx, "Expected 1 file, got %u", count));
+
+       /* Verify the filename matches our original file (case may differ) */
+       torture_assert_str_equal_goto(tctx,
+                                     d[0].id_both_directory_info.name.s, fname, ret, done,
+                                     talloc_asprintf(tctx, "Found file name '%s' doesn't match expected '%s'",
+                                                     d[0].directory_info.name.s, fname));
+
+       torture_comment(tctx, "Case-insensitive find test passed: "
+                       "searched for '%s', found '%s'\n",
+                       fname_upper, d[0].id_both_directory_info.name.s);
+
+done:
+       smb2_util_close(tree, testdirh);
+       smb2_deltree(tree, BASEDIR);
+       return ret;
+}
+
 /*
  * Note: This test depends on "vfs objects = catia fruit streams_xattr".  For
  * some tests torture must be run on the host it tests and takes an additional
@@ -7977,7 +8060,7 @@ struct torture_suite *torture_vfs_fruit(TALLOC_CTX *ctx)
        torture_suite_add_1smb2_test(suite, "writing_afpinfo", test_writing_afpinfo);
        torture_suite_add_1smb2_test(suite, "delete_trigger_convert_sharing_violation", test_delete_trigger_convert_sharing_violation);
        torture_suite_add_1smb2_test(suite, "readonly-exclusive-lock", test_readonly_exclusive_lock);
-
+       torture_suite_add_1smb2_test(suite, "case_insensitive_find", test_case_insensitive_find);
        return suite;
 }