diff --git a/autotests/SetupActionTest.cpp b/autotests/SetupActionTest.cpp --- a/autotests/SetupActionTest.cpp +++ b/autotests/SetupActionTest.cpp @@ -40,6 +40,7 @@ void testBasicActionProperties(); void testUserAuthorization(); void testAuthorizationFail(); + void testRevokeAuthorization(); void cleanup() {} void cleanupTestCase() {} @@ -148,5 +149,28 @@ QVERIFY(job->data().isEmpty()); } +void SetupActionTest::testRevokeAuthorization() +{ + emit changeCapabilities(KAuth::AuthBackend::CheckActionExistenceCapability | KAuth::AuthBackend::AuthorizeFromClientCapability); + + KAuth::Action action(QLatin1String("always.authorized"), QLatin1String("details")); + QVERIFY(action.isValid()); + + QCOMPARE(action.status(), KAuth::Action::AuthorizedStatus); + KAuth::ExecuteJob *job = action.execute(); + QVERIFY(job->exec()); + QVERIFY(!job->error()); + + emit changeCapabilities(KAuth::AuthBackend::CheckActionExistenceCapability); + + QVERIFY(action.revokeAuthorization()); + QCOMPARE(action.status(), KAuth::Action::AuthRequiredStatus); + job = action.execute(); + QVERIFY(!job->exec()); + QCOMPARE(job->error(), (int)KAuth::ActionReply::BackendError); + + QVERIFY(job->data().isEmpty()); +} + QTEST_MAIN(SetupActionTest) #include "SetupActionTest.moc" diff --git a/autotests/TestBackend.h b/autotests/TestBackend.h --- a/autotests/TestBackend.h +++ b/autotests/TestBackend.h @@ -41,6 +41,7 @@ QByteArray callerID() const Q_DECL_OVERRIDE; bool isCallerAuthorized(const QString &action, QByteArray callerID) Q_DECL_OVERRIDE; bool actionExists(const QString &action) Q_DECL_OVERRIDE; + bool revokeTemporaryAuthorization(const QString &action) Q_DECL_OVERRIDE; public Q_SLOTS: void setNewCapabilities(KAuth::AuthBackend::Capabilities capabilities); diff --git a/autotests/TestBackend.cpp b/autotests/TestBackend.cpp --- a/autotests/TestBackend.cpp +++ b/autotests/TestBackend.cpp @@ -117,4 +117,14 @@ return true; } +bool TestBackend::revokeTemporaryAuthorization(const QString &action) +{ + if (m_actionStatuses.value(action) == Action::AuthorizedStatus) { + m_actionStatuses.insert(action, Action::AuthRequiredStatus); + return true; + } + + return false; +} + } // namespace Auth diff --git a/src/AuthBackend.h b/src/AuthBackend.h --- a/src/AuthBackend.h +++ b/src/AuthBackend.h @@ -59,6 +59,7 @@ virtual ExtraCallerIDVerificationMethod extraCallerIDVerificationMethod() const; virtual bool isCallerAuthorized(const QString &action, QByteArray callerID) = 0; virtual bool actionExists(const QString &action); + virtual bool revokeTemporaryAuthorization(const QString &action); Capabilities capabilities() const; diff --git a/src/AuthBackend.cpp b/src/AuthBackend.cpp --- a/src/AuthBackend.cpp +++ b/src/AuthBackend.cpp @@ -71,5 +71,11 @@ Q_UNUSED(parent) } +bool AuthBackend::revokeTemporaryAuthorization(const QString &action) +{ + Q_UNUSED(action) + return false; +} + } //namespace KAuth diff --git a/src/kauthaction.h b/src/kauthaction.h --- a/src/kauthaction.h +++ b/src/kauthaction.h @@ -344,6 +344,15 @@ AuthStatus status() const; /** + * @brief Revokes temporary authorization of an action + * + * This method requests the authorization backend to revoke action's temporary authorization. + * + * @return Whether authorization was successfully revoked + */ + bool revokeAuthorization() const; + + /** * @brief Get the job object used to execute the action * * @return The KJob::ExecuteJob object to be used to run the action. diff --git a/src/kauthaction.cpp b/src/kauthaction.cpp --- a/src/kauthaction.cpp +++ b/src/kauthaction.cpp @@ -199,6 +199,15 @@ return BackendsManager::authBackend()->actionStatus(d->name); } +bool Action::revokeAuthorization() const +{ + if (!isValid()) { + return false; + } + + return BackendsManager::authBackend()->revokeTemporaryAuthorization(d->name); +} + ExecuteJob *Action::execute(ExecutionMode mode) { return new ExecuteJob(*this, mode, nullptr);