def test_validate_signature_bad_sig(self): """ Ensures that an invalid signature results in a False. """ signature = 'helloworld' check = validate_signature(self.value, self.timestamp, self.expires, self.name, self.meta, signature, PUBLIC_KEY) self.assertEqual(False, check)
def test_validate_signature_wrong_public_key(self): """ Ensures that given a valid signature but wrong public key, validation results in False. """ check = validate_signature(self.value, self.timestamp, self.expires, self.name, self.meta, self.signature, ALT_PUBLIC_KEY) self.assertEqual(False, check)
def test_validate_signature(self): """ Ensures that given some values and an associated valid signature the validate_signature returns True for the correct public key. """ check = validate_signature(self.value, self.timestamp, self.expires, self.name, self.meta, self.signature, PUBLIC_KEY) self.assertEqual(True, check)
def test_generate_signature(self): """ Ensures that the given values result in the expected signature given a certain private key and said signature can be validated with the related public key. """ expected = self.signature actual = generate_signature(self.value, self.timestamp, self.expires, self.name, self.meta, PRIVATE_KEY) self.assertEqual(expected, actual) # Check the resulting signature can be validated with the public key check = validate_signature(self.value, self.timestamp, self.expires, self.name, self.meta, expected, PUBLIC_KEY) self.assertEqual(True, check)