diff options
author | Florian Dold <florian.dold@gmail.com> | 2014-02-25 11:15:15 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2014-02-25 11:15:15 +0000 |
commit | 85d0048c22271fac371729ba7b14417a28bb6b48 (patch) | |
tree | de231f5453baed5b406bb88b19496d16530f3850 /src/test | |
parent | 989f297285b843cb631836bf42e47f25fb567418 (diff) | |
download | gnunet-java-85d0048c22271fac371729ba7b14417a28bb6b48.tar.gz gnunet-java-85d0048c22271fac371729ba7b14417a28bb6b48.zip |
- support mesh's new NACK message
- remove
- python test skeleton for voting
- encrypted votes
- establish threshold key during ballot registration
- ballot tool can request threshold public keys from authorities
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/python/test_voting.conf | 5 | ||||
-rw-r--r-- | src/test/python/test_voting_single.py | 154 |
2 files changed, 159 insertions, 0 deletions
diff --git a/src/test/python/test_voting.conf b/src/test/python/test_voting.conf new file mode 100644 index 0000000..0684302 --- /dev/null +++ b/src/test/python/test_voting.conf | |||
@@ -0,0 +1,5 @@ | |||
1 | [arm] | ||
2 | DEFAULTSERVICES = mesh set consensus secretsharing | ||
3 | |||
4 | [testbed] | ||
5 | OVERLAY_TOPOLOGY = CLIQUE | ||
diff --git a/src/test/python/test_voting_single.py b/src/test/python/test_voting_single.py new file mode 100644 index 0000000..630f92e --- /dev/null +++ b/src/test/python/test_voting_single.py | |||
@@ -0,0 +1,154 @@ | |||
1 | """ | ||
2 | Test the voting implementation with a single authority. | ||
3 | """ | ||
4 | import os | ||
5 | import subprocess | ||
6 | import time | ||
7 | |||
8 | |||
9 | NUM_AUTHORITIES = 1 | ||
10 | NUM_VOTERS = 1 | ||
11 | |||
12 | |||
13 | def wait_for_after(ts): | ||
14 | now = time.time() | ||
15 | if now < ts: | ||
16 | time.sleep(ts - now) | ||
17 | |||
18 | def get_config(section, option, filename=None, expand=False): | ||
19 | args = ["gnunet-config"] | ||
20 | if filename is not None: | ||
21 | args.extend(["-c", filename]) | ||
22 | args.extend(["-s", section]) | ||
23 | args.extend(["-o", option]) | ||
24 | if expand: | ||
25 | args.extend(["-f"]) | ||
26 | return subprocess.check_output(args).strip() | ||
27 | |||
28 | |||
29 | def create_identity(name, config=None): | ||
30 | args = ["gnunet-identity", "-C", name] | ||
31 | if config is not None: | ||
32 | args.extend(["-c", config]) | ||
33 | subprocess.check_call(args) | ||
34 | |||
35 | def get_identity_pubkey(name, config=None): | ||
36 | args = ["gnunet-identity", "-d", name] | ||
37 | if config is not None: | ||
38 | args.extend(["-c", config]) | ||
39 | out = subprocess.check_output(args) | ||
40 | components = out.split("-") | ||
41 | return components[-1].strip() | ||
42 | |||
43 | testdir = subprocess.check_output(["mktemp", "-d", "test-voting-XXXXXXXXXX.d", "--tmpdir"]) | ||
44 | testdir = testdir.strip() | ||
45 | ballot = os.path.join(testdir, "ballot") | ||
46 | print "testdir", testdir | ||
47 | |||
48 | |||
49 | testbed_conf = "test_voting.conf" | ||
50 | env = os.environ.copy() | ||
51 | env["GNUNET_TESTING_PREFIX"] = testdir | ||
52 | testbed = subprocess.Popen(["gnunet-testbed-profiler", "-n", "-c", testbed_conf, "-p", "1"], env=env) | ||
53 | |||
54 | ballot_filename = os.path.join(testdir, "ballot") | ||
55 | |||
56 | conf = [] | ||
57 | conf.append(os.path.join(testdir, "0", "config")) | ||
58 | |||
59 | for c in conf: | ||
60 | while not os.path.exists(c): | ||
61 | print "waiting for creation of", c | ||
62 | time.sleep(0.1) | ||
63 | |||
64 | print "test dir:", testdir | ||
65 | |||
66 | |||
67 | # start authority | ||
68 | # FIXME: using gnunet-arm for this might be nicer, | ||
69 | auth = subprocess.Popen(["gnunet-daemon-ballot-tally", "-c", conf[0]]) | ||
70 | |||
71 | private_key_filename = get_config("peer", "private_key", conf[0], expand=True) | ||
72 | |||
73 | public_key = subprocess.check_output(["gnunet-ecc", "--print-public-key", private_key_filename]).strip() | ||
74 | |||
75 | print "public key", public_key | ||
76 | |||
77 | create_identity("voter0", conf[0]) | ||
78 | create_identity("issuer", conf[0]) | ||
79 | create_identity("groupca", conf[0]) | ||
80 | |||
81 | print "created identities" | ||
82 | |||
83 | ballot = open(ballot_filename, "w") | ||
84 | |||
85 | now = int(time.time()) | ||
86 | TS_KEYGEN_START = now + 10 | ||
87 | TS_KEYGEN_END = now + 20 | ||
88 | TS_START = now + 20 | ||
89 | TS_CLOSING = now + 25 | ||
90 | TS_CONCLUDE = now + 45 | ||
91 | TS_QUERY = now + 65 | ||
92 | TS_END = now + 65 | ||
93 | |||
94 | ballot.write("[authorities]\n") | ||
95 | ballot.write("auth0 = %s\n" % public_key) | ||
96 | ballot.write("[election]\n") | ||
97 | ballot.write("TOPIC = mytopic\n") | ||
98 | ballot.write("THRESHOLD = 1\n") | ||
99 | ballot.write("CHOICES = yes//no\n") | ||
100 | ballot.write("GROUP = mygroup\n") | ||
101 | ballot.write("CA_PUB = %s\n" % get_identity_pubkey("groupca", conf[0])) | ||
102 | ballot.write("TIMESTAMP_KEYGEN_START = %s\n" % TS_KEYGEN_START) | ||
103 | ballot.write("TIMESTAMP_KEYGEN_END = %s\n" % TS_KEYGEN_END) | ||
104 | ballot.write("TIMESTAMP_START = %s\n" % TS_START) | ||
105 | ballot.write("TIMESTAMP_CLOSING = %s\n" % TS_CLOSING) | ||
106 | ballot.write("TIMESTAMP_CONCLUDE = %s\n" % TS_CONCLUDE) | ||
107 | ballot.write("TIMESTAMP_QUERY = %s\n" % TS_QUERY) | ||
108 | ballot.write("TIMESTAMP_END = %s\n" % TS_END) | ||
109 | |||
110 | ballot.close() | ||
111 | |||
112 | groupcert_filename = os.path.join(testdir, "v0-cert") | ||
113 | groupcert_file = open(groupcert_filename, "w") | ||
114 | |||
115 | v0_pub = get_identity_pubkey("voter0", conf[0]) | ||
116 | |||
117 | subprocess.check_call(["gnunet-ballot-group-certify", "-c", conf[0], | ||
118 | "-g", "mygroup", "-e", "groupca", "-m", v0_pub], stdout=groupcert_file) | ||
119 | |||
120 | groupcert_file.close() | ||
121 | |||
122 | # register the ballot with authorities | ||
123 | subprocess.check_call(["gnunet-ballot", "-LINFO", "-i", ballot_filename, "-e", "issuer", "-c", conf[0]]) | ||
124 | |||
125 | # register the ballot with authorities | ||
126 | subprocess.check_call(["gnunet-ballot", "-LINFO", "-r", ballot_filename, "-c", conf[0]]) | ||
127 | |||
128 | wait_for_after(TS_KEYGEN_END) | ||
129 | |||
130 | print "getting threshold public key" | ||
131 | |||
132 | # get the threshold public key | ||
133 | subprocess.check_call(["gnunet-ballot", "-LDEBUG", "-k", ballot_filename, "-c", conf[0]]) | ||
134 | |||
135 | print "threshold public key retrieved" | ||
136 | |||
137 | # add voter's group information | ||
138 | subprocess.check_call(["gnunet-ballot", "-g", groupcert_filename, ballot_filename, "-c", conf[0]]) | ||
139 | |||
140 | # actually vote ... | ||
141 | subprocess.check_call(["gnunet-ballot", "-x", "yes", ballot_filename, "-e", "voter0", "-c", conf[0]]) | ||
142 | |||
143 | wait_for_after(TS_START) | ||
144 | |||
145 | # submit the ballot with the vote | ||
146 | subprocess.check_call(["gnunet-ballot", "-s", ballot_filename, "-c", conf[0]]) | ||
147 | |||
148 | wait_for_after(TS_QUERY) | ||
149 | |||
150 | # query the result | ||
151 | subprocess.check_call(["gnunet-ballot", "-q", ballot_filename, "-c", conf[0]]) | ||
152 | |||
153 | # FIXME: cleanup | ||
154 | |||