mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-19 16:20:52 +00:00
Some progress towards passing tests.
This commit is contained in:
parent
2ae03043b7
commit
bcc509b7a7
@ -18,7 +18,7 @@ from allmydata.util.assertutil import precondition
|
||||
class InvalidCacheError(Exception):
|
||||
pass
|
||||
|
||||
V2 = "http://allmydata.org/tahoe/protocols/introducer/v2"
|
||||
V2 = b"http://allmydata.org/tahoe/protocols/introducer/v2"
|
||||
|
||||
@implementer(RIIntroducerSubscriberClient_v2, IIntroducerClient)
|
||||
class IntroducerClient(service.Service, Referenceable):
|
||||
@ -28,6 +28,7 @@ class IntroducerClient(service.Service, Referenceable):
|
||||
app_versions, sequencer, cache_filepath):
|
||||
self._tub = tub
|
||||
self.introducer_furl = introducer_furl
|
||||
assert isinstance(introducer_furl, (bytes, type(None)))
|
||||
|
||||
assert type(nickname) is unicode
|
||||
self._nickname = nickname
|
||||
@ -37,11 +38,11 @@ class IntroducerClient(service.Service, Referenceable):
|
||||
self._sequencer = sequencer
|
||||
self._cache_filepath = cache_filepath
|
||||
|
||||
self._my_subscriber_info = { "version": 0,
|
||||
"nickname": self._nickname,
|
||||
"app-versions": self._app_versions,
|
||||
"my-version": self._my_version,
|
||||
"oldest-supported": self._oldest_supported,
|
||||
self._my_subscriber_info = { b"version": 0,
|
||||
b"nickname": self._nickname,
|
||||
b"app-versions": self._app_versions,
|
||||
b"my-version": self._my_version,
|
||||
b"oldest-supported": self._oldest_supported,
|
||||
}
|
||||
|
||||
self._outbound_announcements = {} # not signed
|
||||
@ -129,9 +130,9 @@ class IntroducerClient(service.Service, Referenceable):
|
||||
|
||||
def _got_introducer(self, publisher):
|
||||
self.log("connected to introducer, getting versions")
|
||||
default = { "http://allmydata.org/tahoe/protocols/introducer/v1":
|
||||
default = { b"http://allmydata.org/tahoe/protocols/introducer/v1":
|
||||
{ },
|
||||
"application-version": "unknown: no get_version()",
|
||||
b"application-version": b"unknown: no get_version()",
|
||||
}
|
||||
d = add_version_to_remote_reference(publisher, default)
|
||||
d.addCallback(self._got_versioned_introducer)
|
||||
@ -144,6 +145,7 @@ class IntroducerClient(service.Service, Referenceable):
|
||||
def _got_versioned_introducer(self, publisher):
|
||||
self.log("got introducer version: %s" % (publisher.version,))
|
||||
# we require an introducer that speaks at least V2
|
||||
assert all(type(V2) == type(v) for v in publisher.version)
|
||||
if V2 not in publisher.version:
|
||||
raise InsufficientVersionError("V2", publisher.version)
|
||||
self._publisher = publisher
|
||||
|
@ -1,3 +1,4 @@
|
||||
from past.builtins import long
|
||||
|
||||
import time, os.path, textwrap
|
||||
from zope.interface import implementer
|
||||
@ -122,7 +123,7 @@ class _IntroducerNode(node.Node):
|
||||
|
||||
from allmydata.webish import IntroducerWebishServer
|
||||
nodeurl_path = self.config.get_config_path(u"node.url")
|
||||
config_staticdir = self.get_config("node", "web.static", "public_html").decode('utf-8')
|
||||
config_staticdir = self.get_config("node", "web.static", "public_html")
|
||||
staticdir = self.config.get_config_path(config_staticdir)
|
||||
ws = IntroducerWebishServer(self, webport, nodeurl_path, staticdir)
|
||||
ws.setServiceParent(self)
|
||||
@ -133,8 +134,8 @@ class IntroducerService(service.MultiService, Referenceable):
|
||||
# v1 is the original protocol, added in 1.0 (but only advertised starting
|
||||
# in 1.3), removed in 1.12. v2 is the new signed protocol, added in 1.10
|
||||
VERSION = { #"http://allmydata.org/tahoe/protocols/introducer/v1": { },
|
||||
"http://allmydata.org/tahoe/protocols/introducer/v2": { },
|
||||
"application-version": str(allmydata.__full_version__),
|
||||
b"http://allmydata.org/tahoe/protocols/introducer/v2": { },
|
||||
b"application-version": allmydata.__full_version__.encode("utf-8"),
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
|
@ -102,7 +102,7 @@ class Node(testutil.SignalMixin, testutil.ReallyEqualMixin, AsyncTestCase):
|
||||
q1 = yield create_introducer(basedir)
|
||||
del q1
|
||||
# new nodes create unguessable furls in private/introducer.furl
|
||||
ifurl = fileutil.read(private_fn)
|
||||
ifurl = fileutil.read(private_fn, mode="r")
|
||||
self.failUnless(ifurl)
|
||||
ifurl = ifurl.strip()
|
||||
self.failIf(ifurl.endswith("/introducer"), ifurl)
|
||||
@ -122,7 +122,7 @@ class Node(testutil.SignalMixin, testutil.ReallyEqualMixin, AsyncTestCase):
|
||||
q2 = yield create_introducer(basedir)
|
||||
del q2
|
||||
self.failIf(os.path.exists(public_fn))
|
||||
ifurl2 = fileutil.read(private_fn)
|
||||
ifurl2 = fileutil.read(private_fn, mode="r")
|
||||
self.failUnless(ifurl2)
|
||||
self.failUnlessEqual(ifurl2.strip(), guessable)
|
||||
|
||||
@ -422,7 +422,7 @@ class Queue(SystemTestMixin, AsyncTestCase):
|
||||
def _done(ign):
|
||||
v = introducer.get_announcements()[0]
|
||||
furl = v.announcement["anonymous-storage-FURL"]
|
||||
self.failUnlessEqual(furl, furl1)
|
||||
self.failUnlessEqual(ensure_binary(furl), furl1)
|
||||
d.addCallback(_done)
|
||||
|
||||
# now let the ack get back
|
||||
@ -448,7 +448,7 @@ class SystemTest(SystemTestMixin, AsyncTestCase):
|
||||
iff = os.path.join(self.basedir, "introducer.furl")
|
||||
tub = self.central_tub
|
||||
ifurl = self.central_tub.registerReference(introducer, furlFile=iff)
|
||||
self.introducer_furl = ifurl
|
||||
self.introducer_furl = ifurl.encode("utf-8")
|
||||
|
||||
# we have 5 clients who publish themselves as storage servers, and a
|
||||
# sixth which does which not. All 6 clients subscriber to hear about
|
||||
@ -489,7 +489,7 @@ class SystemTest(SystemTestMixin, AsyncTestCase):
|
||||
subscribing_clients.append(c)
|
||||
expected_announcements[i] += 1 # all expect a 'storage' announcement
|
||||
|
||||
node_furl = tub.registerReference(Referenceable())
|
||||
node_furl = tub.registerReference(Referenceable()).encode("utf-8")
|
||||
private_key, public_key = ed25519.create_signing_keypair()
|
||||
public_key_str = ed25519.string_from_verifying_key(public_key)
|
||||
privkeys[i] = private_key
|
||||
@ -506,7 +506,7 @@ class SystemTest(SystemTestMixin, AsyncTestCase):
|
||||
|
||||
if i == 2:
|
||||
# also publish something that nobody cares about
|
||||
boring_furl = tub.registerReference(Referenceable())
|
||||
boring_furl = tub.registerReference(Referenceable()).encode("utf-8")
|
||||
c.publish("boring", make_ann(boring_furl), private_key)
|
||||
|
||||
c.setServiceParent(self.parent)
|
||||
@ -987,10 +987,10 @@ class DecodeFurl(SyncTestCase):
|
||||
# make sure we have a working base64.b32decode. The one in
|
||||
# python2.4.[01] was broken.
|
||||
furl = b'pb://t5g7egomnnktbpydbuijt6zgtmw4oqi5@127.0.0.1:51857/hfzv36i'
|
||||
m = re.match(r'pb://(\w+)@', furl)
|
||||
m = re.match(br'pb://(\w+)@', furl)
|
||||
assert m
|
||||
nodeid = b32decode(m.group(1).upper())
|
||||
self.failUnlessEqual(nodeid, "\x9fM\xf2\x19\xcckU0\xbf\x03\r\x10\x99\xfb&\x9b-\xc7A\x1d")
|
||||
self.failUnlessEqual(nodeid, b"\x9fM\xf2\x19\xcckU0\xbf\x03\r\x10\x99\xfb&\x9b-\xc7A\x1d")
|
||||
|
||||
class Signatures(SyncTestCase):
|
||||
|
||||
@ -1002,11 +1002,11 @@ class Signatures(SyncTestCase):
|
||||
(msg, sig, key) = ann_t
|
||||
self.failUnlessEqual(type(msg), type("".encode("utf-8"))) # bytes
|
||||
self.failUnlessEqual(json.loads(msg.decode("utf-8")), ann)
|
||||
self.failUnless(sig.startswith("v0-"))
|
||||
self.failUnless(key.startswith("v0-"))
|
||||
self.failUnless(sig.startswith(b"v0-"))
|
||||
self.failUnless(key.startswith(b"v0-"))
|
||||
(ann2,key2) = unsign_from_foolscap(ann_t)
|
||||
self.failUnlessEqual(ann2, ann)
|
||||
self.failUnlessEqual("pub-" + key2, public_key_str)
|
||||
self.failUnlessEqual(b"pub-" + key2, public_key_str)
|
||||
|
||||
# not signed
|
||||
self.failUnlessRaises(UnknownKeyError,
|
||||
@ -1021,16 +1021,16 @@ class Signatures(SyncTestCase):
|
||||
|
||||
# unrecognized signatures
|
||||
self.failUnlessRaises(UnknownKeyError,
|
||||
unsign_from_foolscap, (bad_msg, "v999-sig", key))
|
||||
unsign_from_foolscap, (bad_msg, b"v999-sig", key))
|
||||
self.failUnlessRaises(UnknownKeyError,
|
||||
unsign_from_foolscap, (bad_msg, sig, "v999-key"))
|
||||
unsign_from_foolscap, (bad_msg, sig, b"v999-key"))
|
||||
|
||||
def test_unsigned_announcement(self):
|
||||
ed25519.verifying_key_from_string(b"pub-v0-wodst6ly4f7i7akt2nxizsmmy2rlmer6apltl56zctn67wfyu5tq")
|
||||
mock_tub = Mock()
|
||||
ic = IntroducerClient(
|
||||
mock_tub,
|
||||
u"pb://",
|
||||
b"pb://",
|
||||
u"fake_nick",
|
||||
"0.0.0",
|
||||
"1.2.3",
|
||||
@ -1040,7 +1040,7 @@ class Signatures(SyncTestCase):
|
||||
)
|
||||
self.assertEqual(0, ic._debug_counts["inbound_announcement"])
|
||||
ic.got_announcements([
|
||||
("message", "v0-aaaaaaa", "v0-wodst6ly4f7i7akt2nxizsmmy2rlmer6apltl56zctn67wfyu5tq")
|
||||
(b"message", b"v0-aaaaaaa", b"v0-wodst6ly4f7i7akt2nxizsmmy2rlmer6apltl56zctn67wfyu5tq")
|
||||
])
|
||||
# we should have rejected this announcement due to a bad signature
|
||||
self.assertEqual(0, ic._debug_counts["inbound_announcement"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user