aboutsummaryrefslogtreecommitdiff
path: root/autotests/kdesktopfiletest.cpp
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2021-11-29 14:38:17 +0100
committerAlbert Astals Cid <aacid@kde.org>2021-12-03 22:02:16 +0000
commitdcc6e03840d0c80068cd5e838c62f60a83abcc9d (patch)
tree3c2a6acf4606dd5a083973b33b42291b6c4e0894 /autotests/kdesktopfiletest.cpp
parent202b23cdbfba2bacd8dde7ffb5b8ca26274df58a (diff)
downloadkconfig-dcc6e03840d0c80068cd5e838c62f60a83abcc9d.tar.gz
kconfig-dcc6e03840d0c80068cd5e838c62f60a83abcc9d.tar.bz2
Fix KDesktopFileTest::testIsAuthorizedDesktopFile running on gitlab CI
Diffstat (limited to 'autotests/kdesktopfiletest.cpp')
-rw-r--r--autotests/kdesktopfiletest.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/autotests/kdesktopfiletest.cpp b/autotests/kdesktopfiletest.cpp
index b8235606..efbbb244 100644
--- a/autotests/kdesktopfiletest.cpp
+++ b/autotests/kdesktopfiletest.cpp
@@ -13,6 +13,10 @@
#include <QTest>
+#if defined(Q_OS_UNIX)
+#include <unistd.h>
+#endif
+
QTEST_MAIN(KDesktopFileTest)
void KDesktopFileTest::initTestCase()
@@ -199,6 +203,24 @@ void KDesktopFileTest::testIsAuthorizedDesktopFile()
"\n";
file.close();
QVERIFY(QFile::exists(fileName));
+
+#if defined(Q_OS_UNIX)
+ // Try to fix test failing in docker running as root
+ const QFileInfo entryInfo(fileName);
+ if (entryInfo.ownerId() == 0) {
+ // try to find a valid user/group combination
+ for (int i = 1; i < 100; ++i) {
+ if (chown(fileName.toLocal8Bit().constData(), i, i) == 0) {
+ break;
+ }
+ }
+ const QFileInfo entryInfo1(fileName);
+ if (entryInfo1.ownerId() == 0) {
+ QEXPECT_FAIL("", "Running test as root and could not find a non root user to change the ownership of the file too", Continue);
+ }
+ }
+#endif
+
QVERIFY(!KDesktopFile::isAuthorizedDesktopFile(fileName));
const QString installedFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("/kservices5/http_cache_cleaner.desktop"));