(self, site)
| 184 | assert "Includes not allowed" in str(err.value) |
| 185 | |
| 186 | def testCert(self, site): |
| 187 | # user_addr = "1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C" |
| 188 | user_priv = "5Kk7FSA63FC2ViKmKLuBxk9gQkaQ5713hKq8LmFAf4cVeXh6K6A" |
| 189 | # cert_addr = "14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet" |
| 190 | cert_priv = "5JusJDSjHaMHwUjDT3o6eQ54pA6poo8La5fAgn1wNc3iK59jxjA" |
| 191 | |
| 192 | # Check if the user file is loaded |
| 193 | assert "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json" in site.content_manager.contents |
| 194 | user_content = site.content_manager.contents["data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json"] |
| 195 | rules_content = site.content_manager.contents["data/users/content.json"] |
| 196 | |
| 197 | # Override valid cert signers for the test |
| 198 | rules_content["user_contents"]["cert_signers"]["zeroid.bit"] = [ |
| 199 | "14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet", |
| 200 | "1iD5ZQJMNXu43w1qLB8sfdHVKppVMduGz" |
| 201 | ] |
| 202 | |
| 203 | # Check valid cert signers |
| 204 | rules = site.content_manager.getRules("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_content) |
| 205 | assert rules["cert_signers"] == {"zeroid.bit": [ |
| 206 | "14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet", |
| 207 | "1iD5ZQJMNXu43w1qLB8sfdHVKppVMduGz" |
| 208 | ]} |
| 209 | |
| 210 | # Sign a valid cert |
| 211 | user_content["cert_sign"] = CryptBitcoin.sign("1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C#%s/%s" % ( |
| 212 | user_content["cert_auth_type"], |
| 213 | user_content["cert_user_id"].split("@")[0] |
| 214 | ), cert_priv) |
| 215 | |
| 216 | # Verify cert |
| 217 | assert site.content_manager.verifyCert("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_content) |
| 218 | |
| 219 | # Verify if the cert is valid for other address |
| 220 | assert not site.content_manager.verifyCert("data/users/badaddress/content.json", user_content) |
| 221 | |
| 222 | # Sign user content |
| 223 | signed_content = site.content_manager.sign( |
| 224 | "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_priv, filewrite=False |
| 225 | ) |
| 226 | |
| 227 | # Test user cert |
| 228 | assert site.content_manager.verifyFile( |
| 229 | "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", |
| 230 | io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False |
| 231 | ) |
| 232 | |
| 233 | # Test banned user |
| 234 | cert_user_id = user_content["cert_user_id"] # My username |
| 235 | site.content_manager.contents["data/users/content.json"]["user_contents"]["permissions"][cert_user_id] = False |
| 236 | with pytest.raises(VerifyError) as err: |
| 237 | site.content_manager.verifyFile( |
| 238 | "data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", |
| 239 | io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False |
| 240 | ) |
| 241 | assert "Valid signs: 0/1" in str(err.value) |
| 242 | del site.content_manager.contents["data/users/content.json"]["user_contents"]["permissions"][cert_user_id] # Reset |
| 243 |
nothing calls this directly
no test coverage detected