Skip to content

Commit

Permalink
TLS connect fail to correct port
Browse files Browse the repository at this point in the history
Signed-off-by: John Andersen <[email protected]>
  • Loading branch information
pdxjohnny committed Nov 4, 2023
1 parent 836bc08 commit 36399cc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion scitt_emulator/federation_activitypub_bovine.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,4 @@ async def loop(client_name, client_config, handlers):
except Exception as e:
logger.exception("Something went wrong for %s", client_name)
logger.exception(e)
await asyncio.sleep(60)
await asyncio.sleep(1)
39 changes: 29 additions & 10 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,25 @@
old_create_sockets = hypercorn.config.Config.create_sockets


def socket_getaddrinfo_map_service_ports(services, host, *args, **kwargs):
# Map f"scitt.{handle_name}.example.com" to various local ports
if "scitt." not in host:
return old_socket_getaddrinfo(host, *args, **kwargs)
_, handle_name, _, _ = host.split(".")
def load_services_from_services_path(services):
if isinstance(services, (str, pathlib.Path)):
services_path = pathlib.Path(services)
if not services_path.exists():
return old_socket_getaddrinfo(host, *args, **kwargs)
services_content = services_path.read_text()
services_dict = json.loads(services_content)
services = {
handle_name: types.SimpleNameSpace(**service_dict)
for handle_name, service_dict in service_dict.items()
handle_name: types.SimpleNamespace(**service_dict)
for handle_name, service_dict in services_dict.items()
}
return services

def socket_getaddrinfo_map_service_ports(services, host, *args, **kwargs):
# Map f"scitt.{handle_name}.example.com" to various local ports
if "scitt." not in host:
return old_socket_getaddrinfo(host, *args, **kwargs)
_, handle_name, _, _ = host.split(".")
services = load_services_from_services_path(services)
return [
(
socket.AF_INET,
Expand Down Expand Up @@ -91,10 +97,23 @@ def __exit__(self, *args):
def server_process(app, addr_queue, services):
try:
class MockResolver(aiohttp.resolver.DefaultResolver):
async def resolve(self, *args, **kwargs):
async def resolve(self, host, *args, **kwargs):
nonlocal services
print("MockResolver.getaddrinfo")
return socket_getaddrinfo_map_service_ports(services, *args, **kwargs)
if "scitt." not in host:
return old_socket_getaddrinfo(host, *args, **kwargs)
_, handle_name, _, _ = host.split(".")
services = load_services_from_services_path(services)
return [
{
"hostname": host,
"host": "127.0.0.1",
"port": services[handle_name].port,
"family": socket.AF_INET,
"proto": socket.SOCK_STREAM,
"flags": socket.AI_ADDRCONFIG,
}
]

with contextlib.ExitStack() as exit_stack:
exit_stack.enter_context(
unittest.mock.patch(
Expand Down

0 comments on commit 36399cc

Please sign in to comment.