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

Method testVerifyAddress

src/Test/TestContentUser.py:88–115  ·  view source on GitHub ↗
(self, site)

Source from the content-addressed store, hash-verified

86 assert rules["max_size"] == 20000
87
88 def testVerifyAddress(self, site):
89 privatekey = "5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv" # For 1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT
90 user_inner_path = "data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/content.json"
91 data_dict = site.storage.loadJson(user_inner_path)
92 users_content = site.content_manager.contents["data/users/content.json"]
93
94 data = io.BytesIO(json.dumps(data_dict).encode())
95 assert site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
96
97 # Test error on 15k data.json
98 data_dict["files"]["data.json"]["size"] = 1024 * 15
99 del data_dict["signs"] # Remove signs before signing
100 data_dict["signs"] = {
101 "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), privatekey)
102 }
103 data = io.BytesIO(json.dumps(data_dict).encode())
104 with pytest.raises(VerifyError) as err:
105 site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
106 assert "Include too large" in str(err.value)
107
108 # Give more space based on address
109 users_content["user_contents"]["permissions"]["1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9"] = {"max_size": 20000}
110 del data_dict["signs"] # Remove signs before signing
111 data_dict["signs"] = {
112 "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), privatekey)
113 }
114 data = io.BytesIO(json.dumps(data_dict).encode())
115 assert site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
116
117 def testVerify(self, site):
118 privatekey = "5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv" # For 1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT

Callers

nothing calls this directly

Calls 3

loadJsonMethod · 0.80
verifyFileMethod · 0.45
signMethod · 0.45

Tested by

no test coverage detected