paragraph for gnunet devs that don't know how to use the web
[oweals/gnunet.git] / src / revocation / test_local_revocation.py.in
1 #!@PYTHON@
2 #    This file is part of GNUnet.
3 #    (C) 2010, 2018 Christian Grothoff (and other contributing authors)
4 #
5 #    GNUnet is free software: you can redistribute it and/or modify it
6 #    under the terms of the GNU Affero General Public License as published
7 #    by the Free Software Foundation, either version 3 of the License,
8 #    or (at your option) any later version.
9 #
10 #    GNUnet is distributed in the hope that it will be useful, but
11 #    WITHOUT ANY WARRANTY; without even the implied warranty of
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #    Affero General Public License for more details.
14 #   
15 #    You should have received a copy of the GNU Affero General Public License
16 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18 # Testcase for ego revocation
19 from __future__ import print_function
20 import sys
21 import os
22 import subprocess
23 import re
24 import shutil
25
26 if os.name == 'posix':
27     config = 'gnunet-config'
28     gnunetarm = 'gnunet-arm'
29     ident = 'gnunet-identity'
30     revoc = './gnunet-revocation'
31 elif os.name == 'nt':
32     config = 'gnunet-config.exe'
33     gnunetarm = 'gnunet-arm.exe'
34     ident = 'gnunet-identity.exe'
35     revoc = './gnunet-revocation.exe'
36
37 TEST_CONFIGURATION = "test_revocation.conf"
38 TEST_REVOCATION_EGO = "revoc_test"
39
40 get_clean = subprocess.Popen([config, '-c', TEST_CONFIGURATION, '-s', 'PATHS', '-o', 'GNUNET_HOME', '-f'], stdout=subprocess.PIPE)
41 cleandir, x = get_clean.communicate()
42 cleandir = cleandir.decode("utf-8")
43 cleandir = cleandir.rstrip('\n').rstrip('\r')
44
45 if os.path.isdir(cleandir):
46     shutil.rmtree(cleandir, True)
47
48 res = 0
49 arm = subprocess.Popen([gnunetarm, '-s', '-c', TEST_CONFIGURATION])
50 arm.communicate()
51
52 try:
53     print("Creating an ego " + TEST_REVOCATION_EGO)
54     sys.stdout.flush()
55     sys.stderr.flush()
56     idc = subprocess.Popen([ident, '-C', TEST_REVOCATION_EGO, '-c', TEST_CONFIGURATION])
57     idc.communicate()
58     if idc.returncode != 0:
59         raise Exception("gnunet-identity failed to create an ego `" + TEST_REVOCATION_EGO + "'")
60
61     sys.stdout.flush()
62     sys.stderr.flush()
63     idd = subprocess.Popen([ident, '-d'], stdout=subprocess.PIPE)
64     rev_key, x = idd.communicate()
65     rev_key = rev_key.decode("utf-8")
66     if len(rev_key.split()) < 3:
67         raise Exception("can't get revocation key out of `" + rev_key + "'")
68     rev_key = rev_key.split()[2]
69
70     print("Testing key " + rev_key)
71     sys.stdout.flush()
72     sys.stderr.flush()
73     tst = subprocess.Popen([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE)
74     output_not_revoked, x = tst.communicate()
75     output_not_revoked = output_not_revoked.decode("utf-8")
76     if tst.returncode != 0:
77         raise Exception("gnunet-revocation failed to test a key - " + str(tst.returncode) + ": " + output_not_revoked)
78     if 'valid' not in output_not_revoked:
79         res = 1
80         print("Key was not valid")
81     else:
82         print("Key was valid")
83
84     print("Revoking key " + rev_key)
85     sys.stdout.flush()
86     sys.stderr.flush()
87     rev = subprocess.Popen([revoc, '-R', TEST_REVOCATION_EGO, '-p', '-c', TEST_CONFIGURATION])
88     rev.communicate()
89     if rev.returncode != 0:
90         raise Exception("gnunet-revocation failed to revoke a key")
91
92     print("Testing revoked key " + rev_key)
93     sys.stdout.flush()
94     sys.stderr.flush()
95     tst = subprocess.Popen([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE)
96     output_revoked, x = tst.communicate()
97     output_revoked = output_revoked.decode("utf-8")
98     if tst.returncode != 0:
99         raise Exception("gnunet-revocation failed to test a revoked key")
100     if 'revoked' not in output_revoked:
101         res = 1
102         print("Key was not revoked")
103     else:
104         print("Key was revoked")
105
106 finally:
107     arm = subprocess.Popen([gnunetarm, '-e', '-c', TEST_CONFIGURATION])
108     arm.communicate()
109     if os.path.isdir(cleandir):
110         shutil.rmtree(cleandir, True)
111
112 sys.exit(res)