MCPcopy Index your code
hub / github.com/HelloZeroNet/ZeroNet / testConnection

Method testConnection

src/Test/TestTor.py:53–81  ·  view source on GitHub ↗
(self, tor_manager, file_server, site, site_temp)

Source from the content-addressed store, hash-verified

51
52 @pytest.mark.slow
53 def testConnection(self, tor_manager, file_server, site, site_temp):
54 file_server.tor_manager.start_onions = True
55 address = file_server.tor_manager.getOnion(site.address)
56 assert address
57 print("Connecting to", address)
58 for retry in range(5): # Wait for hidden service creation
59 time.sleep(10)
60 try:
61 connection = file_server.getConnection(address + ".onion", 1544)
62 if connection:
63 break
64 except Exception as err:
65 continue
66 assert connection.handshake
67 assert not connection.handshake["peer_id"] # No peer_id for Tor connections
68
69 # Return the same connection without site specified
70 assert file_server.getConnection(address + ".onion", 1544) == connection
71 # No reuse for different site
72 assert file_server.getConnection(address + ".onion", 1544, site=site) != connection
73 assert file_server.getConnection(address + ".onion", 1544, site=site) == file_server.getConnection(address + ".onion", 1544, site=site)
74 site_temp.address = "1OTHERSITE"
75 assert file_server.getConnection(address + ".onion", 1544, site=site) != file_server.getConnection(address + ".onion", 1544, site=site_temp)
76
77 # Only allow to query from the locked site
78 file_server.sites[site.address] = site
79 connection_locked = file_server.getConnection(address + ".onion", 1544, site=site)
80 assert "body" in connection_locked.request("getFile", {"site": site.address, "inner_path": "content.json", "location": 0})
81 assert connection_locked.request("getFile", {"site": "1OTHERSITE", "inner_path": "content.json", "location": 0})["error"] == "Invalid site"
82
83 def testPex(self, file_server, site, site_temp):
84 # Register site to currently running fileserver

Callers

nothing calls this directly

Calls 3

getOnionMethod · 0.80
getConnectionMethod · 0.80
requestMethod · 0.45

Tested by

no test coverage detected