From dfc2a4a537a053b2c9157d48090637a0b77c4485 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 18 Feb 2017 09:41:30 +0100 Subject: QLoggingRegistry: remove rules vector It only contained a concatenation of the individual rule sets, probably to fix their order in a central place, as well as simplifying iteration in defaultCategoryFilter(). Fix these two issues differently, but introducing a RuleSet enum that lists rule sets in the order in which they should be applied by defaultCategoryFilter(), and turn individual rule sets vectors into a C array of vectors. This enables two nested loops in defaultCategoryFilter to replace the one loop over 'rules'. Apart from building up 'rules' in updateRules(), this was the only access to that member. That leaves updateRules() with just the task of running defaultCategoryFilter() on the new rule sets. Consequently, a call to updateRules() can now replace the identical loop in installFilter(). Performance should not suffer. Iterating over a fixed-size array of vectors is hardly any slower than iterating over a single vector, and while the construction of 'rules' was probably a one-off task in most programs, this way of keeping the rules also saves memory because rules are not kept in two different vectors. It is also more maintainable, of course. Change-Id: Ibc132d096c8137dd02b034752646212e51208637 Reviewed-by: Kai Koehne Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../io/qloggingregistry/tst_qloggingregistry.cpp | 26 +++++++++------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'tests/auto/corelib/io') diff --git a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp index 0a74dc64c0..1643eed3d2 100644 --- a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp +++ b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp @@ -202,18 +202,15 @@ private slots: QLoggingRegistry registry; registry.init(); - QCOMPARE(registry.apiRules.size(), 0); - QCOMPARE(registry.configRules.size(), 0); - QCOMPARE(registry.envRules.size(), 1); - - QCOMPARE(registry.rules.size(), 1); + QCOMPARE(registry.ruleSets[QLoggingRegistry::ApiRules].size(), 0); + QCOMPARE(registry.ruleSets[QLoggingRegistry::ConfigRules].size(), 0); + QCOMPARE(registry.ruleSets[QLoggingRegistry::EnvironmentRules].size(), 1); // check that QT_LOGGING_RULES take precedence qputenv("QT_LOGGING_RULES", "Digia.*=true"); registry.init(); - QCOMPARE(registry.envRules.size(), 2); - QCOMPARE(registry.envRules.at(1).enabled, true); - QCOMPARE(registry.rules.size(), 2); + QCOMPARE(registry.ruleSets[QLoggingRegistry::EnvironmentRules].size(), 2); + QCOMPARE(registry.ruleSets[QLoggingRegistry::EnvironmentRules].at(1).enabled, true); } void QLoggingRegistry_config() @@ -238,7 +235,7 @@ private slots: QLoggingRegistry registry; registry.init(); - QCOMPARE(registry.configRules.size(), 1); + QCOMPARE(registry.ruleSets[QLoggingRegistry::ConfigRules].size(), 1); // remove file again QVERIFY(file.remove()); @@ -260,10 +257,9 @@ private slots: QLoggingRegistry *registry = QLoggingRegistry::instance(); // empty all rules , check default - registry->rules.clear(); - registry->apiRules.clear(); - registry->configRules.clear(); - registry->envRules.clear(); + registry->ruleSets[QLoggingRegistry::ApiRules].clear(); + registry->ruleSets[QLoggingRegistry::ConfigRules].clear(); + registry->ruleSets[QLoggingRegistry::EnvironmentRules].clear(); registry->updateRules(); QVERIFY(cat.isWarningEnabled()); @@ -271,7 +267,7 @@ private slots: // set Config rule QLoggingSettingsParser parser; parser.setContent("[Rules]\nDigia.*=false"); - registry->configRules=parser.rules(); + registry->ruleSets[QLoggingRegistry::ConfigRules] = parser.rules(); registry->updateRules(); QVERIFY(!cat.isWarningEnabled()); @@ -283,7 +279,7 @@ private slots: // set Env rule, should overwrite Config one parser.setContent("Digia.*=false"); - registry->envRules=parser.rules(); + registry->ruleSets[QLoggingRegistry::EnvironmentRules] = parser.rules(); registry->updateRules(); QVERIFY(!cat.isWarningEnabled()); -- cgit v1.2.3 From 21dd5d314a75c09250448e5d59dfb9af88c0f7d5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 23 Apr 2017 22:43:18 -0300 Subject: QUrl: fix IDN whitelist checking when the TLD is in Unicode The whitelist is kept in ACE form, so if the TLD came in Unicode, we need to run ToASCII before we can check the whitelist. This is slightly inefficient because we'll run the same operation later in this domain. Change-Id: Iadfecb6f28984634979dfffd14b831f37b0f4818 Reviewed-by: Lars Knoll Reviewed-by: Florian Bruhin --- tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/auto/corelib/io') diff --git a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp index f5835ec5f4..766338e4f8 100644 --- a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp +++ b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp @@ -670,6 +670,14 @@ void tst_QUrlInternal::ace_testsuite() QCOMPARE(QUrl::fromAce(domain.toLatin1()), fromace + suffix); QCOMPARE(QUrl::fromAce(QUrl::toAce(domain)), unicode + suffix); + QUrl u; + u.setHost(domain); + QVERIFY(u.isValid()); + QCOMPARE(u.host(), unicode + suffix); + QCOMPARE(u.host(QUrl::EncodeUnicode), toace + suffix); + QCOMPARE(u.toEncoded(), "//" + toace.toLatin1() + suffix); + QCOMPARE(u.toDisplayString(), "//" + unicode + suffix); + domain = in + (suffix ? ".troll.No" : ""); QCOMPARE(QString::fromLatin1(QUrl::toAce(domain)), toace + suffix); if (fromace != ".") -- cgit v1.2.3 From 9e2c6899e0a07edf525945a182d2537086441268 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 23 Apr 2017 23:03:58 -0300 Subject: QUrl: fix IDN conversion when the ACE form is invalid We guarded against the Unicode form being invalid and did not produce an encoded form. But we did not guard against proper Punycode sequences that decode to forms that had not passed the proper Nameprep stage. So check for that and, if it fails, just keep the label in the form we found it in (it's valid STD3 anyway). [ChangeLog][QtCore][QUrl] Fixed a bug that caused certain domain names that look like Internationalized Domain Names to become corrupt in decoded forms of QUrl, notably toString() and toDisplayString(). Task-number: QTBUG-60364 Change-Id: Iadfecb6f28984634979dfffd14b833142cca8d0d Reviewed-by: Lars Knoll --- .../corelib/io/qurlinternal/tst_qurlinternal.cpp | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/auto/corelib/io') diff --git a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp index 766338e4f8..bcf6d6c32b 100644 --- a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp +++ b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp @@ -650,6 +650,31 @@ void tst_QUrlInternal::ace_testsuite_data() << "xn--djrptm67aikb.xn--kpry57d" << "." << taiwaneseIDN; + + // violations / invalids + QTest::newRow("invalid-punycode") << "xn--z" << "xn--z" << "xn--z" << "xn--z"; + + // U+00A0 NO-BREAK SPACE encodes to Punycode "6a" + // but it is prohibited and should have caused encoding failure + QTest::newRow("invalid-nameprep-prohibited") << "xn--6a" << "xn--6a" << "xn--6a" << "xn--6a"; + + // U+00AD SOFT HYPHEN between "a" and "b" encodes to Punycode "ab-5da" + // but it should have been removed in the nameprep stage + QTest::newRow("invalid-nameprep-maptonothing") << "xn-ab-5da" << "xn-ab-5da" << "xn-ab-5da" << "xn-ab-5da"; + + // U+00C1 LATIN CAPITAL LETTER A WITH ACUTE encodes to Punycode "4ba" + // but it should have nameprepped to lowercase first + QTest::newRow("invalid-nameprep-uppercase") << "xn--4ba" << "xn--4ba" << "xn--4ba" << "xn--4ba"; + + // U+00B5 MICRO SIGN encodes to Punycode "sba" + // but is should have nameprepped to NFKC U+03BC GREEK SMALL LETTER MU + QTest::newRow("invalid-nameprep-nonnfkc") << "xn--sba" << "xn--sba" << "xn--sba" << "xn--sba"; + + // U+04CF CYRILLIC SMALL LETTER PALOCHKA encodes to "s5a" + // but it's not in RFC 3454's allowed character list (Unicode 3.2) + QTest::newRow("invalid-nameprep-unassigned") << "xn--s5a" << "xn--s5a" << "xn--s5a" << "xn--s5a"; + // same character, see QTBUG-60364 + QTest::newRow("invalid-nameprep-unassigned2") << "xn--80ak6aa92e" << "xn--80ak6aa92e" << "xn--80ak6aa92e" << "xn--80ak6aa92e"; } void tst_QUrlInternal::ace_testsuite() -- cgit v1.2.3 From a1e94bcfbb7b2814340f481b632ebab224eddda5 Mon Sep 17 00:00:00 2001 From: Sami Nurmenniemi Date: Tue, 18 Apr 2017 13:29:04 +0300 Subject: Fix tests that assume system files are owned by root for qemu If QEMU is provided sysroot with QEMU_LD_PREFIX, it opens files from there. If their owner is the current user, testing their access rights based on assumption that they are root fails. Skip the tests in that case similarly as is already done when the tests are run as root. This fixes following tests: - tst_QTemporaryDir::nonWritableCurrentDir - tst_QNetworkReply::getErrors(file-permissions) - tst_qstandardpaths::testCustomRuntimeDirectory Task-number: QTBUG-59966 Change-Id: I972ce37b4b5a7747cdd732a8e4a737ef09cbc6a5 Reviewed-by: Teemu Holappa Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qstandardpaths/qstandardpaths.pro | 2 ++ .../corelib/io/qstandardpaths/tst_qstandardpaths.cpp | 16 ++++++++++++++-- tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro | 2 ++ .../auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp | 8 ++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib/io') diff --git a/tests/auto/corelib/io/qstandardpaths/qstandardpaths.pro b/tests/auto/corelib/io/qstandardpaths/qstandardpaths.pro index c72d9e4fad..9fd7047405 100644 --- a/tests/auto/corelib/io/qstandardpaths/qstandardpaths.pro +++ b/tests/auto/corelib/io/qstandardpaths/qstandardpaths.pro @@ -1,5 +1,7 @@ CONFIG += testcase TARGET = tst_qstandardpaths QT = core testlib +INCLUDEPATH += ../../../../shared/ +HEADERS += ../../../../shared/emulationdetector.h SOURCES = tst_qstandardpaths.cpp TESTDATA += tst_qstandardpaths.cpp qstandardpaths.pro diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 0a00e00d83..3de777653e 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -46,6 +46,8 @@ #define Q_XDG_PLATFORM #endif +#include "emulationdetector.h" + // Update this when adding new enum values; update enumNames too static const int MaxStandardLocation = QStandardPaths::AppConfigLocation; @@ -485,14 +487,24 @@ void tst_qstandardpaths::testCustomRuntimeDirectory() EnvVarRestorer restorer; // When $XDG_RUNTIME_DIR points to a directory with wrong ownership, QStandardPaths should warn - qputenv("XDG_RUNTIME_DIR", QFile::encodeName("/tmp")); + QByteArray rootOwnedFileName = "/tmp"; + if (EmulationDetector::isRunningArmOnX86()) { + // Directory "tmp" under toolchain sysroot is detected by qemu and has same uid as current user. + // Try /opt instead, it might not be located in the sysroot. + QFileInfo rootOwnedFile = QFileInfo(QString::fromLatin1(rootOwnedFileName)); + if (rootOwnedFile.ownerId() == ::geteuid()) { + rootOwnedFileName = "/opt"; + } + } + qputenv("XDG_RUNTIME_DIR", QFile::encodeName(rootOwnedFileName)); + // It's very unlikely that /tmp is 0600 or that we can chmod it // The call below outputs // "QStandardPaths: wrong ownership on runtime directory /tmp, 0 instead of $UID" // but we can't reliably expect that it's owned by uid 0, I think. const uid_t uid = geteuid(); QTest::ignoreMessage(QtWarningMsg, - qPrintable(QString::fromLatin1("QStandardPaths: wrong ownership on runtime directory /tmp, 0 instead of %1").arg(uid))); + qPrintable(QString::fromLatin1("QStandardPaths: wrong ownership on runtime directory " + rootOwnedFileName + ", 0 instead of %1").arg(uid))); const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); QVERIFY2(runtimeDir.isEmpty(), qPrintable(runtimeDir)); diff --git a/tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro b/tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro index 4a69971f78..351e263093 100644 --- a/tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro +++ b/tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro @@ -1,5 +1,7 @@ CONFIG += testcase TARGET = tst_qtemporarydir SOURCES += tst_qtemporarydir.cpp +INCLUDEPATH += ../../../../shared/ +HEADERS += ../../../../shared/emulationdetector.h QT = core testlib diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp index 758bbead84..4bed8d0fd6 100644 --- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp +++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp @@ -42,6 +42,7 @@ # include # include #endif +#include "emulationdetector.h" class tst_QTemporaryDir : public QObject { @@ -316,6 +317,13 @@ void tst_QTemporaryDir::nonWritableCurrentDir() const QFileInfo nonWritableDirFi = QFileInfo(QLatin1String(nonWritableDir)); QVERIFY(nonWritableDirFi.isDir()); + + if (EmulationDetector::isRunningArmOnX86()) { + if (nonWritableDirFi.ownerId() == ::geteuid()) { + QSKIP("Sysroot directories are owned by the current user"); + } + } + QVERIFY(!nonWritableDirFi.isWritable()); ChdirOnReturn cor(QDir::currentPath()); -- cgit v1.2.3