Commit 65fbbf75 authored by Lukas Appelhans's avatar Lukas Appelhans
Browse files

Add permissions test

parent d6a91eee
......@@ -307,19 +307,13 @@ bool removeFile(const QString &file)
Permissions permissionsOfPath(const QString &path)
{
//NOTE: Don't EVER put a qDebug() in here, it will let akabei freeze at the start because of our heavy mutexing
struct stat results;
stat(path.toUtf8().data(), &results);
mode_t permissions = results.st_mode;
__uid_t uid = results.st_uid;
__gid_t gid = results.st_gid;
Permissions perm = NoPermission;
if (((permissions & S_IWUSR) && (uid == getuid())) || ((permissions & S_IWGRP) && (gid == getgid())) || permissions & S_IWOTH) {
QFileInfo file(path);
if (file.isWritable()) {
perm = perm | WritePermission;
}
if (((permissions & S_IRUSR) && (uid == getuid())) || ((permissions & S_IRGRP) && (gid == getgid())) || permissions & S_IROTH) {
if (file.isReadable()) {
perm = perm | ReadPermission;
}
return perm;
......
......@@ -31,10 +31,10 @@ class Delta;
namespace Helpers
{
enum Permission {
ReadWritePermission = 0x03,
WritePermission = 0x02,
NoPermission = 0x00,
ReadPermission = 0x01,
NoPermission = 0x00
WritePermission = 0x02,
ReadWritePermission = 0x03
};
Q_DECLARE_FLAGS(Permissions, Permission);
QByteArray md5sum(const QByteArray &data);
......
......@@ -122,5 +122,17 @@ if("${CMAKE_BUILD_TYPE}" MATCHES "^[Dd]ebug[Ff]ull$")
target_link_libraries(akabei_polkit_sqliteconnection_test ${QT_QTTEST_LIBRARY} akabeicore)
add_test(akabei_polkit_sqliteconnection_test akabei_polkit_sqliteconnection_test)
#Permissions test
set(akabei_permissions_test_SRCS
akabeipermissionstest.cpp
)
qt4_wrap_cpp(akabei_permissions_test_MOC_SRCS akabeipermissionstest.h)
add_executable(akabei_permissions_test ${akabei_permissions_test_SRCS} ${akabei_permissions_test_MOC_SRCS})
target_link_libraries(akabei_permissions_test ${QT_QTTEST_LIBRARY} akabeicore)
add_test(akabei_permissions_test akabei_permissions_test)
endif("${CMAKE_BUILD_TYPE}" MATCHES "^[Dd]ebug[Ff]ull$")
/* This file is part of the Chakra project
Copyright (C) 2013 Lukas Appelhans
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#include "akabeipermissionstest.h"
#include "akabeihelpers.h"
#include <QTest>
#include <QDebug>
#include <QDir>
AkabeiPermissionsTest::AkabeiPermissionsTest(QObject* parent): QObject(parent)
{
}
AkabeiPermissionsTest::~AkabeiPermissionsTest()
{
}
void AkabeiPermissionsTest::test()
{
QWARN("This will test permissions on your system!");
QVERIFY2(Akabei::Helpers::permissionsOfPath("/").testFlag(Akabei::Helpers::ReadPermission), "We don't have read permission in '/'!");
QVERIFY2(!Akabei::Helpers::permissionsOfPath("/").testFlag(Akabei::Helpers::WritePermission), "We have write permission in '/'!");
QVERIFY2(Akabei::Helpers::permissionsOfPath(QDir::homePath()).testFlag(Akabei::Helpers::WritePermission), "We don't have write permission in our home dir!");
QVERIFY2(Akabei::Helpers::permissionsOfPath(QDir::homePath()).testFlag(Akabei::Helpers::ReadPermission), "We don't have read permission in our home dir!");
}
QTEST_MAIN(AkabeiPermissionsTest)
/* This file is part of the Chakra project
Copyright (C) 2013 Lukas Appelhans
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#ifndef AKABEIPERMISSIONSTEST_H
#define AKABEIPERMISSIONSTEST_H
#include <QObject>
class AkabeiPermissionsTest : public QObject
{
Q_OBJECT
public:
explicit AkabeiPermissionsTest(QObject* parent = 0);
virtual ~AkabeiPermissionsTest();
private slots:
void test();
};
#endif // AKABEIPERMISSIONSTEST_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment