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

Method testInlcudeLimits

src/Test/TestContent.py:41–90  ·  view source on GitHub ↗
(self, site, crypt_bitcoin_lib)

Source from the content-addressed store, hash-verified

39 assert site.content_manager.getValidSigners("content.json") == ["1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"]
40
41 def testInlcudeLimits(self, site, crypt_bitcoin_lib):
42 # Data validation
43 res = []
44 data_dict = {
45 "files": {
46 "data.json": {
47 "sha512": "369d4e780cc80504285f13774ca327fe725eed2d813aad229e62356b07365906",
48 "size": 505
49 }
50 },
51 "modified": time.time()
52 }
53
54 # Normal data
55 data_dict["signs"] = {"1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), self.privatekey)}
56 data_json = json.dumps(data_dict).encode()
57 data = io.BytesIO(data_json)
58 assert site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False)
59
60 # Reset
61 del data_dict["signs"]
62
63 # Too large
64 data_dict["files"]["data.json"]["size"] = 200000 # Emulate 2MB sized data.json
65 data_dict["signs"] = {"1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), self.privatekey)}
66 data = io.BytesIO(json.dumps(data_dict).encode())
67 with pytest.raises(VerifyError) as err:
68 site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False)
69 assert "Include too large" in str(err.value)
70
71 # Reset
72 data_dict["files"]["data.json"]["size"] = 505
73 del data_dict["signs"]
74
75 # Not allowed file
76 data_dict["files"]["notallowed.exe"] = data_dict["files"]["data.json"]
77 data_dict["signs"] = {"1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), self.privatekey)}
78 data = io.BytesIO(json.dumps(data_dict).encode())
79 with pytest.raises(VerifyError) as err:
80 site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False)
81 assert "File not allowed" in str(err.value)
82
83 # Reset
84 del data_dict["files"]["notallowed.exe"]
85 del data_dict["signs"]
86
87 # Should work again
88 data_dict["signs"] = {"1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), self.privatekey)}
89 data = io.BytesIO(json.dumps(data_dict).encode())
90 assert site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False)
91
92 @pytest.mark.parametrize("inner_path", ["content.json", "data/test_include/content.json", "data/users/content.json"])
93 def testSign(self, site, inner_path):

Callers

nothing calls this directly

Calls 2

signMethod · 0.45
verifyFileMethod · 0.45

Tested by

no test coverage detected