diff options
author | LRN <lrn1986@gmail.com> | 2013-12-04 00:10:56 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2013-12-04 00:10:56 +0000 |
commit | 1bd149a81fe9feace554cbab710d7a54578f72b9 (patch) | |
tree | a3151eb6663e5780fc2fd5a8735e13d722b40ba4 /src/revocation | |
parent | 10d2f1180dc620075f8c95b2ba3a440ead42a2f2 (diff) | |
download | gnunet-1bd149a81fe9feace554cbab710d7a54578f72b9.tar.gz gnunet-1bd149a81fe9feace554cbab710d7a54578f72b9.zip |
Pythonize the revocation test
Diffstat (limited to 'src/revocation')
-rw-r--r-- | src/revocation/Makefile.am | 2 | ||||
-rwxr-xr-x | src/revocation/test_local_revocation.py | 111 | ||||
-rwxr-xr-x | src/revocation/test_local_revocation.sh | 50 |
3 files changed, 112 insertions, 51 deletions
diff --git a/src/revocation/Makefile.am b/src/revocation/Makefile.am index 94fda5fca..1dfea1432 100644 --- a/src/revocation/Makefile.am +++ b/src/revocation/Makefile.am | |||
@@ -70,7 +70,7 @@ check_PROGRAMS = \ | |||
70 | 70 | ||
71 | 71 | ||
72 | check_SCRIPTS = \ | 72 | check_SCRIPTS = \ |
73 | test_local_revocation.sh | 73 | test_local_revocation.py |
74 | 74 | ||
75 | if ENABLE_TEST_RUN | 75 | if ENABLE_TEST_RUN |
76 | TESTS = \ | 76 | TESTS = \ |
diff --git a/src/revocation/test_local_revocation.py b/src/revocation/test_local_revocation.py new file mode 100755 index 000000000..ef368a510 --- /dev/null +++ b/src/revocation/test_local_revocation.py | |||
@@ -0,0 +1,111 @@ | |||
1 | #!/mingw/bin/python | ||
2 | # This file is part of GNUnet. | ||
3 | # (C) 2010 Christian Grothoff (and other contributing authors) | ||
4 | # | ||
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. | ||
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 | # General Public License for more details. | ||
14 | # | ||
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. | ||
19 | # | ||
20 | # Testcase for ego revocation | ||
21 | from __future__ import print_function | ||
22 | import sys | ||
23 | import os | ||
24 | import subprocess | ||
25 | import re | ||
26 | import shutil | ||
27 | |||
28 | if os.name == 'posix': | ||
29 | config = 'gnunet-config' | ||
30 | gnunetarm = 'gnunet-arm' | ||
31 | ident = 'gnunet-identity' | ||
32 | revoc = './gnunet-revocation' | ||
33 | elif os.name == 'nt': | ||
34 | config = 'gnunet-config.exe' | ||
35 | gnunetarm = 'gnunet-arm.exe' | ||
36 | ident = 'gnunet-identity.exe' | ||
37 | revoc = './gnunet-revocation.exe' | ||
38 | |||
39 | TEST_CONFIGURATION = "test_revocation.conf" | ||
40 | TEST_REVOCATION_EGO = "revoc_test" | ||
41 | |||
42 | |||
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') | ||
46 | |||
47 | if os.path.isdir (cleandir): | ||
48 | shutil.rmtree (cleandir, True) | ||
49 | |||
50 | res = 0 | ||
51 | arm = subprocess.Popen ([gnunetarm, '-s', '-c', TEST_CONFIGURATION]) | ||
52 | arm.communicate () | ||
53 | |||
54 | try: | ||
55 | print ("Creating an ego " + TEST_REVOCATION_EGO) | ||
56 | sys.stdout.flush () | ||
57 | sys.stderr.flush () | ||
58 | idc = subprocess.Popen ([ident, '-C', TEST_REVOCATION_EGO, '-c', TEST_CONFIGURATION]) | ||
59 | idc.communicate () | ||
60 | if idc.returncode != 0: | ||
61 | raise Exception ("gnunet-identity failed to create an ego `" + TEST_REVOCATION_EGO + "'") | ||
62 | |||
63 | sys.stdout.flush () | ||
64 | sys.stderr.flush () | ||
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] | ||
70 | |||
71 | print ("Testing key " + rev_key) | ||
72 | sys.stdout.flush () | ||
73 | sys.stderr.flush () | ||
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: | ||
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 | if tst.returncode != 0: | ||
98 | raise Exception ("gnunet-revocation failed to test a revoked key") | ||
99 | if 'revoked' not in output_revoked: | ||
100 | res = 1 | ||
101 | print ("Key was not revoked") | ||
102 | else: | ||
103 | print ("Key was revoked") | ||
104 | |||
105 | finally: | ||
106 | arm = subprocess.Popen ([gnunetarm, '-e', '-c', TEST_CONFIGURATION]) | ||
107 | arm.communicate () | ||
108 | if os.path.isdir (cleandir): | ||
109 | shutil.rmtree (cleandir, True) | ||
110 | |||
111 | sys.exit (res) | ||
diff --git a/src/revocation/test_local_revocation.sh b/src/revocation/test_local_revocation.sh deleted file mode 100755 index 8595c8df2..000000000 --- a/src/revocation/test_local_revocation.sh +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | #!/bin/bash | ||
2 | TEST_CONFIGURATION="test_revocation.conf" | ||
3 | TEST_REVOCATION_EGO="revoc_test" | ||
4 | |||
5 | which timeout &> /dev/null && DO_TIMEOUT="timeout 5" | ||
6 | trap "gnunet-arm -e -c test_revocation.conf" SIGINT | ||
7 | |||
8 | LOCATION=$(which gnunet-config) | ||
9 | if [ -z $LOCATION ] | ||
10 | then | ||
11 | echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX" | ||
12 | exit 1 | ||
13 | fi | ||
14 | |||
15 | # clean up | ||
16 | rm -rf `gnunet-config -c test_revocation.conf -s PATHS -o GNUNET_HOME -f` | ||
17 | |||
18 | # Start | ||
19 | RES=0 | ||
20 | gnunet-arm -s -c $TEST_CONFIGURATION | ||
21 | gnunet-identity -C $TEST_REVOCATION_EGO -c $TEST_CONFIGURATION | ||
22 | TEST_REVOCATION_KEY=$(gnunet-identity -d | awk '{split($0,a," "); print a[3]}') | ||
23 | |||
24 | echo Testing key $TEST_REVOCATION_KEY | ||
25 | OUTPUT_NOT_REVOKED=$(gnunet-revocation -t $TEST_REVOCATION_KEY -c $TEST_CONFIGURATION) | ||
26 | if grep -q valid <<<$OUTPUT_NOT_REVOKED; | ||
27 | then | ||
28 | echo "Key was valid" | ||
29 | else | ||
30 | RES=1 | ||
31 | fi | ||
32 | |||
33 | echo Revoking key $TEST_REVOCATION_KEY | ||
34 | gnunet-revocation -R $TEST_REVOCATION_EGO -p -c $TEST_CONFIGURATION 1> /dev/null 2> /dev/null | ||
35 | |||
36 | echo Testing revoked key $TEST_REVOCATION_KEY | ||
37 | OUTPUT_REVOKED=$(gnunet-revocation -t $TEST_REVOCATION_KEY -c $TEST_CONFIGURATION) | ||
38 | if grep -q revoked <<<$OUTPUT_REVOKED; | ||
39 | then | ||
40 | echo "Key was revoked" | ||
41 | else | ||
42 | RES=1 | ||
43 | fi | ||
44 | |||
45 | |||
46 | #clean up | ||
47 | gnunet-arm -e -c $TEST_CONFIGURATION | ||
48 | rm -rf `gnunet-config -c test_revocation.conf -s PATHS -o GNUNET_HOME -f` | ||
49 | |||
50 | exit $RES \ No newline at end of file | ||