(self, site, crypt_bitcoin_lib)
| 197 | assert site.content_manager.verifyFile(inner_path, data, ignore_same=False) |
| 198 | |
| 199 | def testVerifyInnerPath(self, site, crypt_bitcoin_lib): |
| 200 | inner_path = "content.json" |
| 201 | data_dict = site.storage.loadJson(inner_path) |
| 202 | |
| 203 | for good_relative_path in ["data.json", "out/data.json", "Any File [by none] (1).jpg"]: |
| 204 | data_dict["files"] = {good_relative_path: {"sha512": "369d4e780cc80504285f13774ca327fe725eed2d813aad229e62356b07365906", "size": 505}} |
| 205 | |
| 206 | if "sign" in data_dict: |
| 207 | del data_dict["sign"] |
| 208 | del data_dict["signs"] |
| 209 | data_dict["signs"] = { |
| 210 | "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), self.privatekey) |
| 211 | } |
| 212 | data = io.BytesIO(json.dumps(data_dict).encode()) |
| 213 | assert site.content_manager.verifyFile(inner_path, data, ignore_same=False) |
| 214 | |
| 215 | for bad_relative_path in ["../data.json", "data/" * 100, "invalid|file.jpg"]: |
| 216 | data_dict["files"] = {bad_relative_path: {"sha512": "369d4e780cc80504285f13774ca327fe725eed2d813aad229e62356b07365906", "size": 505}} |
| 217 | |
| 218 | if "sign" in data_dict: |
| 219 | del data_dict["sign"] |
| 220 | del data_dict["signs"] |
| 221 | data_dict["signs"] = { |
| 222 | "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), self.privatekey) |
| 223 | } |
| 224 | data = io.BytesIO(json.dumps(data_dict).encode()) |
| 225 | with pytest.raises(VerifyError) as err: |
| 226 | site.content_manager.verifyFile(inner_path, data, ignore_same=False) |
| 227 | assert "Invalid relative path" in str(err.value) |
| 228 | |
| 229 | @pytest.mark.parametrize("key", ["ignore", "optional"]) |
| 230 | def testSignUnsafePattern(self, site, key): |
nothing calls this directly
no test coverage detected