]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tests: test SMB3 POSIX append-IO behaviour
authorRalph Boehme <slow@samba.org>
Thu, 28 Nov 2024 11:12:26 +0000 (12:12 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 7 Jan 2025 22:04:33 +0000 (22:04 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
python/samba/tests/smb3unix.py
selftest/knownfail.d/samba.tests.smb3unix [new file with mode: 0644]

index cbd280956e9a640921aa87e91ad30648cbfdfaeb..5c8ab182061147263f826f6315fa30ca034b2090 100644 (file)
@@ -543,3 +543,49 @@ class Smb3UnixTests(samba.tests.libsmb.LibsmbTests):
             c.close(dh)
             self.clean_file(c, '\\test_copy_chunk_posix_src')
             self.clean_file(c, '\\test_copy_chunk_posix_dst')
+
+    def test_append(self):
+        """
+        Test append-io behaviour
+        """
+        (wc, pc) = self.connections()
+
+        self.clean_file(pc, '\\test_append')
+        wire_mode = libsmb.unix_mode_to_wire(0o644)
+
+        ph,*_ = pc.create_ex('\\test_append',
+                             DesiredAccess=security.SEC_FILE_APPEND_DATA | security.SEC_FILE_READ_DATA,
+                             CreateDisposition=libsmb.FILE_CREATE,
+                             ShareAccess=libsmb.FILE_SHARE_READ|libsmb.FILE_SHARE_WRITE,
+                             CreateContexts=[posix_context(wire_mode)])
+
+        wh,*_ = wc.create_ex('\\test_append',
+                             DesiredAccess=security.SEC_FILE_APPEND_DATA,
+                             ShareAccess=libsmb.FILE_SHARE_READ|libsmb.FILE_SHARE_WRITE,
+                             CreateDisposition=libsmb.FILE_OPEN)
+
+        wc.write(wh, buffer=b"hello", offset=0)
+        wc.write(wh, buffer=b"h", offset=0)
+
+        try:
+            pc.write(ph, buffer=b"world", offset=0)
+        except Exception as e:
+            self.assertEqual(e.args[0], ntstatus.NT_STATUS_INVALID_PARAMETER)
+            pass
+        else:
+            pc.close(ph)
+            wc.close(wh)
+            self.clean_file(pc, '\\test_append')
+            self.fail("Write with offset=0 must fail on POSIX handle in append mode")
+
+        pc.write(ph, buffer=b" world", offset=libsmb.VFS_PWRITE_APPEND_OFFSET)
+
+        info = pc.qfileinfo(ph, libsmb.FSCC_FILE_POSIX_INFORMATION);
+        self.assertEqual(info['size'], 11)
+
+        data = pc.read(ph, 0, 11)
+        self.assertEqual(data, b'hello world')
+
+        pc.close(ph)
+        wc.close(wh)
+        self.clean_file(pc, '\\test_append')
diff --git a/selftest/knownfail.d/samba.tests.smb3unix b/selftest/knownfail.d/samba.tests.smb3unix
new file mode 100644 (file)
index 0000000..d6fa705
--- /dev/null
@@ -0,0 +1 @@
+^samba.tests.smb3unix.samba.tests.smb3unix.Smb3UnixTests.test_append\(fileserver_smb1\)