def test_signed_model(self): """ Test is models can be signed, and if the signature is read as valid """ model = DatabaseModel() model.post_or_put(self.db) pre_hash = model.generate_sha1_hash() # Sign the model model.sign(self.api) post_hash = model.generate_sha1_hash() self.assertEqual(pre_hash, post_hash) self.assertEqual(model.signer, self.db.backend.get_option('user_key_pub')) self.assertTrue(DatabaseModel.signature_valid(model))
def test_signed_model_detect_tamper(self): """ Test is models can be signed, and if the signature is read as valid """ model = DatabaseModel() model.post_or_put(self.db) pre_hash = model.generate_sha1_hash() # Sign the model model.sign(self.api) #Tamper with the model model._id = 'different' post_hash = model.generate_sha1_hash() self.assertNotEqual(pre_hash, post_hash) self.assertEqual(model.signer, self.db.backend.get_option('user_key_pub')) self.assertFalse(DatabaseModel.signature_valid(model))