(self, site)
| 115 | assert site.content_manager.verifyFile(user_inner_path, data, ignore_same=False) |
| 116 | |
| 117 | def testVerify(self, site): |
| 118 | privatekey = "5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv" # For 1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT |
| 119 | user_inner_path = "data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/content.json" |
| 120 | data_dict = site.storage.loadJson(user_inner_path) |
| 121 | users_content = site.content_manager.contents["data/users/content.json"] |
| 122 | |
| 123 | data = io.BytesIO(json.dumps(data_dict).encode()) |
| 124 | assert site.content_manager.verifyFile(user_inner_path, data, ignore_same=False) |
| 125 | |
| 126 | # Test max size exception by setting allowed to 0 |
| 127 | rules = site.content_manager.getRules(user_inner_path, data_dict) |
| 128 | assert rules["max_size"] == 10000 |
| 129 | assert users_content["user_contents"]["permission_rules"][".*"]["max_size"] == 10000 |
| 130 | |
| 131 | users_content["user_contents"]["permission_rules"][".*"]["max_size"] = 0 |
| 132 | rules = site.content_manager.getRules(user_inner_path, data_dict) |
| 133 | assert rules["max_size"] == 0 |
| 134 | data = io.BytesIO(json.dumps(data_dict).encode()) |
| 135 | |
| 136 | with pytest.raises(VerifyError) as err: |
| 137 | site.content_manager.verifyFile(user_inner_path, data, ignore_same=False) |
| 138 | assert "Include too large" in str(err.value) |
| 139 | users_content["user_contents"]["permission_rules"][".*"]["max_size"] = 10000 # Reset |
| 140 | |
| 141 | # Test max optional size exception |
| 142 | # 1 MB gif = Allowed |
| 143 | data_dict["files_optional"]["peanut-butter-jelly-time.gif"]["size"] = 1024 * 1024 |
| 144 | del data_dict["signs"] # Remove signs before signing |
| 145 | data_dict["signs"] = { |
| 146 | "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), privatekey) |
| 147 | } |
| 148 | data = io.BytesIO(json.dumps(data_dict).encode()) |
| 149 | assert site.content_manager.verifyFile(user_inner_path, data, ignore_same=False) |
| 150 | |
| 151 | # 100 MB gif = Not allowed |
| 152 | data_dict["files_optional"]["peanut-butter-jelly-time.gif"]["size"] = 100 * 1024 * 1024 |
| 153 | del data_dict["signs"] # Remove signs before signing |
| 154 | data_dict["signs"] = { |
| 155 | "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), privatekey) |
| 156 | } |
| 157 | data = io.BytesIO(json.dumps(data_dict).encode()) |
| 158 | with pytest.raises(VerifyError) as err: |
| 159 | site.content_manager.verifyFile(user_inner_path, data, ignore_same=False) |
| 160 | assert "Include optional files too large" in str(err.value) |
| 161 | data_dict["files_optional"]["peanut-butter-jelly-time.gif"]["size"] = 1024 * 1024 # Reset |
| 162 | |
| 163 | # hello.exe = Not allowed |
| 164 | data_dict["files_optional"]["hello.exe"] = data_dict["files_optional"]["peanut-butter-jelly-time.gif"] |
| 165 | del data_dict["signs"] # Remove signs before signing |
| 166 | data_dict["signs"] = { |
| 167 | "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), privatekey) |
| 168 | } |
| 169 | data = io.BytesIO(json.dumps(data_dict).encode()) |
| 170 | with pytest.raises(VerifyError) as err: |
| 171 | site.content_manager.verifyFile(user_inner_path, data, ignore_same=False) |
| 172 | assert "Optional file not allowed" in str(err.value) |
| 173 | del data_dict["files_optional"]["hello.exe"] # Reset |
| 174 |
nothing calls this directly
no test coverage detected