From b0a3e4276e8318475c39c2b7b4b5bc4040dcd19e Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Sun, 26 Sep 2021 18:47:44 +0200 Subject: Create enum to to authorize common keys By using an enum we have a central place to provide docs for the most common actions/restrictions. Also consumers can pass in type-safe enum values instead of potentially undocumented strings that might contain typos. Also it is better documents is a value is supposed to be authorized using KAuthorized::authorize or KAuthorized::authorizeAction, in the case of "shell_access" this was mixed up from time to time. Considering that we do not want the parameter for the methods to become too long I have deliberately decided against using `enum class`. Also we don't have and usecases for the binary operators in combination with the newly added enums. Task: https://phabricator.kde.org/T11948 --- autotests/kconfigtest.cpp | 13 +++++++++++++ autotests/kconfigtest.h | 1 + 2 files changed, 14 insertions(+) (limited to 'autotests') diff --git a/autotests/kconfigtest.cpp b/autotests/kconfigtest.cpp index 00e7bbf0..9f88e67b 100644 --- a/autotests/kconfigtest.cpp +++ b/autotests/kconfigtest.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -2071,6 +2072,18 @@ void KConfigTest::testNotify() QCOMPARE(otherWatcherSpy[0][1].value(), QByteArrayList({"someGlobalEntry"})); } +void KConfigTest::testKAuthorizeEnums() +{ + KSharedConfig::Ptr config = KSharedConfig::openConfig(); + KConfigGroup actionRestrictions = config->group("KDE Action Restrictions"); + actionRestrictions.writeEntry("shell_access", false); + actionRestrictions.writeEntry("action/open_with", false); + + QVERIFY(!KAuthorized::authorize(KAuthorized::SHELL_ACCESS)); + QVERIFY(!KAuthorized::authorizeAction(KAuthorized::OPEN_WITH)); + actionRestrictions.deleteGroup(); +} + void KConfigTest::testKdeglobalsVsDefault() { // Add testRestore key with global value in kdeglobals diff --git a/autotests/kconfigtest.h b/autotests/kconfigtest.h index f716bd70..cdc94366 100644 --- a/autotests/kconfigtest.h +++ b/autotests/kconfigtest.h @@ -82,6 +82,7 @@ private Q_SLOTS: void testNewlines(); void testXdgListEntry(); void testNotify(); + void testKAuthorizeEnums(); void testThreads(); -- cgit v1.2.1