2 # This file is part of GNUnet.
3 # (C) 2010 Christian Grothoff (and other contributing authors)
5 # GNUnet is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 2, or (at your
8 # option) any later version.
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 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with GNUnet; see the file COPYING. If not, write to the
17 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
20 # Testcase for ego revocation
21 from __future__ import print_function
28 if os.name == 'posix':
29 config = 'gnunet-config'
30 gnunetarm = 'gnunet-arm'
31 ident = 'gnunet-identity'
32 revoc = './gnunet-revocation'
34 config = 'gnunet-config.exe'
35 gnunetarm = 'gnunet-arm.exe'
36 ident = 'gnunet-identity.exe'
37 revoc = './gnunet-revocation.exe'
39 TEST_CONFIGURATION = "test_revocation.conf"
40 TEST_REVOCATION_EGO = "revoc_test"
43 get_clean = subprocess.Popen ([config, '-c', TEST_CONFIGURATION, '-s', 'PATHS', '-o', 'GNUNET_HOME', '-f'], stdout=subprocess.PIPE)
44 cleandir, x = get_clean.communicate ()
45 cleandir = cleandir.rstrip ('\n').rstrip ('\r')
47 if os.path.isdir (cleandir):
48 shutil.rmtree (cleandir, True)
51 arm = subprocess.Popen ([gnunetarm, '-s', '-c', TEST_CONFIGURATION])
55 print ("Creating an ego " + TEST_REVOCATION_EGO)
58 idc = subprocess.Popen ([ident, '-C', TEST_REVOCATION_EGO, '-c', TEST_CONFIGURATION])
60 if idc.returncode != 0:
61 raise Exception ("gnunet-identity failed to create an ego `" + TEST_REVOCATION_EGO + "'")
65 idd = subprocess.Popen ([ident, '-d'], stdout=subprocess.PIPE)
66 rev_key, x = idd.communicate ()
67 if len (rev_key.split ()) < 3:
68 raise Exception ("can't get revocation key out of `" + rev_key + "'")
69 rev_key = rev_key.split ()[2]
71 print ("Testing key " + rev_key)
74 tst = subprocess.Popen ([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE)
75 output_not_revoked, x = tst.communicate ()
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:
80 print ("Key was not valid")
82 print ("Key was valid")
84 print ("Revoking key " + rev_key)
87 rev = subprocess.Popen ([revoc, '-R', TEST_REVOCATION_EGO, '-p', '-c', TEST_CONFIGURATION])
89 if rev.returncode != 0:
90 raise Exception ("gnunet-revocation failed to revoke a key")
92 print ("Testing revoked key " + rev_key)
95 tst = subprocess.Popen ([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE)
96 output_revoked, x = tst.communicate ()
97 if tst.returncode != 0:
98 raise Exception ("gnunet-revocation failed to test a revoked key")
99 if 'revoked' not in output_revoked:
101 print ("Key was not revoked")
103 print ("Key was revoked")
106 arm = subprocess.Popen ([gnunetarm, '-e', '-c', TEST_CONFIGURATION])
108 if os.path.isdir (cleandir):
109 shutil.rmtree (cleandir, True)