fix(settings): address review feedback on managed override settings

- Return whether setOverrideServerUrl() and setOverrideLocalDir() wrote
  the value, and show a hint when a policy blocks --overrideserverurl or
  --overridelocaldir.
- Reject a --overridelocaldir path that is not absolute while parsing the
  command line, using the schema validator.
- Add ConfigFile::isOverrideServerUrlLocked(), shared by the wizard and
  the nc:// URI scheme handler, so only a policy or command line value
  locks the server URL and restricts login links. Builds enable
  APPLICATION_SERVER_URL_ENFORCE by default, so the wizard now clears the
  lock for a device default.
- Apply an overrideLocalDir from device default or policy only to the
  first account, in the wizard and for account setup from the command
  line. A command line value still applies to the next account. Skip the
  sync options step only for a locked folder.
- Update the docs and add tests.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Nathan van Dael <[email protected]>
This commit is contained in:
Nathan van Dael committed 2026-10-26 16:50:31 +01:00
1 parent 2a51533064
commit f209efb1ec
13 files changed
+289 -30

No files matched your search

+8 -3
View File
@@ -125,9 +125,13 @@ schema, so a policy can not enforce a setting the client did not declare.
device default prefills every new account setup and stays editable, while a device
policy or `--overrideserverurl` locks the server URL and starts the login flow. The
wizard removes the user value after an account is added, so a command line override
applies once and a device default applies again. Legacy account migration is skipped
only for an override from the user config. The server cannot set these keys, because
they are needed before an account exists.
applies once and a device default applies again. Only a locked server URL restricts
which servers `nc://login` links may open. An `overrideLocalDir` from device default
or policy applies only to the first account, in the wizard and for an account set up
from the command line, and a device default folder stays editable. `--overridelocaldir`
applies to the account set up next. Legacy account migration is skipped only for an
override from the user config. The server cannot set these keys, because they are
needed before an account exists.
- **`overrideServerUrl` is a URL or a JSON list of servers**: a single value starts
with `http://` or `https://`. A list is a JSON array of `{"name": "...", "url": "..."}`
objects, which the wizard offers as a choice of servers only when the server URL is
@@ -135,6 +139,7 @@ locked, so a list set as a device default leaves the server field empty.
`--overrideserverurl` accepts a single URL only.
- **`overrideLocalDir` is an absolute path**: environment variables such as
`%USERPROFILE%` are not expanded, so such a value is not absolute.
`--overridelocaldir` rejects a path that is not absolute.
- **An empty or invalid override value is skipped**, from any source, so the next
source applies. This includes an empty user value written by older clients.
- **Proxy resolves through getConfig as well**, wrapped in
+1 -1
View File
@@ -66,7 +66,7 @@ bool AccountSetupFromCommandLineJob::localSyncFolderRequired() const
QString AccountSetupFromCommandLineJob::defaultLocalDirPath() const
{
const auto overrideLocalDir = ConfigFile().overrideLocalDir();
const auto overrideLocalDir = ConfigFile().overrideLocalDirForNewAccount(AccountManager::instance()->accounts().isEmpty());
auto localDirPath = overrideLocalDir;
if (localDirPath.isEmpty()) {
+11 -5
View File
@@ -34,6 +34,7 @@
#include "version.h"
#include "config.h"
#include "settings/managedsettingsschema.h"
#include "settings/migration.h"
#if defined(Q_OS_WIN)
@@ -361,18 +362,18 @@ Application::Application(int &argc, char **argv)
// these config values will always be empty after the first client run
if (!_overrideServerUrl.isEmpty()) {
if (cfg.isEnforced(QLatin1String(ConfigFile::overrideServerUrlC))) {
if (!cfg.setOverrideServerUrl(_overrideServerUrl)) {
qCWarning(lcApplication) << "Ignoring --overrideserverurl because overrideServerUrl is enforced by a policy.";
showHint("--overrideserverurl cannot be used because overrideServerUrl is enforced by a policy");
}
cfg.setOverrideServerUrl(_overrideServerUrl);
shouldExit = true;
}
if (!_overrideLocalDir.isEmpty()) {
if (cfg.isEnforced(QLatin1String(ConfigFile::overrideLocalDirC))) {
if (!cfg.setOverrideLocalDir(_overrideLocalDir)) {
qCWarning(lcApplication) << "Ignoring --overridelocaldir because overrideLocalDir is enforced by a policy.";
showHint("--overridelocaldir cannot be used because overrideLocalDir is enforced by a policy");
}
cfg.setOverrideLocalDir(_overrideLocalDir);
shouldExit = true;
}
@@ -1097,7 +1098,12 @@ void Application::parseOptions(const QStringList &options)
}
} else if (option == QStringLiteral("--overridelocaldir")) {
if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
_overrideLocalDir = it.next();
const auto overrideLocalDir = it.next();
if (!ManagedSettingsSchema::isValidOverrideLocalDir(overrideLocalDir)) {
showHint("Invalid path passed to --overridelocaldir, the path must be absolute");
} else {
_overrideLocalDir = overrideLocalDir;
}
} else {
showHint("Invalid URL passed to --overridelocaldir");
}
+3 -2
View File
@@ -87,8 +87,9 @@ constexpr auto loginServerPathPrefix = "/server:";
[[nodiscard]] bool isAllowedByConfiguredServerOverride(const QUrl &serverUrl)
{
const auto configuredOverrideServerUrl = ConfigFile{}.overrideServerUrl();
if (!configuredOverrideServerUrl.isEmpty()) {
ConfigFile cfg;
if (cfg.isOverrideServerUrlLocked()) {
const auto configuredOverrideServerUrl = cfg.overrideServerUrl();
const auto normalizedServerUrl = normalizedServerUrlForComparison(serverUrl);
const auto allowedServerUrls = configuredOverrideServerUrls(configuredOverrideServerUrl);
for (const auto &allowedServerUrl : allowedServerUrls) {
+12 -5
View File
@@ -137,9 +137,11 @@ void AccountWizardController::initialiseAccount()
if (!cfg.overrideServerUrl().isEmpty()) {
Theme::instance()->setOverrideServerUrl(cfg.overrideServerUrl());
Theme::instance()->setVfsEnabled(cfg.isVfsEnabled());
if (cfg.isEnforced(QLatin1String(ConfigFile::overrideServerUrlC)) || cfg.hasUserOverrideServerUrl()) {
if (cfg.isOverrideServerUrlLocked()) {
Theme::instance()->setForceOverrideServerUrl(true);
Theme::instance()->setStartLoginFlowAutomatically(true);
} else {
Theme::instance()->setForceOverrideServerUrl(false);
}
}
@@ -1214,7 +1216,8 @@ void AccountWizardController::chooseSyncModeAfterCapabilities()
if (needsSyncOptions()) {
ConfigFile cfg;
if (Theme::instance()->forceOverrideServerUrl() && !cfg.overrideLocalDir().isEmpty()) {
const auto localDirLocked = cfg.isEnforced(QLatin1String(ConfigFile::overrideLocalDirC)) || cfg.hasUserOverrideLocalDir();
if (Theme::instance()->forceOverrideServerUrl() && localDirLocked && !applicableOverrideLocalDir().isEmpty()) {
QTimer::singleShot(0, this, &AccountWizardController::finish);
return;
}
@@ -1376,14 +1379,18 @@ void AccountWizardController::clearOneShotOverrides()
cfg.clearOverrideLocalDir();
}
QString AccountWizardController::applicableOverrideLocalDir() const
{
return ConfigFile().overrideLocalDirForNewAccount(AccountManager::instance()->accounts().isEmpty());
}
void AccountWizardController::initialiseLocalSyncFolder()
{
ConfigFile cfg;
const auto overrideLocalDir = !cfg.overrideLocalDir().isEmpty();
const auto overrideLocalDir = !applicableOverrideLocalDir().isEmpty();
_localSyncFolderOverride = overrideLocalDir;
QString localFolder;
if (overrideLocalDir) {
localFolder = cfg.overrideLocalDir();
localFolder = applicableOverrideLocalDir();
} else {
#ifndef Q_OS_MACOS
localFolder = Theme::instance()->defaultClientFolder();
+1
View File
@@ -294,6 +294,7 @@ private:
void fetchRootFolderSize();
AccountState *applyAccountChanges();
void clearOneShotOverrides();
[[nodiscard]] QString applicableOverrideLocalDir() const;
void initialiseLocalSyncFolder();
void setLocalSyncFolder(const QString &localSyncFolder, bool selectedByUser = false, const QByteArray &bookmarkData = {});
void promptForInitialLocalSyncFolderIfNeeded();
+23 -4
View File
@@ -897,9 +897,14 @@ void ConfigFile::setUpdateChannel(const QString &channel)
return resolved.source == SettingSourceType::UserConfig && !resolved.value.toString().isEmpty();
}
void ConfigFile::setOverrideServerUrl(const QString &url)
[[nodiscard]] bool ConfigFile::isOverrideServerUrlLocked() const
{
setConfig(QLatin1String(overrideServerUrlC), url);
return isEnforced(QLatin1String(overrideServerUrlC)) || hasUserOverrideServerUrl();
}
bool ConfigFile::setOverrideServerUrl(const QString &url)
{
return setConfig(QLatin1String(overrideServerUrlC), url);
}
void ConfigFile::clearOverrideServerUrl()
@@ -912,9 +917,23 @@ void ConfigFile::clearOverrideServerUrl()
return getConfig<QString>(QLatin1String(overrideLocalDirC));
}
void ConfigFile::setOverrideLocalDir(const QString &localDir)
[[nodiscard]] bool ConfigFile::hasUserOverrideLocalDir() const
{
setConfig(QLatin1String(overrideLocalDirC), localDir);
const auto resolved = getConfig(QLatin1String(overrideLocalDirC));
return resolved.source == SettingSourceType::UserConfig && !resolved.value.toString().isEmpty();
}
[[nodiscard]] QString ConfigFile::overrideLocalDirForNewAccount(bool firstAccount) const
{
if (!firstAccount && !hasUserOverrideLocalDir()) {
return {};
}
return overrideLocalDir();
}
bool ConfigFile::setOverrideLocalDir(const QString &localDir)
{
return setConfig(QLatin1String(overrideLocalDirC), localDir);
}
void ConfigFile::clearOverrideLocalDir()
+5 -2
View File
@@ -226,11 +226,14 @@ public:
[[nodiscard]] QString overrideServerUrl() const;
[[nodiscard]] bool hasUserOverrideServerUrl() const;
void setOverrideServerUrl(const QString &url);
[[nodiscard]] bool isOverrideServerUrlLocked() const;
bool setOverrideServerUrl(const QString &url);
void clearOverrideServerUrl();
[[nodiscard]] QString overrideLocalDir() const;
void setOverrideLocalDir(const QString &localDir);
[[nodiscard]] bool hasUserOverrideLocalDir() const;
[[nodiscard]] QString overrideLocalDirForNewAccount(bool firstAccount) const;
bool setOverrideLocalDir(const QString &localDir);
void clearOverrideLocalDir();
[[nodiscard]] bool isVfsEnabled() const;
@@ -56,13 +56,13 @@ bool isValidOverrideServerUrl(const QVariant &value)
return !serverObject.value("name"_L1).toString().isEmpty() && isValidServerUrl(serverObject.value("url"_L1).toString());
});
}
}
bool isValidOverrideLocalDir(const QVariant &value)
{
const auto localDir = value.toString();
return !localDir.isEmpty() && QDir::isAbsolutePath(localDir);
}
}
const QList<SettingDefinition> &all()
{
@@ -16,6 +16,7 @@ namespace OCC::ManagedSettingsSchema {
[[nodiscard]] OWNCLOUDSYNC_EXPORT const QList<SettingDefinition> &all();
[[nodiscard]] OWNCLOUDSYNC_EXPORT std::optional<SettingDefinition> find(const QString &key);
[[nodiscard]] OWNCLOUDSYNC_EXPORT bool isValidOverrideLocalDir(const QVariant &value);
}
#endif // MANAGEDSETTINGSSCHEMA_H
+86 -4
View File
@@ -4,11 +4,13 @@
*/
#include "account.h"
#include "accountmanager.h"
#include "configfile.h"
#include "folder.h"
#include "gui/localnetworkpermission.h"
#include "gui/wizard/accountwizardcontroller.h"
#include "managedsettingstestutils.h"
#include "syncenginetestutils.h"
#include "theme.h"
#ifdef BUILD_FILE_PROVIDER_MODULE
@@ -83,6 +85,11 @@ public:
{
controller.setCurrentStep(step);
}
static void initialiseLocalSyncFolder(AccountWizardController &controller)
{
controller.initialiseLocalSyncFolder();
}
};
}
@@ -95,18 +102,21 @@ Q_SIGNALS:
void signupUrlRequested(const QUrl &url);
private:
[[nodiscard]] static auto restoreOverrideServerUrlState()
[[nodiscard]] static auto restoreOverrideState()
{
ConfigFile().clearOverrideServerUrl();
ConfigFile().clearOverrideLocalDir();
auto theme = Theme::instance();
const auto previousOverrideServerUrl = theme->overrideServerUrl();
const auto previousForceOverrideServerUrl = theme->forceOverrideServerUrl();
const auto previousStartLoginFlowAutomatically = theme->startLoginFlowAutomatically();
theme->setOverrideServerUrl({});
theme->setForceOverrideServerUrl(false);
// Builds enable APPLICATION_SERVER_URL_ENFORCE by default.
theme->setForceOverrideServerUrl(true);
theme->setStartLoginFlowAutomatically(false);
return qScopeGuard([theme, previousOverrideServerUrl, previousForceOverrideServerUrl, previousStartLoginFlowAutomatically] {
ConfigFile().clearOverrideServerUrl();
ConfigFile().clearOverrideLocalDir();
theme->setOverrideServerUrl(previousOverrideServerUrl);
theme->setForceOverrideServerUrl(previousForceOverrideServerUrl);
theme->setStartLoginFlowAutomatically(previousStartLoginFlowAutomatically);
@@ -632,7 +642,7 @@ private Q_SLOTS:
void prefillsEditableServerUrlFromManagedDefault()
{
const auto restoreConfiguration = restoreOverrideServerUrlState();
const auto restoreConfiguration = restoreOverrideState();
setManagedOverrideServerUrl(SettingSourceType::PlatformDefault, EnforcementState::NotEnforced, 20);
AccountWizardController controller;
@@ -640,11 +650,12 @@ private Q_SLOTS:
QCOMPARE(controller.serverUrl(), u"https://cloud.example"_s);
QVERIFY(controller.serverUrlEditable());
QVERIFY(!controller.startLoginFlowAutomatically());
QVERIFY(!Theme::instance()->forceOverrideServerUrl());
}
void locksServerUrlFromManagedPolicy()
{
const auto restoreConfiguration = restoreOverrideServerUrlState();
const auto restoreConfiguration = restoreOverrideState();
setManagedOverrideServerUrl(SettingSourceType::PlatformPolicy, EnforcementState::Enforced, 200);
AccountWizardController controller;
@@ -654,6 +665,77 @@ private Q_SLOTS:
QVERIFY(controller.startLoginFlowAutomatically());
}
void appliesOverrideLocalDirForNewAccount_data()
{
QTest::addColumn<QString>("source");
QTest::addColumn<bool>("existingAccount");
QTest::addColumn<bool>("applies");
QTest::addColumn<bool>("showsSyncOptions");
QTest::newRow("policy, first account") << u"policy"_s << false << true << false;
QTest::newRow("policy, additional account") << u"policy"_s << true << false << true;
QTest::newRow("device default, first account") << u"default"_s << false << true << true;
QTest::newRow("device default, additional account") << u"default"_s << true << false << true;
QTest::newRow("command line, additional account") << u"commandLine"_s << true << true << false;
}
void appliesOverrideLocalDirForNewAccount()
{
QFETCH(QString, source);
QFETCH(bool, existingAccount);
QFETCH(bool, applies);
QFETCH(bool, showsSyncOptions);
QTemporaryDir dir;
QVERIFY(dir.isValid());
const auto restoreConfiguration = restoreOverrideState();
ConfigFile::setDeviceSourcesFactory([source, localDir = dir.path()] {
auto policyValues = QVariantMap{{u"overrideServerUrl"_s, u"https://cloud.example"_s}};
if (source == u"policy"_s) {
policyValues.insert(u"overrideLocalDir"_s, localDir);
}
std::vector<std::unique_ptr<SettingSource>> sources;
sources.push_back(std::make_unique<MapSource>(SettingSourceType::PlatformPolicy, EnforcementState::Enforced, 200, policyValues));
if (source == u"default"_s) {
sources.push_back(std::make_unique<MapSource>(SettingSourceType::PlatformDefault,
EnforcementState::NotEnforced,
20,
QVariantMap{{u"overrideLocalDir"_s, localDir}}));
}
return sources;
});
if (source == u"commandLine"_s) {
QVERIFY(ConfigFile().setOverrideLocalDir(dir.path()));
}
AccountState *accountState = nullptr;
const auto removeAccount = qScopeGuard([&accountState] {
if (accountState) {
AccountManager::instance()->removeAccountState(accountState);
}
});
if (existingAccount) {
auto account = Account::create();
account->setUrl(QUrl(u"https://cloud.example"_s));
account->setDavUser(u"first"_s);
account->setCredentials(new FakeCredentials{new FakeQNAM({})});
accountState = AccountManager::instance()->addAccount(account);
}
AccountWizardController controller;
AccountWizardControllerTestAccess::setAccountUrl(controller, QUrl(u"https://cloud.example"_s));
AccountWizardControllerTestAccess::initialiseLocalSyncFolder(controller);
QCOMPARE(AccountWizardControllerTestAccess::localSyncFolderOverride(controller), applies);
QCOMPARE(controller.localSyncFolder() == QDir::fromNativeSeparators(dir.path()), applies);
AccountWizardControllerTestAccess::chooseSyncModeAfterCapabilities(controller);
if (!controller.needsSyncOptions()) {
QSKIP("This build chooses no sync options, so the wizard always finishes.");
}
QCOMPARE(controller.currentStep() == AccountWizardController::SyncOptionsStep, showsSyncOptions);
}
#ifdef Q_OS_LINUX
void defaultSyncModeIsNotVirtualFilesOnLinux()
{
+82 -3
View File
@@ -386,7 +386,7 @@ private Q_SLOTS:
20,
QVariantMap{{u"overrideServerUrl"_s, u"https://cloud.example.com"_s}});
config.setOverrideServerUrl(u"https://user.example.com"_s);
QVERIFY(config.setOverrideServerUrl(u"https://user.example.com"_s));
QCOMPARE(config.overrideServerUrl(), u"https://user.example.com"_s);
QVERIFY(config.hasUserOverrideServerUrl());
@@ -402,7 +402,7 @@ private Q_SLOTS:
200,
QVariantMap{{u"overrideServerUrl"_s, u"https://cloud.example.com"_s}});
config.setOverrideServerUrl(u"https://user.example.com"_s);
QVERIFY(!config.setOverrideServerUrl(u"https://user.example.com"_s));
QCOMPARE(config.overrideServerUrl(), u"https://cloud.example.com"_s);
QVERIFY(config.isEnforced(u"overrideServerUrl"_s));
@@ -424,6 +424,8 @@ private Q_SLOTS:
QCOMPARE(config.overrideLocalDir(), u"/home/user/Nextcloud"_s);
QVERIFY(config.isEnforced(u"overrideLocalDir"_s));
QVERIFY(!config.hasUserOverrideLocalDir());
QVERIFY(!config.setOverrideLocalDir(u"/home/user/Other"_s));
}
void testClearedOverrideLocalDirFallsBackToDeviceDefault()
@@ -432,12 +434,89 @@ private Q_SLOTS:
ConfigFile config;
config.setConfDir(dir.path());
setDeviceSource(SettingSourceType::PlatformDefault, EnforcementState::NotEnforced, 20, QVariantMap{{u"overrideLocalDir"_s, u"/home/user/Nextcloud"_s}});
config.setOverrideLocalDir(u"/home/user/Personal"_s);
QVERIFY(config.setOverrideLocalDir(u"/home/user/Personal"_s));
QVERIFY(config.hasUserOverrideLocalDir());
config.clearOverrideLocalDir();
QCOMPARE(config.overrideLocalDir(), u"/home/user/Nextcloud"_s);
QCOMPARE(config.sourceOf(u"overrideLocalDir"_s), SettingSourceType::PlatformDefault);
QVERIFY(!config.hasUserOverrideLocalDir());
}
void testOverrideLocalDirForNewAccount_data()
{
QTest::addColumn<bool>("devicePolicy");
QTest::addColumn<bool>("userValue");
QTest::addColumn<bool>("firstAccount");
QTest::addColumn<QString>("expected");
QTest::newRow("device default, first account") << false << false << true << u"/home/user/Nextcloud"_s;
QTest::newRow("device default, additional account") << false << false << false << QString();
QTest::newRow("device policy, first account") << true << false << true << u"/home/user/Nextcloud"_s;
QTest::newRow("device policy, additional account") << true << false << false << QString();
QTest::newRow("user value, additional account") << false << true << false << u"/home/user/Personal"_s;
}
void testOverrideLocalDirForNewAccount()
{
QFETCH(bool, devicePolicy);
QFETCH(bool, userValue);
QFETCH(bool, firstAccount);
QFETCH(QString, expected);
QTemporaryDir dir;
ConfigFile config;
config.setConfDir(dir.path());
const auto values = QVariantMap{{u"overrideLocalDir"_s, u"/home/user/Nextcloud"_s}};
if (devicePolicy) {
setDeviceSource(SettingSourceType::PlatformPolicy, EnforcementState::Enforced, 200, values);
} else {
setDeviceSource(SettingSourceType::PlatformDefault, EnforcementState::NotEnforced, 20, values);
}
if (userValue) {
QVERIFY(config.setOverrideLocalDir(u"/home/user/Personal"_s));
}
QCOMPARE(config.overrideLocalDirForNewAccount(firstAccount), expected);
}
void testOverrideServerUrlLockedOnlyByPolicyOrUserValue_data()
{
QTest::addColumn<bool>("deviceDefault");
QTest::addColumn<bool>("devicePolicy");
QTest::addColumn<bool>("userValue");
QTest::addColumn<bool>("locked");
QTest::newRow("no value") << false << false << false << false;
QTest::newRow("device default") << true << false << false << false;
QTest::newRow("device policy") << false << true << false << true;
QTest::newRow("user value") << false << false << true << true;
QTest::newRow("user value over device default") << true << false << true << true;
}
void testOverrideServerUrlLockedOnlyByPolicyOrUserValue()
{
QFETCH(bool, deviceDefault);
QFETCH(bool, devicePolicy);
QFETCH(bool, userValue);
QFETCH(bool, locked);
QTemporaryDir dir;
ConfigFile config;
config.setConfDir(dir.path());
const auto values = QVariantMap{{u"overrideServerUrl"_s, u"https://cloud.example.com"_s}};
if (deviceDefault) {
setDeviceSource(SettingSourceType::PlatformDefault, EnforcementState::NotEnforced, 20, values);
}
if (devicePolicy) {
setDeviceSource(SettingSourceType::PlatformPolicy, EnforcementState::Enforced, 200, values);
}
if (userValue) {
QVERIFY(config.setOverrideServerUrl(u"https://user.example.com"_s));
}
QCOMPARE(config.isOverrideServerUrlLocked(), locked);
}
void testEmptyUserOverrideServerUrlFallsBackToDeviceDefault()
+55
View File
@@ -10,10 +10,12 @@
#include <QUrl>
#include "configfile.h"
#include "managedsettingstestutils.h"
#include "theme.h"
#include "urischemehandler.h"
using namespace OCC;
using namespace Qt::StringLiterals;
Q_DECLARE_METATYPE(OCC::UriSchemeHandler::Action)
@@ -27,6 +29,19 @@ private Q_SLOTS:
QStandardPaths::setTestModeEnabled(true);
}
// Keeps tests off the device policy of the machine running them.
void init()
{
ConfigFile::setDeviceSourcesFactory([] {
return std::vector<std::unique_ptr<SettingSource>>{};
});
}
void cleanup()
{
ConfigFile::setDeviceSourcesFactory({});
}
void parseUri_data()
{
QTest::addColumn<QUrl>("url");
@@ -170,6 +185,46 @@ private Q_SLOTS:
QVERIFY(!rejectedResult.error.isEmpty());
}
void parseUriRestrictsOnlyForLockedManagedServerOverride_data()
{
QTest::addColumn<bool>("enforced");
QTest::newRow("device default") << false;
QTest::newRow("device policy") << true;
}
void parseUriRestrictsOnlyForLockedManagedServerOverride()
{
QFETCH(bool, enforced);
ConfigFile cfg;
auto theme = Theme::instance();
const auto previousOverrideServerUrl = theme->overrideServerUrl();
const auto previousForceOverrideServerUrl = theme->forceOverrideServerUrl();
const auto restoreTheme = qScopeGuard([theme, previousOverrideServerUrl, previousForceOverrideServerUrl] {
theme->setOverrideServerUrl(previousOverrideServerUrl);
theme->setForceOverrideServerUrl(previousForceOverrideServerUrl);
});
cfg.clearOverrideServerUrl();
theme->setOverrideServerUrl(QString{});
theme->setForceOverrideServerUrl(false);
ConfigFile::setDeviceSourcesFactory([enforced] {
std::vector<std::unique_ptr<SettingSource>> sources;
sources.push_back(std::make_unique<MapSource>(enforced ? SettingSourceType::PlatformPolicy : SettingSourceType::PlatformDefault,
enforced ? EnforcementState::Enforced : EnforcementState::NotEnforced,
enforced ? 200 : 20,
QVariantMap{{u"overrideServerUrl"_s, u"https://configured.example.com"_s}}));
return sources;
});
const auto configuredResult = UriSchemeHandler::parseUri(QUrl(u"nc://login/server:https://configured.example.com"_s));
QCOMPARE(configuredResult.action, UriSchemeHandler::Action::Login);
const auto otherResult = UriSchemeHandler::parseUri(QUrl(u"nc://login/server:https://unconfigured.example.com"_s));
QCOMPARE(otherResult.action, enforced ? UriSchemeHandler::Action::Invalid : UriSchemeHandler::Action::Login);
}
void parseUriHonoursMultipleServerOverrides()
{
auto theme = Theme::instance();