aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2014-02-25 11:15:15 +0000
committerFlorian Dold <florian.dold@gmail.com>2014-02-25 11:15:15 +0000
commit85d0048c22271fac371729ba7b14417a28bb6b48 (patch)
treede231f5453baed5b406bb88b19496d16530f3850 /src/test
parent989f297285b843cb631836bf42e47f25fb567418 (diff)
downloadgnunet-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.conf5
-rw-r--r--src/test/python/test_voting_single.py154
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]
2DEFAULTSERVICES = mesh set consensus secretsharing
3
4[testbed]
5OVERLAY_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"""
2Test the voting implementation with a single authority.
3"""
4import os
5import subprocess
6import time
7
8
9NUM_AUTHORITIES = 1
10NUM_VOTERS = 1
11
12
13def wait_for_after(ts):
14 now = time.time()
15 if now < ts:
16 time.sleep(ts - now)
17
18def 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
29def 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
35def 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
43testdir = subprocess.check_output(["mktemp", "-d", "test-voting-XXXXXXXXXX.d", "--tmpdir"])
44testdir = testdir.strip()
45ballot = os.path.join(testdir, "ballot")
46print "testdir", testdir
47
48
49testbed_conf = "test_voting.conf"
50env = os.environ.copy()
51env["GNUNET_TESTING_PREFIX"] = testdir
52testbed = subprocess.Popen(["gnunet-testbed-profiler", "-n", "-c", testbed_conf, "-p", "1"], env=env)
53
54ballot_filename = os.path.join(testdir, "ballot")
55
56conf = []
57conf.append(os.path.join(testdir, "0", "config"))
58
59for c in conf:
60 while not os.path.exists(c):
61 print "waiting for creation of", c
62 time.sleep(0.1)
63
64print "test dir:", testdir
65
66
67# start authority
68# FIXME: using gnunet-arm for this might be nicer,
69auth = subprocess.Popen(["gnunet-daemon-ballot-tally", "-c", conf[0]])
70
71private_key_filename = get_config("peer", "private_key", conf[0], expand=True)
72
73public_key = subprocess.check_output(["gnunet-ecc", "--print-public-key", private_key_filename]).strip()
74
75print "public key", public_key
76
77create_identity("voter0", conf[0])
78create_identity("issuer", conf[0])
79create_identity("groupca", conf[0])
80
81print "created identities"
82
83ballot = open(ballot_filename, "w")
84
85now = int(time.time())
86TS_KEYGEN_START = now + 10
87TS_KEYGEN_END = now + 20
88TS_START = now + 20
89TS_CLOSING = now + 25
90TS_CONCLUDE = now + 45
91TS_QUERY = now + 65
92TS_END = now + 65
93
94ballot.write("[authorities]\n")
95ballot.write("auth0 = %s\n" % public_key)
96ballot.write("[election]\n")
97ballot.write("TOPIC = mytopic\n")
98ballot.write("THRESHOLD = 1\n")
99ballot.write("CHOICES = yes//no\n")
100ballot.write("GROUP = mygroup\n")
101ballot.write("CA_PUB = %s\n" % get_identity_pubkey("groupca", conf[0]))
102ballot.write("TIMESTAMP_KEYGEN_START = %s\n" % TS_KEYGEN_START)
103ballot.write("TIMESTAMP_KEYGEN_END = %s\n" % TS_KEYGEN_END)
104ballot.write("TIMESTAMP_START = %s\n" % TS_START)
105ballot.write("TIMESTAMP_CLOSING = %s\n" % TS_CLOSING)
106ballot.write("TIMESTAMP_CONCLUDE = %s\n" % TS_CONCLUDE)
107ballot.write("TIMESTAMP_QUERY = %s\n" % TS_QUERY)
108ballot.write("TIMESTAMP_END = %s\n" % TS_END)
109
110ballot.close()
111
112groupcert_filename = os.path.join(testdir, "v0-cert")
113groupcert_file = open(groupcert_filename, "w")
114
115v0_pub = get_identity_pubkey("voter0", conf[0])
116
117subprocess.check_call(["gnunet-ballot-group-certify", "-c", conf[0],
118 "-g", "mygroup", "-e", "groupca", "-m", v0_pub], stdout=groupcert_file)
119
120groupcert_file.close()
121
122# register the ballot with authorities
123subprocess.check_call(["gnunet-ballot", "-LINFO", "-i", ballot_filename, "-e", "issuer", "-c", conf[0]])
124
125# register the ballot with authorities
126subprocess.check_call(["gnunet-ballot", "-LINFO", "-r", ballot_filename, "-c", conf[0]])
127
128wait_for_after(TS_KEYGEN_END)
129
130print "getting threshold public key"
131
132# get the threshold public key
133subprocess.check_call(["gnunet-ballot", "-LDEBUG", "-k", ballot_filename, "-c", conf[0]])
134
135print "threshold public key retrieved"
136
137# add voter's group information
138subprocess.check_call(["gnunet-ballot", "-g", groupcert_filename, ballot_filename, "-c", conf[0]])
139
140# actually vote ...
141subprocess.check_call(["gnunet-ballot", "-x", "yes", ballot_filename, "-e", "voter0", "-c", conf[0]])
142
143wait_for_after(TS_START)
144
145# submit the ballot with the vote
146subprocess.check_call(["gnunet-ballot", "-s", ballot_filename, "-c", conf[0]])
147
148wait_for_after(TS_QUERY)
149
150# query the result
151subprocess.check_call(["gnunet-ballot", "-q", ballot_filename, "-c", conf[0]])
152
153# FIXME: cleanup
154