Skip to content

Commit

Permalink
Implement test for connection validator
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Jan 16, 2024
1 parent d9d3fcb commit dbadb6f
Show file tree
Hide file tree
Showing 7 changed files with 373 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/gui/connectionvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ Q_LOGGING_CATEGORY(lcConnectionValidator, "sync.connectionvalidator", QtInfoMsg)
// Make sure the timeout for this job is less than how often we get called
// This makes sure we get tried often enough without "ConnectionValidator already running"
namespace {
const auto timeoutToUse = ConnectionValidator::DefaultCallingInterval - 5s;
auto timeoutToUse()
{
return std::min(ConnectionValidator::DefaultCallingInterval - 5s, AbstractNetworkJob::httpTimeout);
};
}

ConnectionValidator::ConnectionValidator(AccountPtr account, QObject *parent)
Expand Down Expand Up @@ -194,7 +197,7 @@ void ConnectionValidator::checkAuthentication()
// we explicitly use a legacy dav path here
auto *job = new PropfindJob(_account, _account->url(), Theme::instance()->webDavPath(), PropfindJob::Depth::Zero, this);
job->setAuthenticationJob(true); // don't retry
job->setTimeout(timeoutToUse);
job->setTimeout(timeoutToUse());
job->setProperties({ QByteArrayLiteral("getlastmodified") });
connect(job, &PropfindJob::finishedWithoutError, this, &ConnectionValidator::slotAuthSuccess);
connect(job, &PropfindJob::finishedWithError, this, &ConnectionValidator::slotAuthFailed);
Expand Down
9 changes: 6 additions & 3 deletions src/gui/fetchserversettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ using namespace OCC;
Q_LOGGING_CATEGORY(lcfetchserversettings, "sync.fetchserversettings", QtInfoMsg)

namespace {
constexpr auto timeoutC = 20s;
auto fetchSettingsTimeout()
{
return std::min(20s, AbstractNetworkJob::httpTimeout);
}
}

// TODO: move to libsync?
Expand All @@ -43,7 +46,7 @@ void FetchServerSettingsJob::start()
// The main flow now needs the capabilities
auto *job = new JsonApiJob(_account, QStringLiteral("ocs/v2.php/cloud/capabilities"), {}, {}, this);
job->setAuthenticationJob(isAuthJob());
job->setTimeout(timeoutC);
job->setTimeout(fetchSettingsTimeout());

connect(job, &JsonApiJob::finishedSignal, this, [job, this] {
auto caps =
Expand All @@ -69,7 +72,7 @@ void FetchServerSettingsJob::start()
}
auto *userJob = new JsonApiJob(_account, QStringLiteral("ocs/v2.php/cloud/user"), SimpleNetworkJob::UrlQuery{}, QNetworkRequest{}, this);
userJob->setAuthenticationJob(isAuthJob());
userJob->setTimeout(timeoutC);
userJob->setTimeout(fetchSettingsTimeout());
connect(userJob, &JsonApiJob::finishedSignal, this, [userJob, this] {
if (userJob->timedOut()) {
Q_EMIT finishedSignal(Result::TimeOut);
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ owncloud_add_test(SyncFileItem)
owncloud_add_test(ConcatUrl)
owncloud_add_test(XmlParse)
owncloud_add_test(ChecksumValidator)
owncloud_add_test(ConnectionValidator)


# TODO: we need keychain access for this test
Expand Down
179 changes: 179 additions & 0 deletions test/testconnectionvalidator/capabilities.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
{
"ocs": {
"meta": {
"status": "ok",
"statuscode": 100,
"message": "OK"
},
"data": {
"capabilities": {
"core": {
"pollinterval": 60,
"webdav-root": "remote.php/webdav",
"status": {
"installed": true,
"maintenance": false,
"needsDbUpgrade": false,
"version": "@{version}",
"versionstring": "10.11.0",
"edition": "Community",
"productname": "Infinite Scale",
"product": "Infinite Scale",
"productversion": "@{productversion}"
},
"support-url-signing": true,
"support-sse": true
},
"checksums": {
"supportedTypes": [
"sha1",
"md5",
"adler32"
],
"preferredUploadType": "sha1"
},
"files": {
"privateLinks": true,
"bigfilechunking": false,
"undelete": true,
"versioning": true,
"favorites": false,
"full_text_search": false,
"tags": true,
"blacklisted_files": [],
"tus_support": {
"version": "1.0.0",
"resumable": "1.0.0",
"extension": "creation,creation-with-upload",
"max_chunk_size": 100000000,
"http_method_override": ""
},
"archivers": [
{
"enabled": true,
"version": "2.0.0",
"formats": [
"tar",
"zip"
],
"archiver_url": "/archiver",
"max_num_files": "10000",
"max_size": "1073741824"
}
],
"app_providers": [
{
"enabled": true,
"version": "1.1.0",
"apps_url": "/app/list",
"open_url": "/app/open",
"open_web_url": "/app/open-with-web",
"new_url": "/app/new"
}
]
},
"dav": {
"chunking": "",
"trashbin": "1.0",
"reports": [
"search-files"
],
"chunkingParallelUploadDisabled": false
},
"files_sharing": {
"api_enabled": true,
"resharing": true,
"group_sharing": true,
"sharing_roles": true,
"deny_access": false,
"auto_accept_share": true,
"share_with_group_members_only": true,
"share_with_membership_groups_only": true,
"search_min_length": 3,
"default_permissions": 22,
"user_enumeration": {
"enabled": true,
"group_members_only": true
},
"federation": {
"outgoing": false,
"incoming": false
},
"public": {
"enabled": true,
"send_mail": true,
"social_share": true,
"upload": true,
"multiple": true,
"supports_upload_only": true,
"password": {
"enforced_for": {
"read_only": false,
"read_write": false,
"read_write_delete": false,
"upload_only": false
},
"enforced": false
},
"expire_date": {
"enabled": false
},
"can_edit": true,
"alias": true
},
"user": {
"send_mail": true,
"profile_picture": false,
"settings": [
{
"enabled": true,
"version": "1.0.0"
}
],
"expire_date": {
"enabled": true
}
}
},
"spaces": {
"version": "1.0.0",
"enabled": true,
"projects": true,
"share_jail": true,
"max_quota": 0
},
"graph": {
"personal-data-export": true,
"users": {
"read_only_attributes": [
"user.onPremisesSamAccountName",
"user.displayName",
"user.mail",
"user.passwordProfile",
"user.appRoleAssignments"
],
"create_disabled": true,
"delete_disabled": true,
"change_password_self_disabled": true
}
},
"notifications": {
"ocs-endpoints": [
"list",
"get",
"delete"
]
}
},
"version": {
"major": 10,
"minor": 11,
"micro": 0,
"string": "10.11.0",
"edition": "Community",
"product": "Infinite Scale",
"productversion": "4.0.5"
}
}
}
}
11 changes: 11 additions & 0 deletions test/testconnectionvalidator/status.php.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"installed": true,
"maintenance": @{maintenance},
"needsDbUpgrade": false,
"version": "10.11.0.0",
"versionstring": "10.11.0",
"edition": "Community",
"productname": "Infinite Scale",
"product": "Infinite Scale",
"productversion": "4.0.5"
}
Loading

0 comments on commit dbadb6f

Please sign in to comment.