Example #1
0
 def test_original_message_unaffected(self):
     """
     Ensure the message (dict) passed into the function is not changed.
     """
     message = {
         'foo': 'bar',
         'baz': [1, 2, 3]
     }
     get_signed_message(message, PUBLIC_KEY, PRIVATE_KEY)
     self.assertNotIn('_p4p2p', message)
     self.assertEqual(2, len(message))
     self.assertIn('foo', message)
     self.assertIn('baz', message)
     self.assertEqual(message['foo'], 'bar')
     self.assertEqual(message['baz'], [1, 2, 3])
Example #2
0
 def test_signed_message_is_verifiable(self):
     """
     Check that the resulting message is able to be verified.
     """
     message = {
         'foo': 'bar',
         'baz': [1, 2, 3]
     }
     signed_message = get_signed_message(message, PUBLIC_KEY, PRIVATE_KEY)
     self.assertTrue(verify_message(signed_message))
Example #3
0
 def test_good_message(self):
     """
     The good case should pass.
     """
     message = {
         'foo': 'bar',
         'baz': [1, 2, 3]
     }
     signed_message = get_signed_message(message, PUBLIC_KEY, PRIVATE_KEY)
     self.assertTrue(verify_message(signed_message))
Example #4
0
 def test_modified_message(self):
     """
     The content of the message do not match the hash / signature.
     """
     message = {
         'foo': 'bar',
         'baz': [1, 2, 3]
     }
     signed_message = get_signed_message(message, PUBLIC_KEY, PRIVATE_KEY)
     signed_message['_p4p2p']['public_key'] = BAD_PUBLIC_KEY
     self.assertFalse(verify_message(message))
Example #5
0
 def test_expected_metadata(self):
     """
     Ensure the message (dict) returned from the function contains the
     expected metadata.
     """
     message = {
         'foo': 'bar',
         'baz': [1, 2, 3]
     }
     signed_message = get_signed_message(message, PUBLIC_KEY, PRIVATE_KEY)
     self.assertIn('_p4p2p', signed_message)
     metadata = signed_message['_p4p2p']
     self.assertIn('timestamp', metadata)
     self.assertIsInstance(metadata['timestamp'], float)
     self.assertIn('public_key', metadata)
     self.assertIsInstance(metadata['public_key'], basestring)
     self.assertIn('signature', metadata)
     self.assertIsInstance(metadata['signature'], basestring)
     self.assertEqual(3, len(metadata))