[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[minion-cvs] Start writing unit tests for directory voting formats. ...
Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv4406/src/minion/lib/mixminion
Modified Files:
ServerInfo.py test.py testSupport.py
Log Message:
Start writing unit tests for directory voting formats. Fix many bugs and conformance issues. Keen!
Index: ServerInfo.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ServerInfo.py,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -d -r1.88 -r1.89
--- ServerInfo.py 12 Dec 2004 22:28:39 -0000 1.88
+++ ServerInfo.py 13 Dec 2004 06:01:58 -0000 1.89
@@ -760,8 +760,11 @@
"Valid-Until" : ("REQUIRE", "date", None),
"Recommended-Servers" : ("REQUIRE", "list", None),
"Voting-Server" : ("REQUIRE*", None, None) },
- "Recommended-Software" :
- _DirectoryHeader._syntax["Recommended-Software"] }
+ 'Recommended-Software': {
+ "__SECTION__": ("ALLOW", None, None),
+ "MixminionClient": ("ALLOW", "list", None),
+ "MixminionServer": ("ALLOW", "list", None), },
+ }
def __init__(self, string):
self.sigStatus = None
@@ -774,6 +777,7 @@
if k == 'Version' and v.strip() != self.VERSION:
raise ConfigError("Unrecognized descriptor version: %s"
% v.strip())
+ return contents
def validate(self, lines, contents):
sec = self['Directory-Info']
@@ -787,8 +791,11 @@
lst = s.split(" ",1)
if len(lst) != 2:
raise ConfigError("Missing URLBase or fingerprint in Voting-Server")
- self.voters.append((mixminion.Config._parseBase64(lst[0]),
- lst[1].strip()))
+ digest = mixminion.Config._parseHex(lst[0]) # can raise ConfigError
+ if len(digest) != DIGEST_LEN:
+ raise ConfigError("Bad length for Voting-Server fingerprint",
+ len(lst[0]), len(digest))
+ self.voters.append((lst[0], lst[1].strip()))
class _DirectorySignature(mixminion.Config._ConfigFile):
"""Internal object: used to parse, validate, and store fields in a
@@ -810,7 +817,7 @@
mixminion.Config._ConfigFile.__init__(self, string=string)
def validate(self, lines, contents):
- sec = contents['Signed-Directory']
+ sec = self['Signed-Directory']
idKeyBytes = sec['Directory-Identity'].get_modulus_bytes()
if not (2048 <= idKeyBytes*8 <= 4096):
raise ConfigError("Identity key length is out of range (%s bits)"
@@ -933,8 +940,8 @@
sigs = []
# Extract all signatures.
- while directory.startswith("[Directory-Signature]\n"):
- eos = directory.find("\n[Directory-Signature]\n", 1)
+ while directory.startswith("[Signed-Directory]\n"):
+ eos = directory.find("\n[Signed-Directory]\n", 1)
if eos < 0:
eos = directory.find("\n[Directory-Info]\n")
if eos < 0:
Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.212
retrieving revision 1.213
diff -u -d -r1.212 -r1.213
--- test.py 12 Dec 2004 23:24:30 -0000 1.212
+++ test.py 13 Dec 2004 06:01:58 -0000 1.213
@@ -165,6 +165,9 @@
_generated_rsa_keys[(0,2048)] = mixminion.testSupport.TEST_KEYS_2048[0]
_generated_rsa_keys[(1,2048)] = mixminion.testSupport.TEST_KEYS_2048[1]
_generated_rsa_keys[(2,2048)] = mixminion.testSupport.TEST_KEYS_2048[2]
+_generated_rsa_keys[(3,2048)] = mixminion.testSupport.TEST_KEYS_2048[3]
+_generated_rsa_keys[(4,2048)] = mixminion.testSupport.TEST_KEYS_2048[4]
+_generated_rsa_keys[(5,2048)] = mixminion.testSupport.TEST_KEYS_2048[5]
def getRSAKey(n,bits):
"""Return the n'th of an arbitrary number of cached 'bits'-bit RSA keys,
generating them as necessary."""
@@ -186,9 +189,9 @@
_pk_generate_orig = Crypto.pk_generate
_pk_generate_idx = 0
def _pk_generate_replacement(bits=1024,e=65537):
- if bits == 1024:
+ if bits == 2048:
global _pk_generate_idx
- _pk_generate_idx = (_pk_generate_idx + 1) % 4
+ _pk_generate_idx = (_pk_generate_idx + 1) % 6
return getRSAKey(_pk_generate_idx, bits)
else:
return getRSAKey(0, bits)
@@ -5071,7 +5074,8 @@
info3 = key3.getServerDescriptor()
eq(info3['Incoming/MMTP']['Hostname'], "Theserver4")
- def test_directory(self):
+ def testOldDirectory(self):
+ #XXXX008 split this into serverlist and serverdirectory tests.
eq = self.assertEquals
examples = getExampleServerDescriptors()
ServerList = mixminion.directory.ServerList.ServerList
@@ -5226,6 +5230,31 @@
eq(4, len(lst.servers))
eq(2, len(os.listdir(archiveDir)))
+ def testNewDirectoryFormats(self):
+ DF = mixminion.directory.DirFormats
+ examples = getExampleServerDescriptors()
+ id0 = getRSAKey(1,2048)
+ id1 = getRSAKey(3,2048)
+ id2 = getRSAKey(5,2048)
+ keyid0 = mixminion.Crypto.pk_fingerprint(id0)
+ keyid1 = mixminion.Crypto.pk_fingerprint(id1)
+ keyid2 = mixminion.Crypto.pk_fingerprint(id2)
+ ub0 = "http://foo/"
+ ub1 = "http://foo.bar/"
+ ub2 = "http://foo.bar/baz/"
+ voters = [(keyid0,ub0), (keyid1,ub1), (keyid2,ub2)]
+
+ # Test generating a vote directory.
+ va = previousMidnight(time.time())
+ s1 = [ examples['Fred'][1], examples['Fred'][2], examples['Lola'][1],
+ examples['Joe'][0], examples['Alice'][0] ]
+ vd1 = {}
+ s_vote1 = DF.generateVoteDirectory(
+ id0, s1, [ "Fred", "Lola", "Joe" ],
+ voters, va, ["0.0.8", "0.0.8.1"], ["0.0.8.1"], validatedDigests=vd1)
+
+ # Test parsing it.
+ vote1 = mixminion.ServerInfo.SignedDirectory(string=s_vote1)
#----------------------------------------------------------------------
# EventStats
@@ -6490,7 +6519,7 @@
# Generate a config file
homedir = mix_mktemp()
conf = EX_SERVER_CONF_TEMPLATE % locals()
- identity = getRSAKey(serveridx%3,2048)
+ identity = getRSAKey(serveridx%6,2048)
serveridx += 1
for t in types:
if t == MBOX_TYPE:
@@ -7839,8 +7868,8 @@
loader = unittest.TestLoader()
tc = loader.loadTestsFromTestCase
- if 0:
- suite.addTest(tc(PingerTests))
+ if 1:
+ suite.addTest(tc(ServerInfoTests))
return suite
testClasses = [MiscTests,
MinionlibCryptoTests,
Index: testSupport.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/testSupport.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- testSupport.py 6 Mar 2004 05:33:01 -0000 1.25
+++ testSupport.py 13 Dec 2004 06:01:58 -0000 1.26
@@ -522,7 +522,73 @@
HFHRYKCLDGJ0vRaxx92yy/XPW33QfHIWVeWGMn2wldvC+7jrUbzroczCkShzt+ocqhFh160/k6eW
vTgMcZV5tXIFSgz+a2P/Qmyn8ENAlmPle9gxsOTrByPxoKUCgYEA1raYnqI9nKWkZYMrEOHx7Sy3
xCaKFSoc4nBxjJvZsSJ2aH6fJfMksPTisbYdSaXkGrb1fN2E7HxM1LsnbCyvXZsbMUV0zkk0Tzum
-qDVW03gO4AvOD9Ix5gdebdq8le0xfMUzDvAIG1ypM+oMdZ122bI/rsOpLkZ4EtmixFxJbpk="""
+qDVW03gO4AvOD9Ix5gdebdq8le0xfMUzDvAIG1ypM+oMdZ122bI/rsOpLkZ4EtmixFxJbpk=""",
+"""\
+MIIEowIBAAKCAQEAs1+yp3NsF9qTybuupbt3cyBD+rEWUB+c3veK+TLTTu/hKrULCg6AaCXObv49
+45xca0FxXc1/hbr7JinarjngmXj8Slr7UlTkbYKar9aGo3oMkMzbamQC4hBlp0fvH95f+A4M0iyM
+RLGgcvZdk5/n0aXGOrlJ0maNFg5qgJcm38i5eRiItPJzTvnktYFcAbKV9IV3C8B8H2soubaJv0JF
+nyPPA/pZDsK5/RNg+YRIflXKWe4dNH4/gt/3FwykQ7qdaoSpfoFS4WYCBPxJVcwzTfkwnAw7V+Lb
+qxpBn0qJTz0sB6IIQWmOL5IhKd2isZVN9H2M+72vU+UDeCPrDYDbjQIDAQABAoIBAGBoVwVZLAfG
+GxiaH0xEbfcaqG7dLzjxRMcyFSfLAXezxjnGBKDrGmjfqQxO6cSkDag4DE52XMvrq4DfjgGGagkS
+1cbBD8M4jW2ufKV1j/fdaVOK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