From: Brian Warner Date: Tue, 4 Mar 2008 21:27:45 +0000 (-0700) Subject: uri.py: get 100% test coverage, fix a few bugs in the process X-Git-Tag: allmydata-tahoe-0.9.0~73 X-Git-Url: https://git.rkrishnan.org/vdrive/%22file:/reliability?a=commitdiff_plain;h=95a085763f043a5db0f0edbbe5516e74c4f1d5df;p=tahoe-lafs%2Ftahoe-lafs.git uri.py: get 100% test coverage, fix a few bugs in the process --- diff --git a/src/allmydata/test/test_uri.py b/src/allmydata/test/test_uri.py index 6b5a8c6a..5ea2a6a6 100644 --- a/src/allmydata/test/test_uri.py +++ b/src/allmydata/test/test_uri.py @@ -29,6 +29,10 @@ class Literal(unittest.TestCase): self.failUnlessIdentical(u, u3) self.failUnlessEqual(u.get_verifier(), None) + he = u.to_human_encoding() + u_h = uri.LiteralFileURI.init_from_human_encoding(he) + self.failUnlessEqual(u, u_h) + def test_empty(self): data = "" # This data is some *very* small data! return self._help_test(data) @@ -54,6 +58,11 @@ class Compare(unittest.TestCase): s = set([lit1, chk1, chk2]) self.failUnlessEqual(len(s), 2) # since chk1==chk2 + def test_is_uri(self): + lit1 = uri.LiteralFileURI("some data").to_string() + self.failUnless(uri.is_uri(lit1)) + self.failIf(uri.is_uri("this is not a uri")) + class CHKFile(unittest.TestCase): def test_pack(self): key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" @@ -85,6 +94,9 @@ class CHKFile(unittest.TestCase): self.failUnlessIdentical(u, u_ro) u1a = IFileURI(u.to_string()) self.failUnlessEqual(u1a, u) + he = u.to_human_encoding() + self.failUnlessEqual(he, "http://127.0.0.1:8123/uri/" + u.to_string()) + self.failUnlessEqual(uri.CHKFileURI.init_from_human_encoding(he), u) u2 = uri.from_string(u.to_string()) self.failUnlessEqual(u2.storage_index, storage_index) @@ -106,6 +118,9 @@ class CHKFile(unittest.TestCase): self.failUnless(isinstance(v.to_string(), str)) v2 = uri.from_string(v.to_string()) self.failUnlessEqual(v, v2) + he = v.to_human_encoding() + v2_h = uri.CHKFileVerifierURI.init_from_human_encoding(he) + self.failUnlessEqual(v2, v2_h) v3 = uri.CHKFileVerifierURI(storage_index="\x00"*16, uri_extension_hash="\x00"*32, @@ -193,6 +208,10 @@ class Mutable(unittest.TestCase): u1a = IMutableFileURI(u.to_string()) self.failUnlessEqual(u1a, u) + he = u.to_human_encoding() + u_h = uri.WriteableSSKFileURI.init_from_human_encoding(he) + self.failUnlessEqual(u, u_h) + u2 = uri.from_string(u.to_string()) self.failUnlessEqual(u2.writekey, writekey) self.failUnlessEqual(u2.fingerprint, fingerprint) @@ -212,6 +231,10 @@ class Mutable(unittest.TestCase): self.failUnless(IMutableFileURI.providedBy(u3)) self.failIf(IDirnodeURI.providedBy(u3)) + he = u3.to_human_encoding() + u3_h = uri.ReadonlySSKFileURI.init_from_human_encoding(he) + self.failUnlessEqual(u3, u3_h) + u4 = uri.ReadonlySSKFileURI(readkey, fingerprint) self.failUnlessEqual(u4.fingerprint, fingerprint) self.failUnlessEqual(u4.readkey, readkey) @@ -236,6 +259,10 @@ class Mutable(unittest.TestCase): self.failUnless(IVerifierURI.providedBy(u7)) self.failUnlessEqual(u7.storage_index, u.storage_index) + he = u5.to_human_encoding() + u5_h = uri.SSKVerifierURI.init_from_human_encoding(he) + self.failUnlessEqual(u5, u5_h) + class NewDirnode(unittest.TestCase): def test_pack(self): diff --git a/src/allmydata/uri.py b/src/allmydata/uri.py index 160d208a..e3e14a39 100644 --- a/src/allmydata/uri.py +++ b/src/allmydata/uri.py @@ -19,7 +19,7 @@ NUMBER='([0-9]+)' # URIs (soon to be renamed "caps") are always allowed to come with a leading # 'http://127.0.0.1:8123/uri/' that will be ignored. -OPTIONALHTTPLEAD=r'(?:https?://(127.0.0.1|localhost):8123/uri/)?' +OPTIONALHTTPLEAD=r'(?:https?://(?:127.0.0.1|localhost):8123/uri/)?' class _BaseURI: @@ -283,7 +283,7 @@ class SSKVerifierURI(_BaseURI): BASE_STRING='URI:SSK-Verifier:' STRING_RE=re.compile('^'+BASE_STRING+BASE32STR_128bits+':'+BASE32STR_256bits+'$') - HUMAN_RE=re.compile('^'+OPTIONALHTTPLEAD+'URI'+SEP+'SSK-RO'+SEP+BASE32STR_128bits+SEP+BASE32STR_256bits+'$') + HUMAN_RE=re.compile('^'+OPTIONALHTTPLEAD+'URI'+SEP+'SSK-Verifier'+SEP+BASE32STR_128bits+SEP+BASE32STR_256bits+'$') def __init__(self, storage_index, fingerprint): assert len(storage_index) == 16