(self, site)
| 334 | |
| 335 | |
| 336 | def testCertSignersPattern(self, site): |
| 337 | user_priv = "5Kk7FSA63FC2ViKmKLuBxk9gQkaQ5713hKq8LmFAf4cVeXh6K6A" |
| 338 | cert_priv = "5JusJDSjHaMHwUjDT3o6eQ54pA6poo8La5fAgn1wNc3iK59jxjA" # For 14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet |
| 339 | |
| 340 | user_content = site.content_manager.contents["data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json"] |
| 341 | rules_content = site.content_manager.contents["data/users/content.json"] |
| 342 | |
| 343 | # Override valid cert signers for the test |
| 344 | rules_content["user_contents"]["cert_signers_pattern"] = "14wgQ[0-9][A-Z]" |
| 345 | |
| 346 | # Sign a valid cert |
| 347 | user_content["cert_user_id"] = "certuser@14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet" |
| 348 | user_content["cert_sign"] = CryptBitcoin.sign("1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C#%s/%s" % ( |
| 349 | user_content["cert_auth_type"], |
| 350 | "certuser" |
| 351 | ), cert_priv) |
| 352 | signed_content = site.content_manager.sign( |
| 353 | "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_priv, filewrite=False |
| 354 | ) |
| 355 | |
| 356 | assert site.content_manager.verifyFile( |
| 357 | "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", |
| 358 | io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False |
| 359 | ) |
| 360 | |
| 361 | # Cert does not matches the pattern |
| 362 | rules_content["user_contents"]["cert_signers_pattern"] = "14wgX[0-9][A-Z]" |
| 363 | |
| 364 | with pytest.raises(VerifyError) as err: |
| 365 | site.content_manager.verifyFile( |
| 366 | "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", |
| 367 | io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False |
| 368 | ) |
| 369 | assert "Invalid cert signer: 14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet" in str(err.value) |
| 370 | |
| 371 | # Removed cert_signers_pattern |
| 372 | del rules_content["user_contents"]["cert_signers_pattern"] |
| 373 | |
| 374 | with pytest.raises(VerifyError) as err: |
| 375 | site.content_manager.verifyFile( |
| 376 | "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", |
| 377 | io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False |
| 378 | ) |
| 379 | assert "Invalid cert signer: 14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet" in str(err.value) |
| 380 | |
| 381 | |
| 382 | def testNewFile(self, site): |
nothing calls this directly
no test coverage detected