2015-07-13 15:35:19 +03:00
|
|
|
/*
|
|
|
|
* This software is in the public domain, furnished "as is", without technical
|
|
|
|
* support, and with no warranty, express or implied, as to its usefulness for
|
|
|
|
* any purpose.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-07-15 10:47:42 +03:00
|
|
|
#include <qglobal.h>
|
2015-07-13 15:35:19 +03:00
|
|
|
#include <QTemporaryDir>
|
|
|
|
#include <QtTest>
|
|
|
|
|
2022-11-16 22:56:34 +03:00
|
|
|
#include "QtTest/qtestcase.h"
|
2017-08-16 09:36:52 +03:00
|
|
|
#include "common/utility.h"
|
2015-07-13 15:35:19 +03:00
|
|
|
#include "folderman.h"
|
2016-03-16 21:07:40 +03:00
|
|
|
#include "account.h"
|
2015-07-13 15:35:19 +03:00
|
|
|
#include "accountstate.h"
|
2022-10-21 17:11:29 +03:00
|
|
|
#include <accountmanager.h>
|
2016-10-11 12:55:20 +03:00
|
|
|
#include "configfile.h"
|
2022-10-21 17:11:29 +03:00
|
|
|
#include "syncenginetestutils.h"
|
2019-07-24 14:56:21 +03:00
|
|
|
#include "testhelper.h"
|
2016-10-07 17:24:09 +03:00
|
|
|
|
2015-07-13 15:35:19 +03:00
|
|
|
using namespace OCC;
|
|
|
|
|
2023-01-09 17:51:26 +03:00
|
|
|
static QByteArray fake400Response = R"(
|
|
|
|
{"ocs":{"meta":{"status":"failure","statuscode":400,"message":"Parameter is incorrect.\n"},"data":[]}}
|
|
|
|
)";
|
|
|
|
|
2022-11-16 22:56:34 +03:00
|
|
|
bool itemDidCompleteSuccessfully(const ItemCompletedSpy &spy, const QString &path)
|
|
|
|
{
|
|
|
|
if (auto item = spy.findItem(path)) {
|
|
|
|
return item->_status == SyncFileItem::Success;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:35:19 +03:00
|
|
|
class TestFolderMan: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
FolderMan _fm;
|
|
|
|
|
2022-10-21 17:11:29 +03:00
|
|
|
signals:
|
|
|
|
void incomingShareDeleted();
|
|
|
|
|
2015-07-13 15:35:19 +03:00
|
|
|
private slots:
|
2023-01-09 17:51:26 +03:00
|
|
|
void testDeleteEncryptedFiles()
|
|
|
|
{
|
|
|
|
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
|
|
|
|
QCOMPARE(fakeFolder.currentLocalState().children.count(), 4);
|
|
|
|
|
|
|
|
ItemCompletedSpy completeSpy(fakeFolder);
|
|
|
|
fakeFolder.localModifier().mkdir("encrypted");
|
|
|
|
fakeFolder.localModifier().setE2EE("encrypted", true);
|
|
|
|
fakeFolder.remoteModifier().mkdir("encrypted");
|
|
|
|
fakeFolder.remoteModifier().setE2EE("encrypted", true);
|
|
|
|
|
|
|
|
const auto fakeFileInfo = fakeFolder.remoteModifier().find("encrypted");
|
|
|
|
QVERIFY(fakeFileInfo);
|
2023-01-23 23:37:57 +03:00
|
|
|
QVERIFY(fakeFileInfo->isEncrypted);
|
2023-01-09 17:51:26 +03:00
|
|
|
QCOMPARE(fakeFolder.currentLocalState().children.count(), 5);
|
|
|
|
|
|
|
|
const auto fakeFileId = fakeFileInfo->fileId;
|
|
|
|
const auto fakeQnam = new FakeQNAM({});
|
|
|
|
// Let's avoid the null filename assert in the default FakeQNAM request creation
|
|
|
|
const auto fakeQnamOverride = [this, fakeFileId](const QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *device) {
|
|
|
|
Q_UNUSED(device)
|
|
|
|
QNetworkReply *reply = nullptr;
|
|
|
|
|
|
|
|
const auto reqUrl = req.url();
|
|
|
|
const auto reqRawPath = reqUrl.path();
|
|
|
|
const auto reqPath = reqRawPath.startsWith("/owncloud/") ? reqRawPath.mid(10) : reqRawPath;
|
|
|
|
|
|
|
|
if (reqPath.startsWith(QStringLiteral("ocs/v2.php/apps/end_to_end_encryption/api/v1/meta-data/"))) {
|
|
|
|
const auto splitUrlPath = reqPath.split('/');
|
|
|
|
const auto fileId = splitUrlPath.last();
|
|
|
|
|
|
|
|
const QUrlQuery urlQuery(req.url());
|
|
|
|
const auto formatParam = urlQuery.queryItemValue(QStringLiteral("format"));
|
|
|
|
|
|
|
|
if(fileId == fakeFileId && formatParam == QStringLiteral("json")) {
|
|
|
|
reply = new FakePayloadReply(op, req, QJsonDocument().toJson(), this);
|
|
|
|
} else {
|
|
|
|
reply = new FakeErrorReply(op, req, this, 400, fake400Response);
|
|
|
|
}
|
|
|
|
}
|
2023-01-23 23:37:57 +03:00
|
|
|
|
2023-01-09 17:51:26 +03:00
|
|
|
return reply;
|
|
|
|
};
|
|
|
|
fakeFolder.setServerOverride(fakeQnamOverride);
|
|
|
|
fakeQnam->setOverride(fakeQnamOverride);
|
|
|
|
|
|
|
|
const auto account = Account::create();
|
|
|
|
const auto capabilities = QVariantMap {
|
|
|
|
{QStringLiteral("end-to-end-encryption"), QVariantMap {
|
|
|
|
{QStringLiteral("enabled"), true},
|
|
|
|
{QStringLiteral("api-version"), QString::number(2.0)},
|
|
|
|
}},
|
|
|
|
};
|
|
|
|
account->setCapabilities(capabilities);
|
|
|
|
account->setCredentials(new FakeCredentials{fakeQnam});
|
|
|
|
account->setUrl(QUrl(("owncloud://somehost/owncloud")));
|
|
|
|
const auto accountState = new FakeAccountState(account);
|
|
|
|
QVERIFY(accountState->isConnected());
|
|
|
|
|
|
|
|
QVERIFY(fakeFolder.syncOnce());
|
|
|
|
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
|
|
|
|
2023-01-23 23:37:57 +03:00
|
|
|
auto folderDef = folderDefinition(fakeFolder.localPath());
|
|
|
|
folderDef.targetPath = "";
|
|
|
|
const auto folder = FolderMan::instance()->addFolder(accountState, folderDef);
|
2023-01-09 17:51:26 +03:00
|
|
|
QVERIFY(folder);
|
2023-01-23 23:37:57 +03:00
|
|
|
|
|
|
|
qRegisterMetaType<OCC::SyncResult>("SyncResult");
|
2023-01-09 17:51:26 +03:00
|
|
|
QSignalSpy folderSyncDone(folder, &Folder::syncFinished);
|
|
|
|
|
|
|
|
QDir dir(folder->path() + QStringLiteral("encrypted"));
|
|
|
|
QVERIFY(dir.exists());
|
|
|
|
QVERIFY(fakeFolder.remoteModifier().find("encrypted"));
|
|
|
|
QVERIFY(fakeFolder.currentLocalState().find("encrypted"));
|
|
|
|
QCOMPARE(fakeFolder.currentLocalState().children.count(), 5);
|
|
|
|
|
|
|
|
// Rather than go through the pain of trying to replicate the E2EE response from
|
|
|
|
// the server, let's just manually set the encryption bool in the folder journal
|
|
|
|
SyncJournalFileRecord rec;
|
|
|
|
QVERIFY(folder->journalDb()->getFileRecord(QStringLiteral("encrypted"), &rec));
|
|
|
|
rec._isE2eEncrypted = true;
|
|
|
|
rec._path = QStringLiteral("encrypted").toUtf8();
|
2023-01-23 23:37:57 +03:00
|
|
|
rec._type = CSyncEnums::ItemTypeDirectory;
|
2023-01-09 17:51:26 +03:00
|
|
|
QVERIFY(folder->journalDb()->setFileRecord(rec));
|
2023-01-23 23:37:57 +03:00
|
|
|
|
|
|
|
SyncJournalFileRecord updatedRec;
|
|
|
|
QVERIFY(folder->journalDb()->getFileRecord(QStringLiteral("encrypted"), &updatedRec));
|
2023-03-29 10:22:22 +03:00
|
|
|
QVERIFY(updatedRec.isE2eEncrypted());
|
2023-01-23 23:37:57 +03:00
|
|
|
QVERIFY(updatedRec.isDirectory());
|
|
|
|
|
2023-01-09 17:51:26 +03:00
|
|
|
FolderMan::instance()->removeE2eFiles(account);
|
|
|
|
|
2023-01-23 23:37:57 +03:00
|
|
|
if (folderSyncDone.isEmpty()) {
|
|
|
|
QVERIFY(folderSyncDone.wait());
|
|
|
|
}
|
2023-01-09 17:51:26 +03:00
|
|
|
|
|
|
|
QVERIFY(fakeFolder.currentRemoteState().find("encrypted"));
|
|
|
|
QVERIFY(!fakeFolder.currentLocalState().find("encrypted"));
|
|
|
|
QCOMPARE(fakeFolder.currentLocalState().children.count(), 4);
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:11:29 +03:00
|
|
|
void testLeaveShare()
|
|
|
|
{
|
2022-11-23 18:56:35 +03:00
|
|
|
QTemporaryDir dir;
|
|
|
|
ConfigFile::setConfDir(dir.path()); // we don't want to pollute the user's config file
|
|
|
|
|
2022-10-21 17:11:29 +03:00
|
|
|
constexpr auto firstSharePath = "A/sharedwithme_A.txt";
|
|
|
|
constexpr auto secondSharePath = "A/B/sharedwithme_B.data";
|
|
|
|
|
|
|
|
QScopedPointer<FakeQNAM> fakeQnam(new FakeQNAM({}));
|
|
|
|
OCC::AccountPtr account = OCC::Account::create();
|
|
|
|
account->setCredentials(new FakeCredentials{fakeQnam.data()});
|
|
|
|
account->setUrl(QUrl(("http://example.de")));
|
|
|
|
OCC::AccountManager::instance()->addAccount(account);
|
|
|
|
|
|
|
|
FakeFolder fakeFolder{FileInfo{}};
|
|
|
|
fakeFolder.remoteModifier().mkdir("A");
|
|
|
|
|
|
|
|
fakeFolder.remoteModifier().insert(firstSharePath, 100);
|
|
|
|
const auto firstShare = fakeFolder.remoteModifier().find(firstSharePath);
|
|
|
|
QVERIFY(firstShare);
|
|
|
|
firstShare->permissions.setPermission(OCC::RemotePermissions::IsShared);
|
|
|
|
|
|
|
|
fakeFolder.remoteModifier().mkdir("A/B");
|
|
|
|
|
|
|
|
fakeFolder.remoteModifier().insert(secondSharePath, 100);
|
|
|
|
const auto secondShare = fakeFolder.remoteModifier().find(secondSharePath);
|
|
|
|
QVERIFY(secondShare);
|
|
|
|
secondShare->permissions.setPermission(OCC::RemotePermissions::IsShared);
|
|
|
|
|
|
|
|
FolderMan *folderman = FolderMan::instance();
|
|
|
|
QCOMPARE(folderman, &_fm);
|
|
|
|
OCC::AccountState *accountState = OCC::AccountManager::instance()->accounts().first().data();
|
|
|
|
const auto folder = folderman->addFolder(accountState, folderDefinition(fakeFolder.localPath()));
|
|
|
|
QVERIFY(folder);
|
|
|
|
|
|
|
|
auto realFolder = FolderMan::instance()->folderForPath(fakeFolder.localPath());
|
|
|
|
QVERIFY(realFolder);
|
|
|
|
|
|
|
|
QVERIFY(fakeFolder.syncOnce());
|
|
|
|
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
|
|
|
|
|
|
|
fakeQnam->setOverride([this, accountState, &fakeFolder](QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *device) {
|
|
|
|
Q_UNUSED(device);
|
|
|
|
QNetworkReply *reply = nullptr;
|
|
|
|
|
|
|
|
if (op != QNetworkAccessManager::DeleteOperation) {
|
|
|
|
reply = new FakeErrorReply(op, req, this, 405);
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.url().path().isEmpty()) {
|
|
|
|
reply = new FakeErrorReply(op, req, this, 404);
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto filePathRelative = req.url().path().remove(accountState->account()->davPath());
|
|
|
|
|
|
|
|
const auto foundFileInRemoteFolder = fakeFolder.remoteModifier().find(filePathRelative);
|
|
|
|
|
|
|
|
if (filePathRelative.isEmpty() || !foundFileInRemoteFolder) {
|
|
|
|
reply = new FakeErrorReply(op, req, this, 404);
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
fakeFolder.remoteModifier().remove(filePathRelative);
|
|
|
|
reply = new FakePayloadReply(op, req, {}, nullptr);
|
|
|
|
|
|
|
|
emit incomingShareDeleted();
|
2022-11-23 18:57:14 +03:00
|
|
|
|
2022-10-21 17:11:29 +03:00
|
|
|
return reply;
|
|
|
|
});
|
|
|
|
|
|
|
|
QSignalSpy incomingShareDeletedSignal(this, &TestFolderMan::incomingShareDeleted);
|
|
|
|
|
|
|
|
// verify first share gets deleted
|
|
|
|
folderman->leaveShare(fakeFolder.localPath() + firstSharePath);
|
|
|
|
QCOMPARE(incomingShareDeletedSignal.count(), 1);
|
|
|
|
QVERIFY(!fakeFolder.remoteModifier().find(firstSharePath));
|
|
|
|
QVERIFY(fakeFolder.syncOnce());
|
|
|
|
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
|
|
|
|
|
|
|
// verify no share gets deleted
|
|
|
|
folderman->leaveShare(fakeFolder.localPath() + "A/B/notsharedwithme_B.data");
|
|
|
|
QCOMPARE(incomingShareDeletedSignal.count(), 1);
|
|
|
|
QVERIFY(fakeFolder.remoteModifier().find("A/B/sharedwithme_B.data"));
|
|
|
|
QVERIFY(fakeFolder.syncOnce());
|
|
|
|
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
|
|
|
|
|
|
|
// verify second share gets deleted
|
|
|
|
folderman->leaveShare(fakeFolder.localPath() + secondSharePath);
|
|
|
|
QCOMPARE(incomingShareDeletedSignal.count(), 2);
|
|
|
|
QVERIFY(!fakeFolder.remoteModifier().find(secondSharePath));
|
|
|
|
QVERIFY(fakeFolder.syncOnce());
|
|
|
|
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
|
|
|
|
|
|
|
OCC::AccountManager::instance()->deleteAccount(accountState);
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:35:19 +03:00
|
|
|
void testCheckPathValidityForNewFolder()
|
|
|
|
{
|
2020-11-26 17:03:11 +03:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
Utility::NtfsPermissionLookupRAII ntfs_perm;
|
|
|
|
#endif
|
2015-07-13 15:35:19 +03:00
|
|
|
QTemporaryDir dir;
|
2016-10-11 12:55:20 +03:00
|
|
|
ConfigFile::setConfDir(dir.path()); // we don't want to pollute the user's config file
|
2015-07-13 15:35:19 +03:00
|
|
|
QVERIFY(dir.isValid());
|
|
|
|
QDir dir2(dir.path());
|
|
|
|
QVERIFY(dir2.mkpath("sub/ownCloud1/folder/f"));
|
|
|
|
QVERIFY(dir2.mkpath("ownCloud2"));
|
|
|
|
QVERIFY(dir2.mkpath("sub/free"));
|
|
|
|
QVERIFY(dir2.mkpath("free2/sub"));
|
2015-07-28 13:14:52 +03:00
|
|
|
{
|
|
|
|
QFile f(dir.path() + "/sub/file.txt");
|
|
|
|
f.open(QFile::WriteOnly);
|
|
|
|
f.write("hello");
|
|
|
|
}
|
2017-02-09 20:17:01 +03:00
|
|
|
QString dirPath = dir2.canonicalPath();
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2016-10-07 17:24:09 +03:00
|
|
|
AccountPtr account = Account::create();
|
|
|
|
QUrl url("http://example.de");
|
2020-05-18 21:54:23 +03:00
|
|
|
auto *cred = new HttpCredentialsTest("testuser", "secret");
|
2016-10-07 17:24:09 +03:00
|
|
|
account->setCredentials(cred);
|
|
|
|
account->setUrl( url );
|
|
|
|
|
|
|
|
AccountStatePtr newAccountState(new AccountState(account));
|
2015-07-13 15:35:19 +03:00
|
|
|
FolderMan *folderman = FolderMan::instance();
|
|
|
|
QCOMPARE(folderman, &_fm);
|
2017-02-09 20:17:01 +03:00
|
|
|
QVERIFY(folderman->addFolder(newAccountState.data(), folderDefinition(dirPath + "/sub/ownCloud1")));
|
|
|
|
QVERIFY(folderman->addFolder(newAccountState.data(), folderDefinition(dirPath + "/ownCloud2")));
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2021-07-28 08:48:38 +03:00
|
|
|
const auto folderList = folderman->map();
|
|
|
|
|
|
|
|
for (const auto &folder : folderList) {
|
|
|
|
QVERIFY(!folder->isSyncRunning());
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:35:19 +03:00
|
|
|
|
|
|
|
// those should be allowed
|
2022-09-08 14:21:30 +03:00
|
|
|
// QString FolderMan::checkPathValidityForNewFolder(const QString& path, const QUrl &serverUrl, bool forNewDirectory).second
|
2016-10-07 17:24:09 +03:00
|
|
|
|
2022-09-08 13:00:13 +03:00
|
|
|
QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/free").second, QString());
|
|
|
|
QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/free2/").second, QString());
|
2015-07-28 13:14:52 +03:00
|
|
|
// Not an existing directory -> Ok
|
2022-09-08 13:00:13 +03:00
|
|
|
QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/bliblablu").second, QString());
|
|
|
|
QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/free/bliblablu").second, QString());
|
2022-09-08 14:21:30 +03:00
|
|
|
// QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/bliblablu/some/more").second, QString());
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2015-07-28 13:14:52 +03:00
|
|
|
// A file -> Error
|
2022-09-08 13:00:13 +03:00
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/sub/file.txt").second.isNull());
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2016-10-07 17:24:09 +03:00
|
|
|
// There are folders configured in those folders, url needs to be taken into account: -> ERROR
|
|
|
|
QUrl url2(url);
|
|
|
|
const QString user = account->credentials()->user();
|
|
|
|
url2.setUserName(user);
|
|
|
|
|
|
|
|
// The following both fail because they refer to the same account (user and url)
|
2022-09-08 13:00:13 +03:00
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/sub/ownCloud1", url2).second.isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/ownCloud2/", url2).second.isNull());
|
2016-10-07 17:24:09 +03:00
|
|
|
|
|
|
|
// Now it will work because the account is different
|
|
|
|
QUrl url3("http://anotherexample.org");
|
|
|
|
url3.setUserName("dummy");
|
2022-09-08 13:00:13 +03:00
|
|
|
QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/ownCloud1", url3).second, QString());
|
|
|
|
QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/ownCloud2/", url3).second, QString());
|
2016-10-07 17:24:09 +03:00
|
|
|
|
2022-09-08 13:00:13 +03:00
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath).second.isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/sub/ownCloud1/folder").second.isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/sub/ownCloud1/folder/f").second.isNull());
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2017-12-15 16:50:41 +03:00
|
|
|
#ifndef Q_OS_WIN // no links on windows, no permissions
|
2015-07-13 15:35:19 +03:00
|
|
|
// make a bunch of links
|
2017-02-09 20:17:01 +03:00
|
|
|
QVERIFY(QFile::link(dirPath + "/sub/free", dirPath + "/link1"));
|
|
|
|
QVERIFY(QFile::link(dirPath + "/sub", dirPath + "/link2"));
|
|
|
|
QVERIFY(QFile::link(dirPath + "/sub/ownCloud1", dirPath + "/link3"));
|
|
|
|
QVERIFY(QFile::link(dirPath + "/sub/ownCloud1/folder", dirPath + "/link4"));
|
2015-07-13 15:35:19 +03:00
|
|
|
|
|
|
|
// Ok
|
2022-09-08 14:21:30 +03:00
|
|
|
QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + "/link1").second.isNull());
|
|
|
|
QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + "/link2/free").second.isNull());
|
2015-07-13 15:35:19 +03:00
|
|
|
|
|
|
|
// Not Ok
|
2022-09-08 14:21:30 +03:00
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link2").second.isNull());
|
2016-10-07 17:24:09 +03:00
|
|
|
|
|
|
|
// link 3 points to an existing sync folder. To make it fail, the account must be the same
|
2022-09-08 14:21:30 +03:00
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link3", url2).second.isNull());
|
2016-10-07 17:24:09 +03:00
|
|
|
// while with a different account, this is fine
|
2022-09-08 14:21:30 +03:00
|
|
|
QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/link3", url3).second, QString());
|
2016-10-07 17:24:09 +03:00
|
|
|
|
2022-09-08 14:21:30 +03:00
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link4").second.isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link3/folder").second.isNull());
|
2015-07-28 13:14:52 +03:00
|
|
|
|
|
|
|
// test some non existing sub path (error)
|
2022-09-08 14:21:30 +03:00
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/sub/ownCloud1/some/sub/path").second.isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/ownCloud2/blublu").second.isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/sub/ownCloud1/folder/g/h").second.isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link3/folder/neu_folder").second.isNull());
|
2015-07-28 13:14:52 +03:00
|
|
|
|
|
|
|
// Subfolder of links
|
2022-09-08 14:21:30 +03:00
|
|
|
QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + "/link1/subfolder").second.isNull());
|
|
|
|
QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + "/link2/free/subfolder").second.isNull());
|
2015-07-28 13:14:52 +03:00
|
|
|
|
|
|
|
// Should not have the rights
|
2022-09-08 14:21:30 +03:00
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder("/").second.isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder("/usr/bin/somefolder").second.isNull());
|
2017-12-15 16:50:41 +03:00
|
|
|
#endif
|
|
|
|
|
2019-03-14 11:12:46 +03:00
|
|
|
#ifdef Q_OS_WIN // drive-letter tests
|
|
|
|
if (!QFileInfo("v:/").exists()) {
|
2022-09-08 13:00:13 +03:00
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder("v:").second.isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder("v:/").second.isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder("v:/foo").second.isNull());
|
2019-03-14 11:12:46 +03:00
|
|
|
}
|
|
|
|
if (QFileInfo("c:/").isWritable()) {
|
2022-09-08 13:00:13 +03:00
|
|
|
QVERIFY(folderman->checkPathValidityForNewFolder("c:").second.isNull());
|
|
|
|
QVERIFY(folderman->checkPathValidityForNewFolder("c:/").second.isNull());
|
|
|
|
QVERIFY(folderman->checkPathValidityForNewFolder("c:/foo").second.isNull());
|
2019-03-14 11:12:46 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-12-15 16:50:41 +03:00
|
|
|
// Invalid paths
|
2022-09-08 13:00:13 +03:00
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder("").second.isNull());
|
2018-07-16 13:46:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
// REMOVE ownCloud2 from the filesystem, but keep a folder sync'ed to it.
|
|
|
|
QDir(dirPath + "/ownCloud2/").removeRecursively();
|
2022-09-08 13:00:13 +03:00
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/ownCloud2/blublu").second.isNull());
|
|
|
|
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/ownCloud2/sub/subsub/sub").second.isNull());
|
2017-03-20 16:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void testFindGoodPathForNewSyncFolder()
|
|
|
|
{
|
|
|
|
// SETUP
|
|
|
|
|
|
|
|
QTemporaryDir dir;
|
|
|
|
ConfigFile::setConfDir(dir.path()); // we don't want to pollute the user's config file
|
|
|
|
QVERIFY(dir.isValid());
|
|
|
|
QDir dir2(dir.path());
|
|
|
|
QVERIFY(dir2.mkpath("sub/ownCloud1/folder/f"));
|
|
|
|
QVERIFY(dir2.mkpath("ownCloud"));
|
|
|
|
QVERIFY(dir2.mkpath("ownCloud2"));
|
|
|
|
QVERIFY(dir2.mkpath("ownCloud2/foo"));
|
|
|
|
QVERIFY(dir2.mkpath("sub/free"));
|
|
|
|
QVERIFY(dir2.mkpath("free2/sub"));
|
|
|
|
QString dirPath = dir2.canonicalPath();
|
|
|
|
|
|
|
|
AccountPtr account = Account::create();
|
|
|
|
QUrl url("http://example.de");
|
2020-05-18 21:54:23 +03:00
|
|
|
auto *cred = new HttpCredentialsTest("testuser", "secret");
|
2017-03-20 16:28:32 +03:00
|
|
|
account->setCredentials(cred);
|
|
|
|
account->setUrl( url );
|
2018-07-16 13:46:03 +03:00
|
|
|
url.setUserName(cred->user());
|
2017-03-20 16:28:32 +03:00
|
|
|
|
|
|
|
AccountStatePtr newAccountState(new AccountState(account));
|
|
|
|
FolderMan *folderman = FolderMan::instance();
|
|
|
|
QCOMPARE(folderman, &_fm);
|
|
|
|
QVERIFY(folderman->addFolder(newAccountState.data(), folderDefinition(dirPath + "/sub/ownCloud/")));
|
|
|
|
QVERIFY(folderman->addFolder(newAccountState.data(), folderDefinition(dirPath + "/ownCloud2/")));
|
|
|
|
|
|
|
|
// TEST
|
|
|
|
|
2023-03-24 14:29:41 +03:00
|
|
|
QCOMPARE(folderman->findGoodPathForNewSyncFolder(dirPath + "/oc", url, FolderMan::GoodPathStrategy::AllowOnlyNewPath),
|
2017-03-20 16:28:32 +03:00
|
|
|
QString(dirPath + "/oc"));
|
2023-03-24 14:29:41 +03:00
|
|
|
QCOMPARE(folderman->findGoodPathForNewSyncFolder(dirPath + "/ownCloud", url, FolderMan::GoodPathStrategy::AllowOnlyNewPath),
|
2017-03-20 16:28:32 +03:00
|
|
|
QString(dirPath + "/ownCloud3"));
|
2023-03-24 14:29:41 +03:00
|
|
|
QCOMPARE(folderman->findGoodPathForNewSyncFolder(dirPath + "/ownCloud2", url, FolderMan::GoodPathStrategy::AllowOnlyNewPath),
|
2017-03-20 16:28:32 +03:00
|
|
|
QString(dirPath + "/ownCloud22"));
|
2023-03-24 14:29:41 +03:00
|
|
|
QCOMPARE(folderman->findGoodPathForNewSyncFolder(dirPath + "/ownCloud2/foo", url, FolderMan::GoodPathStrategy::AllowOnlyNewPath),
|
2017-03-20 16:28:32 +03:00
|
|
|
QString(dirPath + "/ownCloud2/foo"));
|
2023-03-24 14:29:41 +03:00
|
|
|
QCOMPARE(folderman->findGoodPathForNewSyncFolder(dirPath + "/ownCloud2/bar", url, FolderMan::GoodPathStrategy::AllowOnlyNewPath),
|
2017-03-20 16:28:32 +03:00
|
|
|
QString(dirPath + "/ownCloud2/bar"));
|
2023-03-24 14:29:41 +03:00
|
|
|
QCOMPARE(folderman->findGoodPathForNewSyncFolder(dirPath + "/sub", url, FolderMan::GoodPathStrategy::AllowOnlyNewPath),
|
2017-03-20 16:28:32 +03:00
|
|
|
QString(dirPath + "/sub2"));
|
2018-07-16 13:46:03 +03:00
|
|
|
|
|
|
|
// REMOVE ownCloud2 from the filesystem, but keep a folder sync'ed to it.
|
|
|
|
// We should still not suggest this folder as a new folder.
|
|
|
|
QDir(dirPath + "/ownCloud2/").removeRecursively();
|
2023-03-24 14:29:41 +03:00
|
|
|
QCOMPARE(folderman->findGoodPathForNewSyncFolder(dirPath + "/ownCloud", url, FolderMan::GoodPathStrategy::AllowOnlyNewPath),
|
2018-07-16 13:46:03 +03:00
|
|
|
QString(dirPath + "/ownCloud3"));
|
2023-03-24 14:29:41 +03:00
|
|
|
QCOMPARE(folderman->findGoodPathForNewSyncFolder(dirPath + "/ownCloud2", url, FolderMan::GoodPathStrategy::AllowOnlyNewPath),
|
2018-07-16 13:46:03 +03:00
|
|
|
QString(dirPath + "/ownCloud22"));
|
2015-07-13 15:35:19 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-09 17:51:26 +03:00
|
|
|
QTEST_GUILESS_MAIN(TestFolderMan)
|
2016-03-30 18:58:15 +03:00
|
|
|
#include "testfolderman.moc"
|