From fe29d1cf543ba13a173e5f0c0ea20d8da0915df2 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 19 Aug 2024 13:33:36 +0200 Subject: [PATCH] add automated test for deletion of child items in read-only folders should ensure we are able to get files or dolders be deleted by sync engine within read-only folders would happen as the result of changes on server side being propagated locally or when using selective sync Signed-off-by: Matthieu Gallien --- test/testpermissions.cpp | 134 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/test/testpermissions.cpp b/test/testpermissions.cpp index 2e5ad41283650..ee1ddbcdb7a9d 100644 --- a/test/testpermissions.cpp +++ b/test/testpermissions.cpp @@ -769,6 +769,140 @@ private slots: QVERIFY(testFolderStatus.permissions() & std::filesystem::perms::owner_read); QVERIFY(!static_cast(testFolderStatus.permissions() & std::filesystem::perms::owner_write)); } + + void testDeleteChildItemsInReadOnlyFolder() + { + FakeFolder fakeFolder{FileInfo{}}; + + auto &remote = fakeFolder.remoteModifier(); + + remote.mkdir("readOnlyFolder"); + remote.mkdir("readOnlyFolder/test"); + remote.insert("readOnlyFolder/readOnlyFile.txt"); + + remote.find("readOnlyFolder")->permissions = RemotePermissions::fromServerString("M"); + remote.find("readOnlyFolder/test")->permissions = RemotePermissions::fromServerString("m"); + remote.find("readOnlyFolder/readOnlyFile.txt")->permissions = RemotePermissions::fromServerString("m"); + + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + remote.remove("readOnlyFolder/test"); + remote.remove("readOnlyFolder/readOnlyFile.txt"); + + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + const auto ensureReadOnlyItem = [&fakeFolder] (const auto path) -> bool { + const auto itemStatus = std::filesystem::status(static_cast(fakeFolder.localPath() + path).toStdWString()); + return static_cast(itemStatus.permissions() & std::filesystem::perms::owner_read); + }; + QVERIFY(ensureReadOnlyItem("/readOnlyFolder")); + } + + void testRenameChildItemsInReadOnlyFolder() + { + FakeFolder fakeFolder{FileInfo{}}; + + auto &remote = fakeFolder.remoteModifier(); + + remote.mkdir("readOnlyFolder"); + remote.mkdir("readOnlyFolder/test"); + remote.insert("readOnlyFolder/readOnlyFile.txt"); + + remote.find("readOnlyFolder")->permissions = RemotePermissions::fromServerString("M"); + remote.find("readOnlyFolder/test")->permissions = RemotePermissions::fromServerString("m"); + remote.find("readOnlyFolder/readOnlyFile.txt")->permissions = RemotePermissions::fromServerString("m"); + + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + remote.rename("readOnlyFolder/test", "readOnlyFolder/testRename"); + remote.rename("readOnlyFolder/readOnlyFile.txt", "readOnlyFolder/readOnlyFileRename.txt"); + + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + const auto ensureReadOnlyItem = [&fakeFolder] (const auto path) -> bool { + const auto itemStatus = std::filesystem::status(static_cast(fakeFolder.localPath() + path).toStdWString()); + return static_cast(itemStatus.permissions() & std::filesystem::perms::owner_read); + }; + QVERIFY(ensureReadOnlyItem("/readOnlyFolder")); + QVERIFY(ensureReadOnlyItem("/readOnlyFolder/testRename")); + QVERIFY(ensureReadOnlyItem("/readOnlyFolder/readOnlyFileRename.txt")); + } + + void testMoveChildItemsInReadOnlyFolder() + { + FakeFolder fakeFolder{FileInfo{}}; + + auto &remote = fakeFolder.remoteModifier(); + + remote.mkdir("readOnlyFolder"); + remote.mkdir("readOnlyFolder/child"); + remote.mkdir("readOnlyFolder/test"); + remote.insert("readOnlyFolder/readOnlyFile.txt"); + + remote.find("readOnlyFolder")->permissions = RemotePermissions::fromServerString("M"); + remote.find("readOnlyFolder/child")->permissions = RemotePermissions::fromServerString("m"); + remote.find("readOnlyFolder/test")->permissions = RemotePermissions::fromServerString("m"); + remote.find("readOnlyFolder/readOnlyFile.txt")->permissions = RemotePermissions::fromServerString("m"); + + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + remote.rename("readOnlyFolder/test", "readOnlyFolder/child/test"); + remote.rename("readOnlyFolder/readOnlyFile.txt", "readOnlyFolder/child/readOnlyFile.txt"); + + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + const auto ensureReadOnlyItem = [&fakeFolder] (const auto path) -> bool { + const auto itemStatus = std::filesystem::status(static_cast(fakeFolder.localPath() + path).toStdWString()); + return static_cast(itemStatus.permissions() & std::filesystem::perms::owner_read); + }; + QVERIFY(ensureReadOnlyItem("/readOnlyFolder")); + QVERIFY(ensureReadOnlyItem("/readOnlyFolder/child")); + QVERIFY(ensureReadOnlyItem("/readOnlyFolder/child/test")); + QVERIFY(ensureReadOnlyItem("/readOnlyFolder/child/readOnlyFile.txt")); + } + + void testModifyChildItemsInReadOnlyFolder() + { + FakeFolder fakeFolder{FileInfo{}}; + + auto &remote = fakeFolder.remoteModifier(); + + remote.mkdir("readOnlyFolder"); + remote.mkdir("readOnlyFolder/test"); + remote.insert("readOnlyFolder/readOnlyFile.txt"); + + remote.find("readOnlyFolder")->permissions = RemotePermissions::fromServerString("M"); + remote.find("readOnlyFolder/test")->permissions = RemotePermissions::fromServerString("m"); + remote.find("readOnlyFolder/readOnlyFile.txt")->permissions = RemotePermissions::fromServerString("m"); + + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + remote.insert("readOnlyFolder/test/newFile.txt"); + remote.find("readOnlyFolder/test/newFile.txt")->permissions = RemotePermissions::fromServerString("m"); + remote.mkdir("readOnlyFolder/test/newFolder"); + remote.find("readOnlyFolder/test/newFolder")->permissions = RemotePermissions::fromServerString("m"); + remote.appendByte("readOnlyFolder/readOnlyFile.txt"); + + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + const auto ensureReadOnlyItem = [&fakeFolder] (const auto path) -> bool { + const auto itemStatus = std::filesystem::status(static_cast(fakeFolder.localPath() + path).toStdWString()); + return static_cast(itemStatus.permissions() & std::filesystem::perms::owner_read); + }; + QVERIFY(ensureReadOnlyItem("/readOnlyFolder")); + QVERIFY(ensureReadOnlyItem("/readOnlyFolder/test")); + QVERIFY(ensureReadOnlyItem("/readOnlyFolder/readOnlyFile.txt")); + QVERIFY(ensureReadOnlyItem("/readOnlyFolder/test/newFile.txt")); + QVERIFY(ensureReadOnlyItem("/readOnlyFolder/newFolder")); + } #endif };