Compare commits

...
Author SHA1 Message Date
Rello 03ed776d98 fix(test): materialize user agent branding as a byte array
Use QByteArray::append to avoid passing a QStringBuilder expression to QByteArray::contains.

Signed-off-by: Rello <[email protected]>
Assisted-by: Codex:GPT-5
2026-11-06 16:07:30 +01:00
Rello 492ae367dd fix(network): encode the user agent as UTF-8
Preserve non-ASCII application names in the User-Agent header used by login flow v2. Add regression coverage for ASCII and Unicode branding.

Signed-off-by: Rello <[email protected]>
Assisted-by: Codex:GPT-5
2026-11-06 15:34:27 +01:00
2 changed files with 34 additions and 7 deletions

No files matched your search

+7 -7
View File
@@ -156,13 +156,13 @@ QByteArray Utility::userAgentString()
{
return QStringLiteral("Mozilla/5.0 (%1) mirall/%2 (%3, %4-%5 ClientArchitecture: %6 OsArchitecture: %7)")
.arg(platform(),
QStringLiteral(MIRALL_VERSION_STRING),
qApp->applicationName(),
QSysInfo::productType(),
QSysInfo::kernelVersion(),
QSysInfo::buildCpuArchitecture(),
QSysInfo::currentCpuArchitecture())
.toLatin1();
QStringLiteral(MIRALL_VERSION_STRING),
qApp->applicationName(),
QSysInfo::productType(),
QSysInfo::kernelVersion(),
QSysInfo::buildCpuArchitecture(),
QSysInfo::currentCpuArchitecture())
.toUtf8();
}
QByteArray Utility::friendlyUserAgentString()
+27
View File
@@ -34,6 +34,33 @@ private Q_SLOTS:
QStandardPaths::setTestModeEnabled(true);
}
void testUserAgentString_data()
{
using namespace Qt::StringLiterals;
QTest::addColumn<QString>("applicationName");
QTest::addColumn<QByteArray>("expectedName");
QTest::newRow("ascii") << u"Nextcloud"_s << QByteArray("Nextcloud");
QTest::newRow("latin1") << u"Cl\u00f8ud"_s << QByteArray("Cl\xc3\xb8ud");
QTest::newRow("outside-latin1") << u"Cloud \u96f2"_s << QByteArray("Cloud \xe9\x9b\xb2");
QTest::newRow("supplementary") << u"Cloud \U0001f600"_s << QByteArray("Cloud \xf0\x9f\x98\x80");
}
void testUserAgentString()
{
QFETCH(QString, applicationName);
QFETCH(QByteArray, expectedName);
const auto previousName = QCoreApplication::applicationName();
QCoreApplication::setApplicationName(applicationName);
const auto userAgent = userAgentString();
QCoreApplication::setApplicationName(previousName);
const auto expectedBranding = QByteArray("(").append(expectedName).append(", ");
QVERIFY(userAgent.contains(expectedBranding));
QCOMPARE(QString::fromUtf8(userAgent).toUtf8(), userAgent);
}
void testFormatFingerprint()
{
QVERIFY2(formatFingerprint("68ac906495480a3404beee4874ed853a037a7a8f")