Rev467, requirements.txt accept newer dependecies, Boost dbschema.json, Move getDirname getFilename to helper, Verify optional files, Includes not allowed in user files, Optional files rules, Peer hashfield functions, Test optional files signing, Test file info, Test verify file, Test helpers
2015-10-01 01:35:13 +02:00
|
|
|
import socket
|
2019-01-20 19:08:15 +01:00
|
|
|
import struct
|
2019-03-18 01:08:02 +01:00
|
|
|
import os
|
Rev467, requirements.txt accept newer dependecies, Boost dbschema.json, Move getDirname getFilename to helper, Verify optional files, Includes not allowed in user files, Optional files rules, Peer hashfield functions, Test optional files signing, Test file info, Test verify file, Test helpers
2015-10-01 01:35:13 +02:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
from util import helper
|
2019-03-16 02:49:41 +01:00
|
|
|
from Config import config
|
Rev467, requirements.txt accept newer dependecies, Boost dbschema.json, Move getDirname getFilename to helper, Verify optional files, Includes not allowed in user files, Optional files rules, Peer hashfield functions, Test optional files signing, Test file info, Test verify file, Test helpers
2015-10-01 01:35:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures("resetSettings")
|
|
|
|
class TestHelper:
|
|
|
|
def testShellquote(self):
|
|
|
|
assert helper.shellquote("hel'lo") == "\"hel'lo\"" # Allow '
|
|
|
|
assert helper.shellquote('hel"lo') == '"hello"' # Remove "
|
|
|
|
assert helper.shellquote("hel'lo", 'hel"lo') == ('"hel\'lo"', '"hello"')
|
|
|
|
|
|
|
|
def testPackAddress(self):
|
2019-01-20 19:08:15 +01:00
|
|
|
for port in [1, 1000, 65535]:
|
|
|
|
for ip in ["1.1.1.1", "127.0.0.1", "0.0.0.0", "255.255.255.255", "192.168.1.1"]:
|
|
|
|
assert len(helper.packAddress(ip, port)) == 6
|
|
|
|
assert helper.unpackAddress(helper.packAddress(ip, port)) == (ip, port)
|
|
|
|
|
|
|
|
for ip in ["1:2:3:4:5:6:7:8", "::1", "2001:19f0:6c01:e76:5400:1ff:fed6:3eca", "2001:4860:4860::8888"]:
|
|
|
|
assert len(helper.packAddress(ip, port)) == 18
|
|
|
|
assert helper.unpackAddress(helper.packAddress(ip, port)) == (ip, port)
|
|
|
|
|
2019-03-16 02:49:41 +01:00
|
|
|
assert len(helper.packOnionAddress("boot3rdez4rzn36x.onion", port)) == 12
|
|
|
|
assert helper.unpackOnionAddress(helper.packOnionAddress("boot3rdez4rzn36x.onion", port)) == ("boot3rdez4rzn36x.onion", port)
|
|
|
|
|
|
|
|
with pytest.raises(struct.error):
|
2019-01-20 19:08:15 +01:00
|
|
|
helper.packAddress("1.1.1.1", 100000)
|
Rev467, requirements.txt accept newer dependecies, Boost dbschema.json, Move getDirname getFilename to helper, Verify optional files, Includes not allowed in user files, Optional files rules, Peer hashfield functions, Test optional files signing, Test file info, Test verify file, Test helpers
2015-10-01 01:35:13 +02:00
|
|
|
|
|
|
|
with pytest.raises(socket.error):
|
|
|
|
helper.packAddress("999.1.1.1", 1)
|
|
|
|
|
2019-07-03 18:35:55 +02:00
|
|
|
with pytest.raises(Exception):
|
Rev467, requirements.txt accept newer dependecies, Boost dbschema.json, Move getDirname getFilename to helper, Verify optional files, Includes not allowed in user files, Optional files rules, Peer hashfield functions, Test optional files signing, Test file info, Test verify file, Test helpers
2015-10-01 01:35:13 +02:00
|
|
|
helper.unpackAddress("X")
|
|
|
|
|
|
|
|
def testGetDirname(self):
|
|
|
|
assert helper.getDirname("data/users/content.json") == "data/users/"
|
|
|
|
assert helper.getDirname("data/users") == "data/"
|
|
|
|
assert helper.getDirname("") == ""
|
|
|
|
assert helper.getDirname("content.json") == ""
|
|
|
|
assert helper.getDirname("data/users/") == "data/users/"
|
2017-10-04 13:33:00 +02:00
|
|
|
assert helper.getDirname("/data/users/content.json") == "data/users/"
|
Rev467, requirements.txt accept newer dependecies, Boost dbschema.json, Move getDirname getFilename to helper, Verify optional files, Includes not allowed in user files, Optional files rules, Peer hashfield functions, Test optional files signing, Test file info, Test verify file, Test helpers
2015-10-01 01:35:13 +02:00
|
|
|
|
|
|
|
def testGetFilename(self):
|
|
|
|
assert helper.getFilename("data/users/content.json") == "content.json"
|
|
|
|
assert helper.getFilename("data/users") == "users"
|
|
|
|
assert helper.getFilename("") == ""
|
|
|
|
assert helper.getFilename("content.json") == "content.json"
|
|
|
|
assert helper.getFilename("data/users/") == ""
|
2018-12-19 13:25:20 +01:00
|
|
|
assert helper.getFilename("/data/users/content.json") == "content.json"
|
|
|
|
|
|
|
|
def testIsIp(self):
|
|
|
|
assert helper.isIp("1.2.3.4")
|
|
|
|
assert helper.isIp("255.255.255.255")
|
|
|
|
assert not helper.isIp("any.host")
|
|
|
|
assert not helper.isIp("1.2.3.4.com")
|
|
|
|
assert not helper.isIp("1.2.3.4.any.host")
|
|
|
|
|
|
|
|
def testIsPrivateIp(self):
|
|
|
|
assert helper.isPrivateIp("192.168.1.1")
|
|
|
|
assert not helper.isPrivateIp("1.1.1.1")
|
2019-01-26 20:38:30 +01:00
|
|
|
assert helper.isPrivateIp("fe80::44f0:3d0:4e6:637c")
|
|
|
|
assert not helper.isPrivateIp("fca5:95d6:bfde:d902:8951:276e:1111:a22c") # cjdns
|
2019-03-16 01:01:06 +01:00
|
|
|
|
|
|
|
def testOpenLocked(self):
|
|
|
|
locked_f = helper.openLocked(config.data_dir + "/locked.file")
|
|
|
|
assert locked_f
|
2019-03-20 01:05:52 +01:00
|
|
|
with pytest.raises(BlockingIOError):
|
2019-03-16 01:01:06 +01:00
|
|
|
locked_f_again = helper.openLocked(config.data_dir + "/locked.file")
|
|
|
|
locked_f_different = helper.openLocked(config.data_dir + "/locked_different.file")
|
2019-03-18 01:08:02 +01:00
|
|
|
|
|
|
|
locked_f.close()
|
|
|
|
locked_f_different.close()
|
|
|
|
|
|
|
|
os.unlink(locked_f.name)
|
|
|
|
os.unlink(locked_f_different.name)
|