summaryrefslogtreecommitdiffstats
path: root/tests/test_check_authorization.cpp
blob: 3616206cbc2b6ff852d024ee3ada53c14b60a414 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

#include <tqstring.h>
#include "core/polkit-tqt-authority.h"

#define TEST_PASSED 0
#define TEST_FAILED 1

using namespace PolkitTQt;

int main(void)
{
  // This needs the file org.tqt.policykit.examples.policy from examples to be installed
  UnixProcessSubject process(getpid());
  Authority::Result result;
  // Check if this method returns good authorization results
  Authority *authority = Authority::instance();
  result = authority->checkAuthorizationSync("org.tqt.policykit.examples.kick", process, Authority::None);
  if (result != Authority::No)
  {
    return TEST_FAILED;
  }
  if (authority->hasError())
  {
    return TEST_FAILED;
  }
  result = authority->checkAuthorizationSync("org.tqt.policykit.examples.cry", process, Authority::None);
  if (result != Authority::Yes)
  {
    return TEST_FAILED;
  }
  if (authority->hasError())
  {
    return TEST_FAILED;
  }
  result = authority->checkAuthorizationSync("org.tqt.policykit.examples.bleed", process, Authority::None);
  if (result != Authority::Challenge)
  {
    return TEST_FAILED;
  }
  if (authority->hasError())
  {
    return TEST_FAILED;
  }

  // Check if it can cancel user authentication dialog
  authority->checkAuthorization("org.tqt.policykit.examples.bleed", process, Authority::AllowUserInteraction);
  // Show it for second
  sleep(1);
  // And now kill it
  authority->checkAuthorizationCancel();
  if (authority->hasError())
  {
    return TEST_FAILED;
  }
  // But how to test if it was successful?
  tqWarning("You should see an authentication dialog for a short period.");

  return TEST_PASSED;
}