Make network test compatible with ipv6
This commit is contained in:
parent
468666cdc8
commit
44dc3035a5
5 changed files with 100 additions and 95 deletions
|
@ -1,4 +1,5 @@
|
|||
import time
|
||||
import socket
|
||||
import gevent
|
||||
|
||||
import pytest
|
||||
|
@ -11,19 +12,38 @@ from Config import config
|
|||
|
||||
@pytest.mark.usefixtures("resetSettings")
|
||||
class TestConnection:
|
||||
def testIpv6(self, file_server6):
|
||||
assert ":" in file_server6.ip
|
||||
|
||||
client = ConnectionServer(file_server6.ip, 1545)
|
||||
connection = client.getConnection(file_server6.ip, 1544)
|
||||
|
||||
assert connection.ping()
|
||||
|
||||
# Close connection
|
||||
connection.close()
|
||||
client.stop()
|
||||
time.sleep(0.01)
|
||||
assert len(file_server6.connections) == 0
|
||||
|
||||
# Should not able to reach on ipv4 ip
|
||||
with pytest.raises(socket.error) as err:
|
||||
client = ConnectionServer("127.0.0.1", 1545)
|
||||
connection = client.getConnection("127.0.0.1", 1544)
|
||||
|
||||
def testSslConnection(self, file_server):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
client = ConnectionServer("127.0.0.1", 1545)
|
||||
client = ConnectionServer(file_server.ip, 1545)
|
||||
assert file_server != client
|
||||
|
||||
# Connect to myself
|
||||
with mock.patch('Config.config.ip_local', return_value=[]): # SSL not used for local ips
|
||||
connection = client.getConnection("127.0.0.1", 1544)
|
||||
connection = client.getConnection(file_server.ip, 1544)
|
||||
|
||||
assert len(file_server.connections) == 1
|
||||
assert connection.handshake
|
||||
assert connection.crypt
|
||||
|
||||
|
||||
# Close connection
|
||||
connection.close()
|
||||
client.stop()
|
||||
|
@ -31,17 +51,15 @@ class TestConnection:
|
|||
assert len(file_server.connections) == 0
|
||||
|
||||
def testRawConnection(self, file_server):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
client = ConnectionServer("127.0.0.1", 1545)
|
||||
client = ConnectionServer(file_server.ip, 1545)
|
||||
assert file_server != client
|
||||
|
||||
# Remove all supported crypto
|
||||
crypt_supported_bk = CryptConnection.manager.crypt_supported
|
||||
CryptConnection.manager.crypt_supported = []
|
||||
|
||||
print "---"
|
||||
with mock.patch('Config.config.ip_local', return_value=[]): # SSL not used for local ips
|
||||
connection = client.getConnection("127.0.0.1", 1544)
|
||||
connection = client.getConnection(file_server.ip, 1544)
|
||||
assert len(file_server.connections) == 1
|
||||
assert not connection.crypt
|
||||
|
||||
|
@ -55,9 +73,8 @@ class TestConnection:
|
|||
CryptConnection.manager.crypt_supported = crypt_supported_bk
|
||||
|
||||
def testPing(self, file_server, site):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
client = ConnectionServer("127.0.0.1", 1545)
|
||||
connection = client.getConnection("127.0.0.1", 1544)
|
||||
client = ConnectionServer(file_server.ip, 1545)
|
||||
connection = client.getConnection(file_server.ip, 1544)
|
||||
|
||||
assert connection.ping()
|
||||
|
||||
|
@ -65,38 +82,36 @@ class TestConnection:
|
|||
client.stop()
|
||||
|
||||
def testGetConnection(self, file_server):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
client = ConnectionServer("127.0.0.1", 1545)
|
||||
connection = client.getConnection("127.0.0.1", 1544)
|
||||
client = ConnectionServer(file_server.ip, 1545)
|
||||
connection = client.getConnection(file_server.ip, 1544)
|
||||
|
||||
# Get connection by ip/port
|
||||
connection2 = client.getConnection("127.0.0.1", 1544)
|
||||
connection2 = client.getConnection(file_server.ip, 1544)
|
||||
assert connection == connection2
|
||||
|
||||
# Get connection by peerid
|
||||
assert not client.getConnection("127.0.0.1", 1544, peer_id="notexists", create=False)
|
||||
connection2 = client.getConnection("127.0.0.1", 1544, peer_id=connection.handshake["peer_id"], create=False)
|
||||
assert not client.getConnection(file_server.ip, 1544, peer_id="notexists", create=False)
|
||||
connection2 = client.getConnection(file_server.ip, 1544, peer_id=connection.handshake["peer_id"], create=False)
|
||||
assert connection2 == connection
|
||||
|
||||
connection.close()
|
||||
client.stop()
|
||||
|
||||
def testFloodProtection(self, file_server):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
whitelist = file_server.whitelist # Save for reset
|
||||
file_server.whitelist = [] # Disable 127.0.0.1 whitelist
|
||||
client = ConnectionServer("127.0.0.1", 1545)
|
||||
client = ConnectionServer(file_server.ip, 1545)
|
||||
|
||||
# Only allow 6 connection in 1 minute
|
||||
for reconnect in range(6):
|
||||
connection = client.getConnection("127.0.0.1", 1544)
|
||||
connection = client.getConnection(file_server.ip, 1544)
|
||||
assert connection.handshake
|
||||
connection.close()
|
||||
|
||||
# The 7. one will timeout
|
||||
with pytest.raises(gevent.Timeout):
|
||||
with gevent.Timeout(0.1):
|
||||
connection = client.getConnection("127.0.0.1", 1544)
|
||||
connection = client.getConnection(file_server.ip, 1544)
|
||||
|
||||
# Reset whitelist
|
||||
file_server.whitelist = whitelist
|
||||
|
|
|
@ -13,9 +13,9 @@ from File import FileServer
|
|||
class TestFileRequest:
|
||||
def testGetFile(self, file_server, site):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
client = ConnectionServer("127.0.0.1", 1545)
|
||||
client = ConnectionServer(file_server.ip, 1545)
|
||||
|
||||
connection = client.getConnection("127.0.0.1", 1544)
|
||||
connection = client.getConnection(file_server.ip, 1544)
|
||||
file_server.sites[site.address] = site
|
||||
|
||||
# Normal request
|
||||
|
@ -53,8 +53,8 @@ class TestFileRequest:
|
|||
|
||||
def testStreamFile(self, file_server, site):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
client = ConnectionServer("127.0.0.1", 1545)
|
||||
connection = client.getConnection("127.0.0.1", 1544)
|
||||
client = ConnectionServer(file_server.ip, 1545)
|
||||
connection = client.getConnection(file_server.ip, 1544)
|
||||
file_server.sites[site.address] = site
|
||||
|
||||
buff = StringIO.StringIO()
|
||||
|
@ -84,24 +84,24 @@ class TestFileRequest:
|
|||
|
||||
def testPex(self, file_server, site, site_temp):
|
||||
file_server.sites[site.address] = site
|
||||
client = FileServer("127.0.0.1", 1545)
|
||||
client = FileServer(file_server.ip, 1545)
|
||||
client.sites[site_temp.address] = site_temp
|
||||
site_temp.connection_server = client
|
||||
connection = client.getConnection("127.0.0.1", 1544)
|
||||
connection = client.getConnection(file_server.ip, 1544)
|
||||
|
||||
# Add new fake peer to site
|
||||
fake_peer = site.addPeer("1.2.3.4", 11337, return_peer=True)
|
||||
fake_peer = site.addPeer(file_server.ip_external, 11337, return_peer=True)
|
||||
# Add fake connection to it
|
||||
fake_peer.connection = Connection(file_server, "1.2.3.4", 11337)
|
||||
fake_peer.connection = Connection(file_server, file_server.ip_external, 11337)
|
||||
fake_peer.connection.last_recv_time = time.time()
|
||||
assert fake_peer in site.getConnectablePeers()
|
||||
|
||||
# Add file_server as peer to client
|
||||
peer_file_server = site_temp.addPeer("127.0.0.1", 1544)
|
||||
peer_file_server = site_temp.addPeer(file_server.ip, 1544)
|
||||
|
||||
assert "1.2.3.4:11337" not in site_temp.peers
|
||||
assert "%s:11337" % file_server.ip_external not in site_temp.peers
|
||||
assert peer_file_server.pex()
|
||||
assert "1.2.3.4:11337" in site_temp.peers
|
||||
assert "%s:11337" % file_server.ip_external in site_temp.peers
|
||||
|
||||
# Should not exchange private peers from local network
|
||||
fake_peer_private = site.addPeer("192.168.0.1", 11337, return_peer=True)
|
||||
|
|
|
@ -13,15 +13,14 @@ import Spy
|
|||
@pytest.mark.usefixtures("resetTempSettings")
|
||||
class TestPeer:
|
||||
def testPing(self, file_server, site, site_temp):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
file_server.sites[site.address] = site
|
||||
client = FileServer("127.0.0.1", 1545)
|
||||
client = FileServer(file_server.ip, 1545)
|
||||
client.sites[site_temp.address] = site_temp
|
||||
site_temp.connection_server = client
|
||||
connection = client.getConnection("127.0.0.1", 1544)
|
||||
connection = client.getConnection(file_server.ip, 1544)
|
||||
|
||||
# Add file_server as peer to client
|
||||
peer_file_server = site_temp.addPeer("127.0.0.1", 1544)
|
||||
peer_file_server = site_temp.addPeer(file_server.ip, 1544)
|
||||
|
||||
assert peer_file_server.ping() is not None
|
||||
|
||||
|
@ -33,15 +32,14 @@ class TestPeer:
|
|||
client.stop()
|
||||
|
||||
def testDownloadFile(self, file_server, site, site_temp):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
file_server.sites[site.address] = site
|
||||
client = FileServer("127.0.0.1", 1545)
|
||||
client = FileServer(file_server.ip, 1545)
|
||||
client.sites[site_temp.address] = site_temp
|
||||
site_temp.connection_server = client
|
||||
connection = client.getConnection("127.0.0.1", 1544)
|
||||
connection = client.getConnection(file_server.ip, 1544)
|
||||
|
||||
# Add file_server as peer to client
|
||||
peer_file_server = site_temp.addPeer("127.0.0.1", 1544)
|
||||
peer_file_server = site_temp.addPeer(file_server.ip, 1544)
|
||||
|
||||
# Testing streamFile
|
||||
buff = peer_file_server.getFile(site_temp.address, "content.json", streaming=True)
|
||||
|
@ -79,15 +77,16 @@ class TestPeer:
|
|||
|
||||
def testHashfieldExchange(self, file_server, site, site_temp):
|
||||
server1 = file_server
|
||||
server1.ip_incoming = {} # Reset flood protection
|
||||
server1.sites[site.address] = site
|
||||
server2 = FileServer("127.0.0.1", 1545)
|
||||
site.connection_server = server1
|
||||
|
||||
server2 = FileServer(file_server.ip, 1545)
|
||||
server2.sites[site_temp.address] = site_temp
|
||||
site_temp.connection_server = server2
|
||||
site.storage.verifyFiles(quick_check=True) # Find what optional files we have
|
||||
|
||||
# Add file_server as peer to client
|
||||
server2_peer1 = site_temp.addPeer("127.0.0.1", 1544)
|
||||
server2_peer1 = site_temp.addPeer(file_server.ip, 1544)
|
||||
|
||||
# Check if hashfield has any files
|
||||
assert len(site.content_manager.hashfield) > 0
|
||||
|
@ -99,7 +98,7 @@ class TestPeer:
|
|||
|
||||
# Test force push new hashfield
|
||||
site_temp.content_manager.hashfield.appendHash("AABB")
|
||||
server1_peer2 = site.addPeer("127.0.0.1", 1545, return_peer=True)
|
||||
server1_peer2 = site.addPeer(file_server.ip, 1545, return_peer=True)
|
||||
with Spy.Spy(FileRequest, "route") as requests:
|
||||
assert len(server1_peer2.hashfield) == 0
|
||||
server2_peer1.sendMyHashfield()
|
||||
|
@ -128,19 +127,18 @@ class TestPeer:
|
|||
server2.stop()
|
||||
|
||||
def testFindHash(self, file_server, site, site_temp):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
file_server.sites[site.address] = site
|
||||
client = FileServer("127.0.0.1", 1545)
|
||||
client = FileServer(file_server.ip, 1545)
|
||||
client.sites[site_temp.address] = site_temp
|
||||
site_temp.connection_server = client
|
||||
|
||||
# Add file_server as peer to client
|
||||
peer_file_server = site_temp.addPeer("127.0.0.1", 1544)
|
||||
peer_file_server = site_temp.addPeer(file_server.ip, 1544)
|
||||
|
||||
assert peer_file_server.findHashIds([1234]) == {}
|
||||
|
||||
# Add fake peer with requred hash
|
||||
fake_peer_1 = site.addPeer("1.2.3.4", 1544)
|
||||
fake_peer_1 = site.addPeer(file_server.ip_external, 1544)
|
||||
fake_peer_1.hashfield.append(1234)
|
||||
fake_peer_2 = site.addPeer("1.2.3.5", 1545)
|
||||
fake_peer_2.hashfield.append(1234)
|
||||
|
@ -149,14 +147,13 @@ class TestPeer:
|
|||
fake_peer_3.hashfield.append(1235)
|
||||
fake_peer_3.hashfield.append(1236)
|
||||
|
||||
assert peer_file_server.findHashIds([1234, 1235]) == {
|
||||
1234: [('1.2.3.4', 1544), ('1.2.3.5', 1545)],
|
||||
1235: [('1.2.3.5', 1545), ('1.2.3.6', 1546)]
|
||||
}
|
||||
res = peer_file_server.findHashIds([1234, 1235])
|
||||
assert sorted(res[1234]) == sorted([(file_server.ip_external, 1544), ("1.2.3.5", 1545)])
|
||||
assert sorted(res[1235]) == sorted([("1.2.3.5", 1545), ("1.2.3.6", 1546)])
|
||||
|
||||
# Test my address adding
|
||||
site.content_manager.hashfield.append(1234)
|
||||
|
||||
res = peer_file_server.findHashIds([1234, 1235])
|
||||
assert res[1234] == [('1.2.3.4', 1544), ('1.2.3.5', 1545), ("127.0.0.1", 1544)]
|
||||
assert res[1235] == [('1.2.3.5', 1545), ('1.2.3.6', 1546)]
|
||||
assert sorted(res[1234]) == sorted([(file_server.ip_external, 1544), ("1.2.3.5", 1545), (file_server.ip, 1544)])
|
||||
assert sorted(res[1235]) == sorted([("1.2.3.5", 1545), ("1.2.3.6", 1546)])
|
||||
|
|
|
@ -16,8 +16,6 @@ import Spy
|
|||
@pytest.mark.usefixtures("resetSettings")
|
||||
class TestSiteDownload:
|
||||
def testDownload(self, file_server, site, site_temp):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
|
||||
assert site.storage.directory == config.data_dir + "/" + site.address
|
||||
assert site_temp.storage.directory == config.data_dir + "-temp/" + site.address
|
||||
|
||||
|
@ -26,11 +24,11 @@ class TestSiteDownload:
|
|||
file_server.sites[site.address] = site
|
||||
|
||||
# Init client server
|
||||
client = ConnectionServer("127.0.0.1", 1545)
|
||||
client = ConnectionServer(file_server.ip, 1545)
|
||||
site_temp.connection_server = client
|
||||
site_temp.announce = mock.MagicMock(return_value=True) # Don't try to find peers from the net
|
||||
|
||||
site_temp.addPeer("127.0.0.1", 1544)
|
||||
site_temp.addPeer(file_server.ip, 1544)
|
||||
with Spy.Spy(FileRequest, "route") as requests:
|
||||
def boostRequest(inner_path):
|
||||
# I really want these file
|
||||
|
@ -58,19 +56,17 @@ class TestSiteDownload:
|
|||
[connection.close() for connection in file_server.connections]
|
||||
|
||||
def testArchivedDownload(self, file_server, site, site_temp):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
|
||||
# Init source server
|
||||
site.connection_server = file_server
|
||||
file_server.sites[site.address] = site
|
||||
|
||||
# Init client server
|
||||
client = FileServer("127.0.0.1", 1545)
|
||||
client = FileServer(file_server.ip, 1545)
|
||||
client.sites[site_temp.address] = site_temp
|
||||
site_temp.connection_server = client
|
||||
|
||||
# Download normally
|
||||
site_temp.addPeer("127.0.0.1", 1544)
|
||||
site_temp.addPeer(file_server.ip, 1544)
|
||||
site_temp.download(blind_includes=True).join(timeout=5)
|
||||
bad_files = site_temp.storage.verifyFiles(quick_check=True)["bad_files"]
|
||||
|
||||
|
@ -108,19 +104,17 @@ class TestSiteDownload:
|
|||
[connection.close() for connection in file_server.connections]
|
||||
|
||||
def testArchivedBeforeDownload(self, file_server, site, site_temp):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
|
||||
# Init source server
|
||||
site.connection_server = file_server
|
||||
file_server.sites[site.address] = site
|
||||
|
||||
# Init client server
|
||||
client = FileServer("127.0.0.1", 1545)
|
||||
client = FileServer(file_server.ip, 1545)
|
||||
client.sites[site_temp.address] = site_temp
|
||||
site_temp.connection_server = client
|
||||
|
||||
# Download normally
|
||||
site_temp.addPeer("127.0.0.1", 1544)
|
||||
site_temp.addPeer(file_server.ip, 1544)
|
||||
site_temp.download(blind_includes=True).join(timeout=5)
|
||||
bad_files = site_temp.storage.verifyFiles(quick_check=True)["bad_files"]
|
||||
|
||||
|
@ -161,18 +155,16 @@ class TestSiteDownload:
|
|||
|
||||
# Test when connected peer has the optional file
|
||||
def testOptionalDownload(self, file_server, site, site_temp):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
|
||||
# Init source server
|
||||
site.connection_server = file_server
|
||||
file_server.sites[site.address] = site
|
||||
|
||||
# Init client server
|
||||
client = ConnectionServer("127.0.0.1", 1545)
|
||||
client = ConnectionServer(file_server.ip, 1545)
|
||||
site_temp.connection_server = client
|
||||
site_temp.announce = mock.MagicMock(return_value=True) # Don't try to find peers from the net
|
||||
|
||||
site_temp.addPeer("127.0.0.1", 1544)
|
||||
site_temp.addPeer(file_server.ip, 1544)
|
||||
|
||||
# Download site
|
||||
site_temp.download(blind_includes=True).join(timeout=5)
|
||||
|
@ -205,15 +197,13 @@ class TestSiteDownload:
|
|||
|
||||
# Test when connected peer does not has the file, so ask him if he know someone who has it
|
||||
def testFindOptional(self, file_server, site, site_temp):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
|
||||
# Init source server
|
||||
site.connection_server = file_server
|
||||
file_server.sites[site.address] = site
|
||||
|
||||
# Init full source server (has optional files)
|
||||
site_full = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
|
||||
file_server_full = FileServer("127.0.0.1", 1546)
|
||||
file_server_full = FileServer(file_server.ip, 1546)
|
||||
site_full.connection_server = file_server_full
|
||||
|
||||
def listen():
|
||||
|
@ -224,7 +214,7 @@ class TestSiteDownload:
|
|||
time.sleep(0.001) # Port opening
|
||||
file_server_full.sites[site_full.address] = site_full # Add site
|
||||
site_full.storage.verifyFiles(quick_check=True) # Check optional files
|
||||
site_full_peer = site.addPeer("127.0.0.1", 1546) # Add it to source server
|
||||
site_full_peer = site.addPeer(file_server.ip, 1546) # Add it to source server
|
||||
hashfield = site_full_peer.updateHashfield() # Update hashfield
|
||||
assert len(site_full.content_manager.hashfield) == 8
|
||||
assert hashfield
|
||||
|
@ -237,8 +227,8 @@ class TestSiteDownload:
|
|||
site.content_manager.hashfield.remove(hash)
|
||||
|
||||
# Init client server
|
||||
site_temp.connection_server = ConnectionServer("127.0.0.1", 1545)
|
||||
site_temp.addPeer("127.0.0.1", 1544) # Add source server
|
||||
site_temp.connection_server = ConnectionServer(file_server.ip, 1545)
|
||||
site_temp.addPeer(file_server.ip, 1544) # Add source server
|
||||
|
||||
# Download normal files
|
||||
site_temp.log.info("Start Downloading site")
|
||||
|
@ -272,10 +262,9 @@ class TestSiteDownload:
|
|||
assert site_temp.storage.deleteFiles()
|
||||
file_server_full.stop()
|
||||
[connection.close() for connection in file_server.connections]
|
||||
site_full.content_manager.contents.db.close()
|
||||
|
||||
def testUpdate(self, file_server, site, site_temp):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
|
||||
assert site.storage.directory == config.data_dir + "/" + site.address
|
||||
assert site_temp.storage.directory == config.data_dir + "-temp/" + site.address
|
||||
|
||||
|
@ -284,7 +273,7 @@ class TestSiteDownload:
|
|||
file_server.sites[site.address] = site
|
||||
|
||||
# Init client server
|
||||
client = FileServer("127.0.0.1", 1545)
|
||||
client = FileServer(file_server.ip, 1545)
|
||||
client.sites[site_temp.address] = site_temp
|
||||
site_temp.connection_server = client
|
||||
|
||||
|
@ -293,7 +282,7 @@ class TestSiteDownload:
|
|||
site_temp.announce = mock.MagicMock(return_value=True)
|
||||
|
||||
# Connect peers
|
||||
site_temp.addPeer("127.0.0.1", 1544)
|
||||
site_temp.addPeer(file_server.ip, 1544)
|
||||
|
||||
# Download site from site to site_temp
|
||||
site_temp.download(blind_includes=True).join(timeout=5)
|
||||
|
@ -321,7 +310,7 @@ class TestSiteDownload:
|
|||
|
||||
# Close connection to avoid update spam limit
|
||||
site.peers.values()[0].remove()
|
||||
site.addPeer("127.0.0.1", 1545)
|
||||
site.addPeer(file_server.ip, 1545)
|
||||
site_temp.peers.values()[0].ping() # Connect back
|
||||
time.sleep(0.1)
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import pytest
|
||||
import time
|
||||
|
||||
import pytest
|
||||
import mock
|
||||
|
||||
from File import FileServer
|
||||
from Crypt import CryptRsa
|
||||
from Config import config
|
||||
|
||||
@pytest.mark.usefixtures("resetSettings")
|
||||
@pytest.mark.usefixtures("resetTempSettings")
|
||||
|
@ -55,25 +58,25 @@ class TestTor:
|
|||
for retry in range(5): # Wait for hidden service creation
|
||||
time.sleep(10)
|
||||
try:
|
||||
connection = file_server.getConnection(address+".onion", 1544)
|
||||
connection = file_server.getConnection(address + ".onion", 1544)
|
||||
if connection:
|
||||
break
|
||||
except Exception, err:
|
||||
except Exception as err:
|
||||
continue
|
||||
assert connection.handshake
|
||||
assert not connection.handshake["peer_id"] # No peer_id for Tor connections
|
||||
|
||||
# Return the same connection without site specified
|
||||
assert file_server.getConnection(address+".onion", 1544) == connection
|
||||
assert file_server.getConnection(address + ".onion", 1544) == connection
|
||||
# No reuse for different site
|
||||
assert file_server.getConnection(address+".onion", 1544, site=site) != connection
|
||||
assert file_server.getConnection(address+".onion", 1544, site=site) == file_server.getConnection(address+".onion", 1544, site=site)
|
||||
assert file_server.getConnection(address + ".onion", 1544, site=site) != connection
|
||||
assert file_server.getConnection(address + ".onion", 1544, site=site) == file_server.getConnection(address + ".onion", 1544, site=site)
|
||||
site_temp.address = "1OTHERSITE"
|
||||
assert file_server.getConnection(address+".onion", 1544, site=site) != file_server.getConnection(address+".onion", 1544, site=site_temp)
|
||||
assert file_server.getConnection(address + ".onion", 1544, site=site) != file_server.getConnection(address + ".onion", 1544, site=site_temp)
|
||||
|
||||
# Only allow to query from the locked site
|
||||
file_server.sites[site.address] = site
|
||||
connection_locked = file_server.getConnection(address+".onion", 1544, site=site)
|
||||
connection_locked = file_server.getConnection(address + ".onion", 1544, site=site)
|
||||
assert "body" in connection_locked.request("getFile", {"site": site.address, "inner_path": "content.json", "location": 0})
|
||||
assert connection_locked.request("getFile", {"site": "1OTHERSITE", "inner_path": "content.json", "location": 0})["error"] == "Invalid site"
|
||||
|
||||
|
@ -82,12 +85,12 @@ class TestTor:
|
|||
site.connection_server = file_server
|
||||
file_server.sites[site.address] = site
|
||||
# Create a new file server to emulate new peer connecting to our peer
|
||||
file_server_temp = FileServer("127.0.0.1", 1545)
|
||||
file_server_temp = FileServer(file_server.ip, 1545)
|
||||
site_temp.connection_server = file_server_temp
|
||||
file_server_temp.sites[site_temp.address] = site_temp
|
||||
|
||||
# We will request peers from this
|
||||
peer_source = site_temp.addPeer("127.0.0.1", 1544)
|
||||
peer_source = site_temp.addPeer(file_server.ip, 1544)
|
||||
|
||||
# Get ip4 peers from source site
|
||||
site.addPeer("1.2.3.4", 1555) # Add peer to source site
|
||||
|
@ -106,12 +109,12 @@ class TestTor:
|
|||
file_server.sites[site.address] = site
|
||||
file_server.tor_manager = tor_manager
|
||||
|
||||
client = FileServer("127.0.0.1", 1545)
|
||||
client = FileServer(file_server.ip, 1545)
|
||||
client.sites[site_temp.address] = site_temp
|
||||
site_temp.connection_server = client
|
||||
|
||||
# Add file_server as peer to client
|
||||
peer_file_server = site_temp.addPeer("127.0.0.1", 1544)
|
||||
peer_file_server = site_temp.addPeer(file_server.ip, 1544)
|
||||
|
||||
assert peer_file_server.findHashIds([1234]) == {}
|
||||
|
||||
|
@ -132,12 +135,13 @@ class TestTor:
|
|||
|
||||
# Test my address adding
|
||||
site.content_manager.hashfield.append(1234)
|
||||
my_onion_address = tor_manager.getOnion(site_temp.address)+".onion"
|
||||
my_onion_address = tor_manager.getOnion(site_temp.address) + ".onion"
|
||||
|
||||
res = peer_file_server.findHashIds([1234, 1235])
|
||||
assert res[1234] == [('1.2.3.5', 1545), ("bka4ht2bzxchy44r.onion", 1544), (my_onion_address, 1544)]
|
||||
assert res[1235] == [('1.2.3.6', 1546), ('1.2.3.5', 1545)]
|
||||
|
||||
def testSiteOnion(self, tor_manager):
|
||||
assert tor_manager.getOnion("address1") != tor_manager.getOnion("address2")
|
||||
assert tor_manager.getOnion("address1") == tor_manager.getOnion("address1")
|
||||
with mock.patch.object(config, "tor", "always"):
|
||||
assert tor_manager.getOnion("address1") != tor_manager.getOnion("address2")
|
||||
assert tor_manager.getOnion("address1") == tor_manager.getOnion("address1")
|
||||
|
|
Loading…
Reference in a new issue