mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-01 00:45:52 +00:00
Some updates for URI tests.
This commit is contained in:
parent
b79e9c4d61
commit
e22bed447b
@ -1,4 +1,17 @@
|
||||
|
||||
"""
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from builtins import filter, map, zip, ascii, chr, dict, hex, input, next, oct, open, pow, round, super, bytes, int, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
import os
|
||||
from twisted.trial import unittest
|
||||
from allmydata import uri
|
||||
@ -40,24 +53,24 @@ class Literal(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
self.failUnlessReallyEqual(u.get_verify_cap(), None)
|
||||
|
||||
def test_empty(self):
|
||||
data = "" # This data is some *very* small data!
|
||||
data = b"" # This data is some *very* small data!
|
||||
return self._help_test(data)
|
||||
|
||||
def test_pack(self):
|
||||
data = "This is some small data"
|
||||
data = b"This is some small data"
|
||||
return self._help_test(data)
|
||||
|
||||
def test_nonascii(self):
|
||||
data = "This contains \x00 and URI:LIT: and \n, oh my."
|
||||
data = b"This contains \x00 and URI:LIT: and \n, oh my."
|
||||
return self._help_test(data)
|
||||
|
||||
class Compare(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
def test_compare(self):
|
||||
lit1 = uri.LiteralFileURI("some data")
|
||||
lit1 = uri.LiteralFileURI(b"some data")
|
||||
fileURI = 'URI:CHK:f5ahxa25t4qkktywz6teyfvcx4:opuioq7tj2y6idzfp6cazehtmgs5fdcebcz3cygrxyydvcozrmeq:3:10:345834'
|
||||
chk1 = uri.CHKFileURI.init_from_string(fileURI)
|
||||
chk2 = uri.CHKFileURI.init_from_string(fileURI)
|
||||
unk = uri.UnknownURI("lafs://from_the_future")
|
||||
unk = uri.UnknownURI(b"lafs://from_the_future")
|
||||
self.failIfEqual(lit1, chk1)
|
||||
self.failUnlessReallyEqual(chk1, chk2)
|
||||
self.failIfEqual(chk1, "not actually a URI")
|
||||
@ -66,12 +79,12 @@ class Compare(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
self.failUnlessReallyEqual(len(s), 3) # since chk1==chk2
|
||||
|
||||
def test_is_uri(self):
|
||||
lit1 = uri.LiteralFileURI("some data").to_string()
|
||||
lit1 = uri.LiteralFileURI(b"some data").to_string()
|
||||
self.failUnless(uri.is_uri(lit1))
|
||||
self.failIf(uri.is_uri(None))
|
||||
|
||||
def test_is_literal_file_uri(self):
|
||||
lit1 = uri.LiteralFileURI("some data").to_string()
|
||||
lit1 = uri.LiteralFileURI(b"some data").to_string()
|
||||
self.failUnless(uri.is_literal_file_uri(lit1))
|
||||
self.failIf(uri.is_literal_file_uri(None))
|
||||
self.failIf(uri.is_literal_file_uri("foo"))
|
||||
@ -89,9 +102,9 @@ class Compare(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
|
||||
class CHKFile(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
def test_pack(self):
|
||||
key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
||||
key = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
||||
storage_index = hashutil.storage_index_hash(key)
|
||||
uri_extension_hash = hashutil.uri_extension_hash("stuff")
|
||||
uri_extension_hash = hashutil.uri_extension_hash(b"stuff")
|
||||
needed_shares = 25
|
||||
total_shares = 100
|
||||
size = 1234
|
||||
@ -145,8 +158,8 @@ class CHKFile(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
v2 = uri.from_string(v.to_string())
|
||||
self.failUnlessReallyEqual(v, v2)
|
||||
|
||||
v3 = uri.CHKFileVerifierURI(storage_index="\x00"*16,
|
||||
uri_extension_hash="\x00"*32,
|
||||
v3 = uri.CHKFileVerifierURI(storage_index=b"\x00"*16,
|
||||
uri_extension_hash=b"\x00"*32,
|
||||
needed_shares=3,
|
||||
total_shares=10,
|
||||
size=1234)
|
||||
@ -155,9 +168,9 @@ class CHKFile(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
self.failIf(v3.is_mutable())
|
||||
|
||||
def test_pack_badly(self):
|
||||
key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
||||
key = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
||||
storage_index = hashutil.storage_index_hash(key)
|
||||
uri_extension_hash = hashutil.uri_extension_hash("stuff")
|
||||
uri_extension_hash = hashutil.uri_extension_hash(b"stuff")
|
||||
needed_shares = 25
|
||||
total_shares = 100
|
||||
size = 1234
|
||||
@ -186,23 +199,23 @@ class CHKFile(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
|
||||
class Extension(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
def test_pack(self):
|
||||
data = {"stuff": "value",
|
||||
data = {"stuff": b"value",
|
||||
"size": 12,
|
||||
"needed_shares": 3,
|
||||
"big_hash": hashutil.tagged_hash("foo", "bar"),
|
||||
"big_hash": hashutil.tagged_hash(b"foo", b"bar"),
|
||||
}
|
||||
ext = uri.pack_extension(data)
|
||||
d = uri.unpack_extension(ext)
|
||||
self.failUnlessReallyEqual(d["stuff"], "value")
|
||||
self.failUnlessReallyEqual(d["stuff"], b"value")
|
||||
self.failUnlessReallyEqual(d["size"], 12)
|
||||
self.failUnlessReallyEqual(d["big_hash"], hashutil.tagged_hash("foo", "bar"))
|
||||
self.failUnlessReallyEqual(d["big_hash"], hashutil.tagged_hash(b"foo", b"bar"))
|
||||
|
||||
readable = uri.unpack_extension_readable(ext)
|
||||
self.failUnlessReallyEqual(readable["needed_shares"], 3)
|
||||
self.failUnlessReallyEqual(readable["stuff"], "value")
|
||||
self.failUnlessReallyEqual(readable["stuff"], b"value")
|
||||
self.failUnlessReallyEqual(readable["size"], 12)
|
||||
self.failUnlessReallyEqual(readable["big_hash"],
|
||||
base32.b2a(hashutil.tagged_hash("foo", "bar")))
|
||||
base32.b2a(hashutil.tagged_hash(b"foo", b"bar")))
|
||||
self.failUnlessReallyEqual(readable["UEB_hash"],
|
||||
base32.b2a(hashutil.uri_extension_hash(ext)))
|
||||
|
||||
@ -222,7 +235,7 @@ class Unknown(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
self.failUnless(isinstance(u2.get_error(), CapConstraintError))
|
||||
|
||||
# Future caps might have non-ASCII chars in them. (Or maybe not, who can tell about the future?)
|
||||
future_uri = u"I am a cap from the \u263A future. Whatever you ".encode('utf-8')
|
||||
future_uri = u"I am a cap from the \u263A future. Whatever you "
|
||||
u = uri.from_string(future_uri)
|
||||
self.failUnless(isinstance(u, uri.UnknownURI))
|
||||
self.failUnlessReallyEqual(u.to_string(), future_uri)
|
||||
@ -243,8 +256,8 @@ class Constraint(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
|
||||
class Mutable(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.writekey = "\x01" * 16
|
||||
self.fingerprint = "\x02" * 32
|
||||
self.writekey = b"\x01" * 16
|
||||
self.fingerprint = b"\x02" * 32
|
||||
self.readkey = hashutil.ssk_readkey_hash(self.writekey)
|
||||
self.storage_index = hashutil.ssk_storage_index_hash(self.readkey)
|
||||
|
||||
@ -417,7 +430,13 @@ class Mutable(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
self.failIf(u2.is_readonly())
|
||||
self.failUnless(u2.is_mutable())
|
||||
|
||||
cap3 = cap+":"+os.urandom(40) # parse *that*!
|
||||
|
||||
cap3 = cap+":"
|
||||
for item in os.urandom(40):
|
||||
if isinstance(item, int):
|
||||
cap3 += chr(item)
|
||||
else:
|
||||
cap3 += chr(ord(item))
|
||||
u3 = uri.WriteableMDMFFileURI.init_from_string(cap3)
|
||||
self.failUnlessReallyEqual(self.writekey, u3.writekey)
|
||||
self.failUnlessReallyEqual(self.fingerprint, u3.fingerprint)
|
||||
@ -468,8 +487,8 @@ class Mutable(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
|
||||
class Dirnode(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
def test_pack(self):
|
||||
writekey = "\x01" * 16
|
||||
fingerprint = "\x02" * 32
|
||||
writekey = b"\x01" * 16
|
||||
fingerprint = b"\x02" * 32
|
||||
|
||||
n = uri.WriteableSSKFileURI(writekey, fingerprint)
|
||||
u1 = uri.DirectoryURI(n)
|
||||
@ -536,8 +555,8 @@ class Dirnode(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
u1.get_verify_cap()._filenode_uri)
|
||||
|
||||
def test_immutable(self):
|
||||
readkey = "\x01" * 16
|
||||
uri_extension_hash = hashutil.uri_extension_hash("stuff")
|
||||
readkey = b"\x01" * 16
|
||||
uri_extension_hash = hashutil.uri_extension_hash(b"stuff")
|
||||
needed_shares = 3
|
||||
total_shares = 10
|
||||
size = 1234
|
||||
@ -597,7 +616,7 @@ class Dirnode(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
self.failUnless(str(u2_verifier))
|
||||
|
||||
def test_literal(self):
|
||||
u0 = uri.LiteralFileURI("data")
|
||||
u0 = uri.LiteralFileURI(b"data")
|
||||
u1 = uri.LiteralDirectoryURI(u0)
|
||||
self.failUnless(str(u1))
|
||||
self.failUnlessReallyEqual(u1.to_string(), "URI:DIR2-LIT:mrqxiyi")
|
||||
@ -611,8 +630,8 @@ class Dirnode(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
self.failUnlessReallyEqual(u1.abbrev_si(), "<LIT>")
|
||||
|
||||
def test_mdmf(self):
|
||||
writekey = "\x01" * 16
|
||||
fingerprint = "\x02" * 32
|
||||
writekey = b"\x01" * 16
|
||||
fingerprint = b"\x02" * 32
|
||||
uri1 = uri.WriteableMDMFFileURI(writekey, fingerprint)
|
||||
d1 = uri.MDMFDirectoryURI(uri1)
|
||||
self.failIf(d1.is_readonly())
|
||||
@ -635,8 +654,8 @@ class Dirnode(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
self.failUnlessIsInstance(d3, uri.UnknownURI)
|
||||
|
||||
def test_mdmf_attenuation(self):
|
||||
writekey = "\x01" * 16
|
||||
fingerprint = "\x02" * 32
|
||||
writekey = b"\x01" * 16
|
||||
fingerprint = b"\x02" * 32
|
||||
|
||||
uri1 = uri.WriteableMDMFFileURI(writekey, fingerprint)
|
||||
d1 = uri.MDMFDirectoryURI(uri1)
|
||||
@ -676,8 +695,8 @@ class Dirnode(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
|
||||
def test_mdmf_verifier(self):
|
||||
# I'm not sure what I want to write here yet.
|
||||
writekey = "\x01" * 16
|
||||
fingerprint = "\x02" * 32
|
||||
writekey = b"\x01" * 16
|
||||
fingerprint = b"\x02" * 32
|
||||
uri1 = uri.WriteableMDMFFileURI(writekey, fingerprint)
|
||||
d1 = uri.MDMFDirectoryURI(uri1)
|
||||
v1 = d1.get_verify_cap()
|
||||
|
@ -82,6 +82,7 @@ PORTED_TEST_MODULES = [
|
||||
"allmydata.test.test_spans",
|
||||
"allmydata.test.test_statistics",
|
||||
"allmydata.test.test_time_format",
|
||||
"allmydata.test.test_uri",
|
||||
"allmydata.test.test_util",
|
||||
"allmydata.test.test_version",
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user