Fix error message testing
This commit is contained in:
parent
7c6702057d
commit
5178a288ca
3 changed files with 18 additions and 19 deletions
|
@ -63,7 +63,7 @@ class TestContent:
|
||||||
data = StringIO(json.dumps(data_dict))
|
data = StringIO(json.dumps(data_dict))
|
||||||
with pytest.raises(VerifyError) as err:
|
with pytest.raises(VerifyError) as err:
|
||||||
site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False)
|
site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False)
|
||||||
assert "Include too large" in str(err)
|
assert "Include too large" in str(err)
|
||||||
|
|
||||||
# Reset
|
# Reset
|
||||||
data_dict["files"]["data.json"]["size"] = 505
|
data_dict["files"]["data.json"]["size"] = 505
|
||||||
|
@ -75,7 +75,7 @@ class TestContent:
|
||||||
data = StringIO(json.dumps(data_dict))
|
data = StringIO(json.dumps(data_dict))
|
||||||
with pytest.raises(VerifyError) as err:
|
with pytest.raises(VerifyError) as err:
|
||||||
site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False)
|
site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False)
|
||||||
assert "File not allowed" in str(err)
|
assert "File not allowed" in str(err)
|
||||||
|
|
||||||
# Reset
|
# Reset
|
||||||
del data_dict["files"]["notallowed.exe"]
|
del data_dict["files"]["notallowed.exe"]
|
||||||
|
@ -91,7 +91,7 @@ class TestContent:
|
||||||
# Bad privatekey
|
# Bad privatekey
|
||||||
with pytest.raises(SignError) as err:
|
with pytest.raises(SignError) as err:
|
||||||
site.content_manager.sign(inner_path, privatekey="5aaa3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMnaa", filewrite=False)
|
site.content_manager.sign(inner_path, privatekey="5aaa3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMnaa", filewrite=False)
|
||||||
assert "Private key invalid" in str(err)
|
assert "Private key invalid" in str(err)
|
||||||
|
|
||||||
# Good privatekey
|
# Good privatekey
|
||||||
content = site.content_manager.sign(inner_path, privatekey=self.privatekey, filewrite=False)
|
content = site.content_manager.sign(inner_path, privatekey=self.privatekey, filewrite=False)
|
||||||
|
@ -169,7 +169,7 @@ class TestContent:
|
||||||
data = StringIO(json.dumps(data_dict))
|
data = StringIO(json.dumps(data_dict))
|
||||||
with pytest.raises(VerifyError) as err:
|
with pytest.raises(VerifyError) as err:
|
||||||
site.content_manager.verifyFile(inner_path, data, ignore_same=False)
|
site.content_manager.verifyFile(inner_path, data, ignore_same=False)
|
||||||
assert "Wrong site address" in str(err)
|
assert "Wrong site address" in str(err)
|
||||||
|
|
||||||
# Wrong inner_path
|
# Wrong inner_path
|
||||||
data_dict["address"] = "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"
|
data_dict["address"] = "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"
|
||||||
|
@ -181,7 +181,7 @@ class TestContent:
|
||||||
data = StringIO(json.dumps(data_dict))
|
data = StringIO(json.dumps(data_dict))
|
||||||
with pytest.raises(VerifyError) as err:
|
with pytest.raises(VerifyError) as err:
|
||||||
site.content_manager.verifyFile(inner_path, data, ignore_same=False)
|
site.content_manager.verifyFile(inner_path, data, ignore_same=False)
|
||||||
assert "Wrong inner_path" in str(err)
|
assert "Wrong inner_path" in str(err)
|
||||||
|
|
||||||
# Everything right again
|
# Everything right again
|
||||||
data_dict["address"] = "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"
|
data_dict["address"] = "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"
|
||||||
|
@ -221,14 +221,14 @@ class TestContent:
|
||||||
data = StringIO(json.dumps(data_dict))
|
data = StringIO(json.dumps(data_dict))
|
||||||
with pytest.raises(VerifyError) as err:
|
with pytest.raises(VerifyError) as err:
|
||||||
site.content_manager.verifyFile(inner_path, data, ignore_same=False)
|
site.content_manager.verifyFile(inner_path, data, ignore_same=False)
|
||||||
assert "Invalid relative path" in str(err)
|
assert "Invalid relative path" in str(err)
|
||||||
|
|
||||||
@pytest.mark.parametrize("key", ["ignore", "optional"])
|
@pytest.mark.parametrize("key", ["ignore", "optional"])
|
||||||
def testSignUnsafePattern(self, site, key):
|
def testSignUnsafePattern(self, site, key):
|
||||||
site.content_manager.contents["content.json"][key] = "([a-zA-Z]+)*"
|
site.content_manager.contents["content.json"][key] = "([a-zA-Z]+)*"
|
||||||
with pytest.raises(UnsafePatternError) as err:
|
with pytest.raises(UnsafePatternError) as err:
|
||||||
site.content_manager.sign("content.json", privatekey=self.privatekey, filewrite=False)
|
site.content_manager.sign("content.json", privatekey=self.privatekey, filewrite=False)
|
||||||
assert "Potentially unsafe" in str(err)
|
assert "Potentially unsafe" in str(err)
|
||||||
|
|
||||||
|
|
||||||
def testVerifyUnsafePattern(self, site):
|
def testVerifyUnsafePattern(self, site):
|
||||||
|
@ -236,10 +236,10 @@ class TestContent:
|
||||||
with pytest.raises(UnsafePatternError) as err:
|
with pytest.raises(UnsafePatternError) as err:
|
||||||
with site.storage.open("data/test_include/content.json") as data:
|
with site.storage.open("data/test_include/content.json") as data:
|
||||||
site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False)
|
site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False)
|
||||||
assert "Potentially unsafe" in str(err)
|
assert "Potentially unsafe" in str(err)
|
||||||
|
|
||||||
site.content_manager.contents["data/users/content.json"]["user_contents"]["permission_rules"]["([a-zA-Z]+)*"] = {"max_size": 0}
|
site.content_manager.contents["data/users/content.json"]["user_contents"]["permission_rules"]["([a-zA-Z]+)*"] = {"max_size": 0}
|
||||||
with pytest.raises(UnsafePatternError) as err:
|
with pytest.raises(UnsafePatternError) as err:
|
||||||
with site.storage.open("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json") as data:
|
with site.storage.open("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json") as data:
|
||||||
site.content_manager.verifyFile("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json", data, ignore_same=False)
|
site.content_manager.verifyFile("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json", data, ignore_same=False)
|
||||||
assert "Potentially unsafe" in str(err)
|
assert "Potentially unsafe" in str(err)
|
||||||
|
|
|
@ -32,8 +32,7 @@ class TestContentUser:
|
||||||
valid_signers = site.content_manager.getValidSigners("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_content)
|
valid_signers = site.content_manager.getValidSigners("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_content)
|
||||||
assert '1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT' in valid_signers # The site address
|
assert '1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT' in valid_signers # The site address
|
||||||
assert '14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet' in valid_signers # Admin user defined in data/users/content.json
|
assert '14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet' in valid_signers # Admin user defined in data/users/content.json
|
||||||
assert not '1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C' in valid_signers # The user itself
|
assert '1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C' not in valid_signers # The user itself
|
||||||
|
|
||||||
|
|
||||||
def testRules(self, site):
|
def testRules(self, site):
|
||||||
# We going to manipulate it this test rules based on data/users/content.json
|
# We going to manipulate it this test rules based on data/users/content.json
|
||||||
|
@ -104,7 +103,7 @@ class TestContentUser:
|
||||||
data = StringIO(json.dumps(data_dict))
|
data = StringIO(json.dumps(data_dict))
|
||||||
with pytest.raises(VerifyError) as err:
|
with pytest.raises(VerifyError) as err:
|
||||||
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
|
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
|
||||||
assert "Content too large" in str(err)
|
assert "Include too large" in str(err)
|
||||||
|
|
||||||
# Give more space based on address
|
# Give more space based on address
|
||||||
users_content["user_contents"]["permissions"]["1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9"] = {"max_size": 20000}
|
users_content["user_contents"]["permissions"]["1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9"] = {"max_size": 20000}
|
||||||
|
@ -136,7 +135,7 @@ class TestContentUser:
|
||||||
|
|
||||||
with pytest.raises(VerifyError) as err:
|
with pytest.raises(VerifyError) as err:
|
||||||
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
|
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
|
||||||
assert "Include too large" in str(err)
|
assert "Include too large" in str(err)
|
||||||
users_content["user_contents"]["permission_rules"][".*"]["max_size"] = 10000 # Reset
|
users_content["user_contents"]["permission_rules"][".*"]["max_size"] = 10000 # Reset
|
||||||
|
|
||||||
# Test max optional size exception
|
# Test max optional size exception
|
||||||
|
@ -158,7 +157,7 @@ class TestContentUser:
|
||||||
data = StringIO(json.dumps(data_dict))
|
data = StringIO(json.dumps(data_dict))
|
||||||
with pytest.raises(VerifyError) as err:
|
with pytest.raises(VerifyError) as err:
|
||||||
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
|
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
|
||||||
assert "Include optional files too large" in str(err)
|
assert "Include optional files too large" in str(err)
|
||||||
data_dict["files_optional"]["peanut-butter-jelly-time.gif"]["size"] = 1024 * 1024 # Reset
|
data_dict["files_optional"]["peanut-butter-jelly-time.gif"]["size"] = 1024 * 1024 # Reset
|
||||||
|
|
||||||
# hello.exe = Not allowed
|
# hello.exe = Not allowed
|
||||||
|
@ -170,7 +169,7 @@ class TestContentUser:
|
||||||
data = StringIO(json.dumps(data_dict))
|
data = StringIO(json.dumps(data_dict))
|
||||||
with pytest.raises(VerifyError) as err:
|
with pytest.raises(VerifyError) as err:
|
||||||
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
|
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
|
||||||
assert "Optional file not allowed" in str(err)
|
assert "Optional file not allowed" in str(err)
|
||||||
del data_dict["files_optional"]["hello.exe"] # Reset
|
del data_dict["files_optional"]["hello.exe"] # Reset
|
||||||
|
|
||||||
# Includes not allowed in user content
|
# Includes not allowed in user content
|
||||||
|
@ -182,7 +181,7 @@ class TestContentUser:
|
||||||
data = StringIO(json.dumps(data_dict))
|
data = StringIO(json.dumps(data_dict))
|
||||||
with pytest.raises(VerifyError) as err:
|
with pytest.raises(VerifyError) as err:
|
||||||
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
|
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
|
||||||
assert "Includes not allowed" in err
|
assert "Includes not allowed" in str(err)
|
||||||
|
|
||||||
def testCert(self, site):
|
def testCert(self, site):
|
||||||
# user_addr = "1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C"
|
# user_addr = "1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C"
|
||||||
|
@ -239,7 +238,7 @@ class TestContentUser:
|
||||||
"data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
|
"data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
|
||||||
StringIO(json.dumps(signed_content)), ignore_same=False
|
StringIO(json.dumps(signed_content)), ignore_same=False
|
||||||
)
|
)
|
||||||
assert "Valid sings: 0" in str(err)
|
assert "Valid signs: 0/1" in str(err)
|
||||||
del site.content_manager.contents["data/users/content.json"]["user_contents"]["permissions"][cert_user_id] # Reset
|
del site.content_manager.contents["data/users/content.json"]["user_contents"]["permissions"][cert_user_id] # Reset
|
||||||
|
|
||||||
# Test invalid cert
|
# Test invalid cert
|
||||||
|
@ -254,7 +253,7 @@ class TestContentUser:
|
||||||
"data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
|
"data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
|
||||||
StringIO(json.dumps(signed_content)), ignore_same=False
|
StringIO(json.dumps(signed_content)), ignore_same=False
|
||||||
)
|
)
|
||||||
assert "Invalid cert" in str(err)
|
assert "Invalid cert" in str(err)
|
||||||
|
|
||||||
# Test banned user, signed by the site owner
|
# Test banned user, signed by the site owner
|
||||||
user_content["cert_sign"] = CryptBitcoin.sign("1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C#%s/%s" % (
|
user_content["cert_sign"] = CryptBitcoin.sign("1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C#%s/%s" % (
|
||||||
|
|
|
@ -37,7 +37,7 @@ class TestSite:
|
||||||
|
|
||||||
# Changes in non-data files should be overwritten
|
# Changes in non-data files should be overwritten
|
||||||
new_site.storage.write("index.html", "this will be overwritten")
|
new_site.storage.write("index.html", "this will be overwritten")
|
||||||
assert new_site.storage.read("index.html"), "this will be overwritten"
|
assert new_site.storage.read("index.html") == "this will be overwritten"
|
||||||
|
|
||||||
# Changes in data file should be kept after re-cloning
|
# Changes in data file should be kept after re-cloning
|
||||||
changed_contentjson = new_site.storage.loadJson("content.json")
|
changed_contentjson = new_site.storage.loadJson("content.json")
|
||||||
|
|
Loading…
Reference in a new issue