MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / testMissingCert

Method testMissingCert

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

Source from the content-addressed store, hash-verified

274 )
275
276 def testMissingCert(self, site):
277 user_priv = "5Kk7FSA63FC2ViKmKLuBxk9gQkaQ5713hKq8LmFAf4cVeXh6K6A"
278 cert_priv = "5JusJDSjHaMHwUjDT3o6eQ54pA6poo8La5fAgn1wNc3iK59jxjA"
279
280 user_content = site.content_manager.contents["data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json"]
281 rules_content = site.content_manager.contents["data/users/content.json"]
282
283 # Override valid cert signers for the test
284 rules_content["user_contents"]["cert_signers"]["zeroid.bit"] = [
285 "14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet",
286 "1iD5ZQJMNXu43w1qLB8sfdHVKppVMduGz"
287 ]
288
289 # Sign a valid cert
290 user_content["cert_sign"] = CryptBitcoin.sign("1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C#%s/%s" % (
291 user_content["cert_auth_type"],
292 user_content["cert_user_id"].split("@")[0]
293 ), cert_priv)
294 signed_content = site.content_manager.sign(
295 "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_priv, filewrite=False
296 )
297
298 assert site.content_manager.verifyFile(
299 "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
300 io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False
301 )
302
303 # Test invalid cert_user_id
304 user_content["cert_user_id"] = "nodomain"
305 user_content["signs"] = {
306 "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(user_content, sort_keys=True), user_priv)
307 }
308 signed_content = site.content_manager.sign(
309 "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_priv, filewrite=False
310 )
311 with pytest.raises(VerifyError) as err:
312 site.content_manager.verifyFile(
313 "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
314 io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False
315 )
316 assert "Invalid domain in cert_user_id" in str(err.value)
317
318 # Test removed cert
319 del user_content["cert_user_id"]
320 del user_content["cert_auth_type"]
321 del user_content["signs"] # Remove signs before signing
322 user_content["signs"] = {
323 "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(user_content, sort_keys=True), user_priv)
324 }
325 signed_content = site.content_manager.sign(
326 "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_priv, filewrite=False
327 )
328 with pytest.raises(VerifyError) as err:
329 site.content_manager.verifyFile(
330 "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
331 io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False
332 )
333 assert "Missing cert_user_id" in str(err.value)

Callers

nothing calls this directly

Calls 2

signMethod · 0.45
verifyFileMethod · 0.45

Tested by

no test coverage detected