aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_config.cpp
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-15 11:51:34 +0200
committerDanilo M. <danix@danix.xyz>2026-08-15 11:51:34 +0200
commit749600c47f92c97fa50556fbb738d3c3055a9ab4 (patch)
treebfa9e39b6492c80c5e56f2bce6af7142baf67ec1 /tests/test_config.cpp
parentd4e4cebbefdce5f575954594461dc707492b2dd8 (diff)
downloadqtmaildir-749600c47f92c97fa50556fbb738d3c3055a9ab4.tar.gz
qtmaildir-749600c47f92c97fa50556fbb738d3c3055a9ab4.zip
test(config): pin the dotted account key for startup_account
startup_account matches Account::key, the [account.<key>] suffix, and not the mbsync channel. The two genuinely differ in a real setup: a section key may carry dots that the channel does not. The dot is the part worth pinning. QSettings treats "/" as a group separator, which is why account sections use a dot at all; a dot INSIDE the key is a different case, and a silent mismatch would report "not a configured account" and quietly start on All accounts. Verified against a standalone probe before this test was written. The second half asserts the channel is rejected, so the two names cannot be interchangeable in one direction only.
Diffstat (limited to 'tests/test_config.cpp')
-rw-r--r--tests/test_config.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test_config.cpp b/tests/test_config.cpp
index 62913d7..e2dffb0 100644
--- a/tests/test_config.cpp
+++ b/tests/test_config.cpp
@@ -97,6 +97,7 @@ private slots:
void allSentQueryJoinsEveryConfiguredAccount();
void aStoredGeneratedQueryIsUnpinnedNotDropped();
void theStartupAccountIsReadAndValidated();
+ void theStartupAccountTakesTheKeyNotTheSyncChannel();
void theStartupQueryCanNameABuiltinFilter();
void theStartupQueryPrefersASavedQueryOverAFilterOfTheSameName();
void anUnmatchedStartupQueryFallsBackToAFilterNotAStrayQuery();
@@ -1102,6 +1103,53 @@ void TestConfig::theStartupAccountIsReadAndValidated()
QCOMPARE(wrong.problems().size(), 1);
}
+void TestConfig::theStartupAccountTakesTheKeyNotTheSyncChannel()
+{
+ // Two names exist for one account and they genuinely differ in a real
+ // setup: a section key may carry dots that the mbsync channel does not.
+ // startup_account is the KEY, matched against the [account.<key>] suffix.
+ //
+ // The dot is the part worth pinning. QSettings treats "/" as a group
+ // separator, which is why account sections use a dot in the first place; a
+ // dot INSIDE the key is a different case, and a silent mismatch here would
+ // report "not a configured account" and quietly start on All accounts.
+ QTemporaryDir dir;
+ Config config;
+ config.load(writeIni(dir, QStringLiteral(
+ "[general]\n"
+ "startup_account=provider-work.mailbox\n"
+ "\n"
+ "[account.provider-work.mailbox]\n"
+ "maildir=provider-work.mailbox\n"
+ "channel=provider-workmailbox\n")));
+
+ QCOMPARE(config.accounts().size(), 1);
+ QCOMPARE(config.accounts().constFirst().key,
+ QStringLiteral("provider-work.mailbox"));
+ QCOMPARE(config.accounts().constFirst().syncChannel(),
+ QStringLiteral("provider-workmailbox"));
+
+ QCOMPARE(config.startupAccount(),
+ QStringLiteral("provider-work.mailbox"));
+ QVERIFY(config.problems().isEmpty());
+
+ // And the channel is NOT accepted, or the two names would be
+ // interchangeable in one direction only, which is worse than either rule.
+ QTemporaryDir other;
+ Config byChannel;
+ byChannel.load(writeIni(other, QStringLiteral(
+ "[general]\n"
+ "startup_account=provider-workmailbox\n"
+ "\n"
+ "[account.provider-work.mailbox]\n"
+ "maildir=provider-work.mailbox\n"
+ "channel=provider-workmailbox\n")));
+
+ QVERIFY2(byChannel.startupAccount().isEmpty(),
+ "the sync channel was accepted as an account key");
+ QCOMPARE(byChannel.problems().size(), 1);
+}
+
void TestConfig::theStartupQueryCanNameABuiltinFilter()
{
// The defect: startup_query searched the SAVED queries only. A user whose