[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[minion-cvs] Earlier validation for some configuration values
Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv24795/lib/mixminion
Modified Files:
Config.py ServerInfo.py test.py
Log Message:
Earlier validation for some configuration values
Index: Config.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Config.py,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- Config.py 3 Jan 2004 07:35:23 -0000 1.74
+++ Config.py 8 Jan 2004 23:07:31 -0000 1.75
@@ -187,6 +187,14 @@
result.append(str(d))
return ", ".join(result)
+def _parseList(s):
+ """Validation function. Parse a comma-separated list of strings."""
+ return [ item.strip() for item in s.split(",") ]
+
+def _parseSeq(s):
+ """Validation function. Parse a space-separated list of strings."""
+ return [ item.strip() for item in s.split() ]
+
def _parseInt(integer):
"""Validation function. Converts a config value to an int.
Raises ConfigError on failure."""
@@ -696,6 +704,8 @@
"IP" : (_parseIP, str),
"IP6" : (_parseIP6, str),
"host" : (_parseHost, str),
+ "list" : (_parseList, ",".join),
+ "seq" : (_parseSeq, " ".join),
"addressSet_allow" : (_parseAddressSet_allow, str), #XXXX
"addressSet_deny" : (_parseAddressSet_deny, str), #XXXX
"command" : (_parseCommand, lambda c,o: " ".join([c," ".join(o)])),
Index: ServerInfo.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ServerInfo.py,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- ServerInfo.py 7 Jan 2004 20:44:52 -0000 1.73
+++ ServerInfo.py 8 Jan 2004 23:07:31 -0000 1.74
@@ -119,7 +119,7 @@
"Contact-Fingerprint": ("ALLOW", None, None),
"Packet-Formats": ("ALLOW", None, None),#XXXX007 remove
# XXXX008 change these next few to "REQUIRE".
- "Packet-Versions": ("ALLOW", None, '0.3'),
+ "Packet-Versions": ("ALLOW", "list", '0.3'),
"Software": ("ALLOW", None, None),
"Secure-Configuration": ("ALLOW", "boolean", None),
"Why-Insecure": ("ALLOW", None, None),
@@ -130,13 +130,13 @@
"Hostname": ("ALLOW", "host", None),#XXXX008 require
"Port": ("REQUIRE", "int", None),
"Key-Digest": ("ALLOW", "base64", None),#XXXX007/8 rmv
- "Protocols": ("REQUIRE", None, None),
+ "Protocols": ("REQUIRE", "list", None),
"Allow": ("ALLOW*", "addressSet_allow", None),
"Deny": ("ALLOW*", "addressSet_deny", None),
},
"Outgoing/MMTP" : {
"Version": ("REQUIRE", None, None),
- "Protocols": ("REQUIRE", None, None),
+ "Protocols": ("REQUIRE", "list", None),
"Allow": ("ALLOW*", "addressSet_allow", None),
"Deny": ("ALLOW*", "addressSet_deny", None),
},
@@ -364,22 +364,21 @@
inc = self['Incoming/MMTP']
if not inc.get("Version"):
return []
- return [ s.strip() for s in inc["Protocols"].split(",") ]
+ return inc["Protocols"]
def getOutgoingMMTPProtocols(self):
"""Return a list of the MMTP versions supported by this this server
for outgoing packets."""
- inc = self['Outgoing/MMTP']
- if not inc.get("Version"):
+ out = self['Outgoing/MMTP']
+ if not out.get("Version"):
return []
- return [ s.strip() for s in inc["Protocols"].split(",") ]
+ return out["Protocols"]
def supportsPacketVersion(self):
"""Return true iff we can build packets in a format this server
recognizes."""
- formatStr = self['Server'].get("Packet-Versions")
- if formatStr == None: formatStr = "0.3"
- formats = [ s.strip() for s in formatStr.split(",") ]
+ formats = self['Server'].get("Packet-Versions")
+ if formats == None: formats = [ "0.3" ]
return mixminion.Packet.PACKET_VERSION in formats
def canRelayTo(self, otherDesc):
@@ -560,8 +559,8 @@
servercontents = [ "[Server]\n%s"%s for s in sections[1:] ]
self.header = _DirectoryHeader(headercontents, digest)
- self.goodServerNames = [name.strip().lower() for name in
- self.header['Directory']['Recommended-Servers'].split(",")]
+ self.goodServerNames = [name.lower() for name in
+ self.header['Directory']['Recommended-Servers'] ]
servers = [ ServerInfo(string=s,
validatedDigests=validatedDigests)
for s in servercontents ]
@@ -604,7 +603,7 @@
"Published": ("REQUIRE", "time", None),
"Valid-After": ("REQUIRE", "date", None),
"Valid-Until": ("REQUIRE", "date", None),
- "Recommended-Servers": ("REQUIRE", None, None),
+ "Recommended-Servers": ("REQUIRE", "list", None),
},
'Signature': {"__SECTION__": ("REQUIRE", None, None),
"DirectoryIdentity": ("REQUIRE", "publicKey", None),
@@ -612,8 +611,8 @@
"DirectorySignature": ("REQUIRE", "base64", None),
},
'Recommended-Software': {"__SECTION__": ("ALLOW", None, None),
- "MixminionClient": ("ALLOW", None, None),
- "MixminionServer": ("ALLOW", None, None), }
+ "MixminionClient": ("ALLOW", "seq", None),
+ "MixminionServer": ("ALLOW", "seq", None), }
}
def __init__(self, contents, expectedDigest):
"""Parse a directory header out of a provided string; validate it
Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.176
retrieving revision 1.177
diff -u -d -r1.176 -r1.177
--- test.py 8 Jan 2004 22:35:24 -0000 1.176
+++ test.py 8 Jan 2004 23:07:31 -0000 1.177
@@ -4528,15 +4528,15 @@
eq(info['Server']['Contact'], "a@b.c")
eq(info['Server']['Software'], "Mixminion %s"%mixminion.__version__)
eq(info['Server']['Packet-Formats'], None)
- eq(info['Server']['Packet-Versions'], "0.3")
+ eq(info['Server']['Packet-Versions'], ["0.3"])
eq(info['Server']['Comments'],
"This is a test of the emergency broadcast system")
eq(info['Incoming/MMTP']['Version'], "0.1")
eq(info['Incoming/MMTP']['Port'], 48099)
- eq(info['Incoming/MMTP']['Protocols'], "0.3")
+ eq(info['Incoming/MMTP']['Protocols'], ["0.3"])
eq(info['Outgoing/MMTP']['Version'], "0.1")
- eq(info['Outgoing/MMTP']['Protocols'], "0.3")
+ eq(info['Outgoing/MMTP']['Protocols'], ["0.3"])
eq(info['Incoming/MMTP']['Allow'], [("192.168.0.16", "255.255.255.255",
1,1024),
("0.0.0.0", "0.0.0.0",