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 <teemu.holappa@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
9b52cfd64c
commit
a1e94bcfbb
@ -1,5 +1,7 @@
|
|||||||
CONFIG += testcase
|
CONFIG += testcase
|
||||||
TARGET = tst_qstandardpaths
|
TARGET = tst_qstandardpaths
|
||||||
QT = core testlib
|
QT = core testlib
|
||||||
|
INCLUDEPATH += ../../../../shared/
|
||||||
|
HEADERS += ../../../../shared/emulationdetector.h
|
||||||
SOURCES = tst_qstandardpaths.cpp
|
SOURCES = tst_qstandardpaths.cpp
|
||||||
TESTDATA += tst_qstandardpaths.cpp qstandardpaths.pro
|
TESTDATA += tst_qstandardpaths.cpp qstandardpaths.pro
|
||||||
|
@ -46,6 +46,8 @@
|
|||||||
#define Q_XDG_PLATFORM
|
#define Q_XDG_PLATFORM
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "emulationdetector.h"
|
||||||
|
|
||||||
// Update this when adding new enum values; update enumNames too
|
// Update this when adding new enum values; update enumNames too
|
||||||
static const int MaxStandardLocation = QStandardPaths::AppConfigLocation;
|
static const int MaxStandardLocation = QStandardPaths::AppConfigLocation;
|
||||||
|
|
||||||
@ -485,14 +487,24 @@ void tst_qstandardpaths::testCustomRuntimeDirectory()
|
|||||||
EnvVarRestorer restorer;
|
EnvVarRestorer restorer;
|
||||||
|
|
||||||
// When $XDG_RUNTIME_DIR points to a directory with wrong ownership, QStandardPaths should warn
|
// 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
|
// It's very unlikely that /tmp is 0600 or that we can chmod it
|
||||||
// The call below outputs
|
// The call below outputs
|
||||||
// "QStandardPaths: wrong ownership on runtime directory /tmp, 0 instead of $UID"
|
// "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.
|
// but we can't reliably expect that it's owned by uid 0, I think.
|
||||||
const uid_t uid = geteuid();
|
const uid_t uid = geteuid();
|
||||||
QTest::ignoreMessage(QtWarningMsg,
|
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);
|
const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
|
||||||
QVERIFY2(runtimeDir.isEmpty(), qPrintable(runtimeDir));
|
QVERIFY2(runtimeDir.isEmpty(), qPrintable(runtimeDir));
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
CONFIG += testcase
|
CONFIG += testcase
|
||||||
TARGET = tst_qtemporarydir
|
TARGET = tst_qtemporarydir
|
||||||
SOURCES += tst_qtemporarydir.cpp
|
SOURCES += tst_qtemporarydir.cpp
|
||||||
|
INCLUDEPATH += ../../../../shared/
|
||||||
|
HEADERS += ../../../../shared/emulationdetector.h
|
||||||
|
|
||||||
QT = core testlib
|
QT = core testlib
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include "emulationdetector.h"
|
||||||
|
|
||||||
class tst_QTemporaryDir : public QObject
|
class tst_QTemporaryDir : public QObject
|
||||||
{
|
{
|
||||||
@ -316,6 +317,13 @@ void tst_QTemporaryDir::nonWritableCurrentDir()
|
|||||||
|
|
||||||
const QFileInfo nonWritableDirFi = QFileInfo(QLatin1String(nonWritableDir));
|
const QFileInfo nonWritableDirFi = QFileInfo(QLatin1String(nonWritableDir));
|
||||||
QVERIFY(nonWritableDirFi.isDir());
|
QVERIFY(nonWritableDirFi.isDir());
|
||||||
|
|
||||||
|
if (EmulationDetector::isRunningArmOnX86()) {
|
||||||
|
if (nonWritableDirFi.ownerId() == ::geteuid()) {
|
||||||
|
QSKIP("Sysroot directories are owned by the current user");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QVERIFY(!nonWritableDirFi.isWritable());
|
QVERIFY(!nonWritableDirFi.isWritable());
|
||||||
|
|
||||||
ChdirOnReturn cor(QDir::currentPath());
|
ChdirOnReturn cor(QDir::currentPath());
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
CONFIG += testcase
|
CONFIG += testcase
|
||||||
testcase.timeout = 600 # this test is slow
|
testcase.timeout = 600 # this test is slow
|
||||||
CONFIG -= debug_and_release_target
|
CONFIG -= debug_and_release_target
|
||||||
|
INCLUDEPATH += ../../../../../shared/
|
||||||
|
HEADERS += ../../../../../shared/emulationdetector.h
|
||||||
SOURCES += ../tst_qnetworkreply.cpp
|
SOURCES += ../tst_qnetworkreply.cpp
|
||||||
TARGET = ../tst_qnetworkreply
|
TARGET = ../tst_qnetworkreply
|
||||||
|
|
||||||
|
@ -96,6 +96,8 @@ Q_DECLARE_METATYPE(QAuthenticator*)
|
|||||||
Q_DECLARE_METATYPE(QNetworkProxyQuery)
|
Q_DECLARE_METATYPE(QNetworkProxyQuery)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "emulationdetector.h"
|
||||||
|
|
||||||
typedef QSharedPointer<QNetworkReply> QNetworkReplyPtr;
|
typedef QSharedPointer<QNetworkReply> QNetworkReplyPtr;
|
||||||
|
|
||||||
class MyCookieJar;
|
class MyCookieJar;
|
||||||
@ -135,6 +137,7 @@ class tst_QNetworkReply: public QObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const QByteArray httpEmpty200Response;
|
static const QByteArray httpEmpty200Response;
|
||||||
|
static const QString filePermissionFileName;
|
||||||
|
|
||||||
QEventLoop *loop;
|
QEventLoop *loop;
|
||||||
enum RunSimpleRequestReturn { Timeout = 0, Success, Failure };
|
enum RunSimpleRequestReturn { Timeout = 0, Success, Failure };
|
||||||
@ -499,6 +502,8 @@ private:
|
|||||||
|
|
||||||
const QByteArray tst_QNetworkReply::httpEmpty200Response =
|
const QByteArray tst_QNetworkReply::httpEmpty200Response =
|
||||||
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n";
|
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n";
|
||||||
|
const QString tst_QNetworkReply::filePermissionFileName = "/etc/shadow";
|
||||||
|
|
||||||
bool tst_QNetworkReply::seedCreated = false;
|
bool tst_QNetworkReply::seedCreated = false;
|
||||||
|
|
||||||
#define RUN_REQUEST(call) \
|
#define RUN_REQUEST(call) \
|
||||||
@ -1915,8 +1920,10 @@ void tst_QNetworkReply::getErrors_data()
|
|||||||
QTest::newRow("file-is-wronly") << QUrl::fromLocalFile(wronlyFileName).toString()
|
QTest::newRow("file-is-wronly") << QUrl::fromLocalFile(wronlyFileName).toString()
|
||||||
<< int(QNetworkReply::ContentAccessDenied) << 0 << true;
|
<< int(QNetworkReply::ContentAccessDenied) << 0 << true;
|
||||||
#endif
|
#endif
|
||||||
if (QFile::exists("/etc/shadow"))
|
|
||||||
QTest::newRow("file-permissions") << "file:/etc/shadow"
|
|
||||||
|
if (QFile::exists(filePermissionFileName))
|
||||||
|
QTest::newRow("file-permissions") << "file:" + filePermissionFileName
|
||||||
<< int(QNetworkReply::ContentAccessDenied) << 0 << true;
|
<< int(QNetworkReply::ContentAccessDenied) << 0 << true;
|
||||||
|
|
||||||
// ftp: errors
|
// ftp: errors
|
||||||
@ -1952,6 +1959,15 @@ void tst_QNetworkReply::getErrors()
|
|||||||
(qstrcmp(QTest::currentDataTag(), "file-permissions") == 0)) {
|
(qstrcmp(QTest::currentDataTag(), "file-permissions") == 0)) {
|
||||||
if (::getuid() == 0)
|
if (::getuid() == 0)
|
||||||
QSKIP("Running this test as root doesn't make sense");
|
QSKIP("Running this test as root doesn't make sense");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EmulationDetector::isRunningArmOnX86()
|
||||||
|
&& qstrcmp(QTest::currentDataTag(), "file-permissions") == 0) {
|
||||||
|
QFileInfo filePermissionFile = QFileInfo(filePermissionFileName.toLatin1());
|
||||||
|
if (filePermissionFile.ownerId() == ::geteuid()) {
|
||||||
|
QSKIP("Sysroot directories are owned by the current user");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user