]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python/tests: add Smb3UnixTests.test_delete_read_only_attr
authorRalph Boehme <slow@samba.org>
Mon, 2 Mar 2026 13:51:34 +0000 (14:51 +0100)
committerRalph Boehme <slow@samba.org>
Fri, 17 Jul 2026 17:22:37 +0000 (17:22 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
python/samba/tests/smb3unix.py

index 3039a68a1cdabfc4539874c0c9957d10b127769c..f753e189f241eb9b96f4d9df7791f5bf23ccff0f 100644 (file)
@@ -508,6 +508,58 @@ class Smb3UnixTests(samba.tests.libsmb.LibsmbTests):
         found_files = {get_string(f['name']): f for f in l}
         self.assertFalse('test_delete_on_close' in found_files)
 
+    def test_delete_read_only_attr(self):
+        """
+        Test deleting a file with FILE_ATTRIBUTE_READONLY
+        """
+
+        testfile = 'test_delete_read_only_attr'
+        wc, c = self.connections()
+
+        self.clean_file(c, testfile)
+
+        wh,_,_ = wc.create_ex(
+            testfile,
+            DesiredAccess=security.SEC_STD_ALL,
+            ShareAccess=0x07,
+            CreateDisposition=libsmb.FILE_CREATE,
+            FileAttributes=libsmb.FILE_ATTRIBUTE_READONLY)
+
+        # First try to delete on a Windows handle, should fail
+        try:
+            wc.delete_on_close(wh, 1)
+        except Exception as e:
+            if e.args[0] != ntstatus.NT_STATUS_CANNOT_DELETE:
+                wc.close(wh)
+                raise e
+
+        wc.close(wh)
+
+        wire_mode = libsmb.unix_mode_to_wire(0o666)
+
+        h,_,_ = c.create_ex(
+            testfile,
+            DesiredAccess=security.SEC_STD_DELETE |
+                security.SEC_FILE_WRITE_ATTRIBUTE,
+            ShareAccess=0x07,
+            CreateDisposition=libsmb.FILE_OPEN,
+            FileAttributes=libsmb.FILE_ATTRIBUTE_READONLY,
+            CreateContexts=[posix_context(wire_mode)])
+
+        self.addCleanup(self.clean_file, c, testfile)
+
+        try:
+            c.delete_on_close(h, 1)
+        except Exception as e:
+            c.close(h)
+            raise e
+        c.close(h)
+
+        # The file should be deleted
+        l = c.list('', mask='*')
+        found_files = {get_string(f['name']): f for f in l}
+        self.assertFalse(testfile in found_files)
+
     def test_posix_fs_info(self):
         """
         Test the posix filesystem attributes list given by cli_get_posix_fs_info.