mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
Completed Santiago.handle_request's tests.
This commit is contained in:
parent
88d35a83ca
commit
29a1b41996
@ -169,7 +169,8 @@ class Santiago(object):
|
|||||||
"""Learn a service somebody else hosts for me."""
|
"""Learn a service somebody else hosts for me."""
|
||||||
|
|
||||||
if locations:
|
if locations:
|
||||||
self.consuming[service][host].union(locations)
|
self.consuming[service][host] = (
|
||||||
|
self.consuming[service][host] | locations)
|
||||||
|
|
||||||
def provide_service(self, client, service, locations):
|
def provide_service(self, client, service, locations):
|
||||||
"""Start hosting a service for somebody else."""
|
"""Start hosting a service for somebody else."""
|
||||||
@ -367,9 +368,11 @@ class Santiago(object):
|
|||||||
- Reply to the client on the appropriate protocol.
|
- Reply to the client on the appropriate protocol.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
# return if we won't host for the proxy or the client.
|
||||||
if False in map(self.hosting.__contains__, (from_, client)):
|
if False in map(self.hosting.__contains__, (from_, client)):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# if we don't proxy, learn new reply locations and send the request.
|
||||||
if not self.i_am(host):
|
if not self.i_am(host):
|
||||||
self.proxy(to, host, client, service, reply_to)
|
self.proxy(to, host, client, service, reply_to)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -39,7 +39,6 @@ If I produce a listener that just echoes the parameters, I can validate the resp
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
@ -559,7 +558,7 @@ class UnpackRequest(unittest.TestCase):
|
|||||||
|
|
||||||
The really odd ones out are "locations" and "reply_to", which fall into
|
The really odd ones out are "locations" and "reply_to", which fall into
|
||||||
all three categories.
|
all three categories.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Create a request."""
|
"""Create a request."""
|
||||||
@ -568,7 +567,7 @@ class UnpackRequest(unittest.TestCase):
|
|||||||
|
|
||||||
self.keyid = utilities.load_config().get("pgpprocessor", "keyid")
|
self.keyid = utilities.load_config().get("pgpprocessor", "keyid")
|
||||||
|
|
||||||
self.santiago = santiago.Santiago()
|
self.santiago = santiago.Santiago(me = self.keyid)
|
||||||
|
|
||||||
self.request = { "host": self.keyid, "client": self.keyid,
|
self.request = { "host": self.keyid, "client": self.keyid,
|
||||||
"service": "santiago", "reply_to": [1],
|
"service": "santiago", "reply_to": [1],
|
||||||
@ -585,14 +584,27 @@ class UnpackRequest(unittest.TestCase):
|
|||||||
def test_valid_message(self):
|
def test_valid_message(self):
|
||||||
"""A message that should pass does pass normally."""
|
"""A message that should pass does pass normally."""
|
||||||
|
|
||||||
self.fail()
|
adict = self.validate_request(dict(self.request))
|
||||||
|
self.request = self.wrap_message(self.request)
|
||||||
|
|
||||||
|
self.assertEqual(self.santiago.unpack_request(str(self.request)), adict)
|
||||||
|
|
||||||
|
def validate_request(self, adict):
|
||||||
|
# convert non-None elements to sets, like unpack does.
|
||||||
|
adict.update(dict([ (k, set(adict[k])) for
|
||||||
|
k in self.LIST_KEYS
|
||||||
|
if adict[k] is not None ]))
|
||||||
|
adict.update({ "from": self.keyid,
|
||||||
|
"to": self.keyid })
|
||||||
|
|
||||||
|
return adict
|
||||||
|
|
||||||
def test_request_contains_all_keys(self):
|
def test_request_contains_all_keys(self):
|
||||||
"""The test request needs all supported keys."""
|
"""The test request needs all supported keys."""
|
||||||
|
|
||||||
for key in self.ALL_KEYS:
|
for key in self.ALL_KEYS:
|
||||||
self.assertTrue(key in self.request)
|
self.assertTrue(key in self.request)
|
||||||
|
|
||||||
def wrap_message(self, message):
|
def wrap_message(self, message):
|
||||||
"""The standard wrapping method for these tests."""
|
"""The standard wrapping method for these tests."""
|
||||||
|
|
||||||
@ -612,7 +624,7 @@ class UnpackRequest(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(set(self.ALL_KEYS),
|
self.assertEqual(set(self.ALL_KEYS),
|
||||||
set(self.REQUIRED_KEYS) | set(self.OPTIONAL_KEYS))
|
set(self.REQUIRED_KEYS) | set(self.OPTIONAL_KEYS))
|
||||||
|
|
||||||
def test_requred_keys_are_required(self):
|
def test_requred_keys_are_required(self):
|
||||||
"""If any required keys are missing, the message is skipped."""
|
"""If any required keys are missing, the message is skipped."""
|
||||||
|
|
||||||
@ -645,12 +657,7 @@ class UnpackRequest(unittest.TestCase):
|
|||||||
broken_dict[key] = None
|
broken_dict[key] = None
|
||||||
encrypted_data = str(self.wrap_message(str(broken_dict)))
|
encrypted_data = str(self.wrap_message(str(broken_dict)))
|
||||||
|
|
||||||
# convert non-None elements to sets, like unpack does.
|
broken_dict = self.validate_request(broken_dict)
|
||||||
broken_dict.update(dict([ (k, set(broken_dict[k])) for
|
|
||||||
k in self.LIST_KEYS
|
|
||||||
if broken_dict[k] is not None ]))
|
|
||||||
broken_dict.update({ "from": self.keyid,
|
|
||||||
"to": 0 })
|
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.santiago.unpack_request(encrypted_data),
|
self.santiago.unpack_request(encrypted_data),
|
||||||
@ -685,7 +692,7 @@ class UnpackRequest(unittest.TestCase):
|
|||||||
broken_request = self.wrap_message(str(broken_request))
|
broken_request = self.wrap_message(str(broken_request))
|
||||||
|
|
||||||
self.assertEqual(self.santiago.unpack_request(broken_request), None)
|
self.assertEqual(self.santiago.unpack_request(broken_request), None)
|
||||||
|
|
||||||
def test_sets_are_sets(self):
|
def test_sets_are_sets(self):
|
||||||
"""Any variables that must be sets, after processing, actually are."""
|
"""Any variables that must be sets, after processing, actually are."""
|
||||||
|
|
||||||
@ -767,15 +774,22 @@ class HandleRequest(unittest.TestCase):
|
|||||||
def test_unwilling_proxy(self):
|
def test_unwilling_proxy(self):
|
||||||
"""Don't handle the request if the proxy isn't trusted."""
|
"""Don't handle the request if the proxy isn't trusted."""
|
||||||
|
|
||||||
self.fail()
|
self.from_ = 0
|
||||||
|
|
||||||
|
self.test_call()
|
||||||
|
|
||||||
self.assertFalse(self.santiago.requested)
|
self.assertFalse(self.santiago.requested)
|
||||||
|
|
||||||
def test_learn_services(self):
|
def test_learn_services(self):
|
||||||
"""New reply_to locations are learned."""
|
"""New reply_to locations are learned."""
|
||||||
|
|
||||||
self.fail()
|
self.reply_to.update([2])
|
||||||
|
|
||||||
|
self.test_call()
|
||||||
|
|
||||||
|
self.assertTrue(self.santiago.requested)
|
||||||
|
self.assertEqual(self.santiago.consuming["santiago"][self.keyid],
|
||||||
|
set([1, 2]))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user