2015-09-24 22:08:08 +02:00
|
|
|
import time
|
|
|
|
import gevent
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from Crypt import CryptConnection
|
|
|
|
from Connection import ConnectionServer
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures("resetSettings")
|
|
|
|
class TestConnection:
|
|
|
|
def testSslConnection(self, file_server):
|
|
|
|
file_server.ip_incoming = {} # Reset flood protection
|
|
|
|
client = ConnectionServer("127.0.0.1", 1545)
|
|
|
|
assert file_server != client
|
|
|
|
|
|
|
|
# Connect to myself
|
|
|
|
connection = client.getConnection("127.0.0.1", 1544)
|
|
|
|
assert len(file_server.connections) == 1
|
|
|
|
assert len(file_server.ips) == 1
|
|
|
|
assert connection.handshake
|
|
|
|
assert connection.crypt
|
|
|
|
|
|
|
|
# Close connection
|
|
|
|
connection.close()
|
|
|
|
client.stop()
|
|
|
|
time.sleep(0.01)
|
|
|
|
assert len(file_server.connections) == 0
|
|
|
|
assert len(file_server.ips) == 0
|
|
|
|
|
|
|
|
def testRawConnection(self, file_server):
|
|
|
|
file_server.ip_incoming = {} # Reset flood protection
|
|
|
|
client = ConnectionServer("127.0.0.1", 1545)
|
|
|
|
assert file_server != client
|
|
|
|
|
|
|
|
# Remove all supported crypto
|
|
|
|
crypt_supported_bk = CryptConnection.manager.crypt_supported
|
|
|
|
CryptConnection.manager.crypt_supported = []
|
|
|
|
|
|
|
|
connection = client.getConnection("127.0.0.1", 1544)
|
|
|
|
assert len(file_server.connections) == 1
|
|
|
|
assert not connection.crypt
|
|
|
|
|
|
|
|
# Close connection
|
|
|
|
connection.close()
|
|
|
|
client.stop()
|
|
|
|
time.sleep(0.01)
|
|
|
|
assert len(file_server.connections) == 0
|
|
|
|
|
|
|
|
# Reset supported crypts
|
|
|
|
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)
|
|
|
|
|
|
|
|
assert connection.ping()
|
|
|
|
|
|
|
|
connection.close()
|
|
|
|
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)
|
|
|
|
|
|
|
|
# Get connection by ip/port
|
|
|
|
connection2 = client.getConnection("127.0.0.1", 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 connection2 == connection
|
|
|
|
|
|
|
|
connection.close()
|
|
|
|
client.stop()
|
|
|
|
|
|
|
|
def testFloodProtection(self, file_server):
|
|
|
|
file_server.ip_incoming = {} # Reset flood protection
|
Version 0.3.5, Rev830, Full Tor mode support with hidden services, Onion stats in Sidebar, GeoDB download fix using Tor, Gray out disabled sites in Stats page, Tor hidden service status in stat page, Benchmark sha256, Skyts tracker out expodie in, 2 new tracker using ZeroNet protocol, Keep SSL cert option between restarts, SSL Certificate pinning support for connections, Site lock support for connections, Certificate pinned connections using implicit SSL, Flood protection whitelist support, Foreign keys support for DB layer, Not support for SQL query helper, 0 length file get bugfix, Pex onion address support, Faster port testing, Faster uPnP port opening, Need connections more often on owned sites, Delay ZeroHello startup message if port check or Tor manager not ready yet, Use lockfiles to avoid double start, Save original socket on proxy monkey patching to get ability to connect localhost directly, Handle atomic write errors, Broken gevent https workaround helper, Rsa crypt functions, Plugin to Bootstrap using ZeroNet protocol
2016-01-05 00:20:52 +01:00
|
|
|
whitelist = file_server.whitelist # Save for reset
|
|
|
|
file_server.whitelist = [] # Disable 127.0.0.1 whitelist
|
2015-09-24 22:08:08 +02:00
|
|
|
client = ConnectionServer("127.0.0.1", 1545)
|
|
|
|
|
|
|
|
# Only allow 3 connection in 1 minute
|
|
|
|
connection = client.getConnection("127.0.0.1", 1544)
|
|
|
|
assert connection.handshake
|
|
|
|
connection.close()
|
|
|
|
|
|
|
|
connection = client.getConnection("127.0.0.1", 1544)
|
|
|
|
assert connection.handshake
|
|
|
|
connection.close()
|
|
|
|
|
|
|
|
connection = client.getConnection("127.0.0.1", 1544)
|
|
|
|
assert connection.handshake
|
|
|
|
connection.close()
|
|
|
|
|
|
|
|
# The 4. one will timeout
|
|
|
|
with pytest.raises(gevent.Timeout):
|
|
|
|
with gevent.Timeout(0.1):
|
|
|
|
connection = client.getConnection("127.0.0.1", 1544)
|
Version 0.3.5, Rev830, Full Tor mode support with hidden services, Onion stats in Sidebar, GeoDB download fix using Tor, Gray out disabled sites in Stats page, Tor hidden service status in stat page, Benchmark sha256, Skyts tracker out expodie in, 2 new tracker using ZeroNet protocol, Keep SSL cert option between restarts, SSL Certificate pinning support for connections, Site lock support for connections, Certificate pinned connections using implicit SSL, Flood protection whitelist support, Foreign keys support for DB layer, Not support for SQL query helper, 0 length file get bugfix, Pex onion address support, Faster port testing, Faster uPnP port opening, Need connections more often on owned sites, Delay ZeroHello startup message if port check or Tor manager not ready yet, Use lockfiles to avoid double start, Save original socket on proxy monkey patching to get ability to connect localhost directly, Handle atomic write errors, Broken gevent https workaround helper, Rsa crypt functions, Plugin to Bootstrap using ZeroNet protocol
2016-01-05 00:20:52 +01:00
|
|
|
|
|
|
|
# Reset whitelist
|
|
|
|
file_server.whitelist = whitelist
|