| 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): |
| 94 | # Bad privatekey |
| 95 | with pytest.raises(SignError) as err: |
| 96 | site.content_manager.sign(inner_path, privatekey="5aaa3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMnaa", filewrite=False) |
| 97 | assert "Private key invalid" in str(err.value) |
| 98 | |
| 99 | # Good privatekey |
| 100 | content = site.content_manager.sign(inner_path, privatekey=self.privatekey, filewrite=False) |
| 101 | content_old = site.content_manager.contents[inner_path] # Content before the sign |
| 102 | assert not content_old == content # Timestamp changed |
| 103 | assert site.address in content["signs"] # Used the site's private key to sign |
| 104 | if inner_path == "content.json": |
| 105 | assert len(content["files"]) == 17 |
| 106 | elif inner_path == "data/test-include/content.json": |
| 107 | assert len(content["files"]) == 1 |
| 108 | elif inner_path == "data/users/content.json": |
| 109 | assert len(content["files"]) == 0 |
| 110 | |
| 111 | # Everything should be same as before except the modified timestamp and the signs |
| 112 | assert ( |
| 113 | {key: val for key, val in content_old.items() if key not in ["modified", "signs", "sign", "zeronet_version"]} |
| 114 | == |
| 115 | {key: val for key, val in content.items() if key not in ["modified", "signs", "sign", "zeronet_version"]} |
| 116 | ) |
| 117 | |
| 118 | def testSignOptionalFiles(self, site): |
| 119 | for hash in list(site.content_manager.hashfield): |