def test_message(self): """Test message initialization.""" m = radius.Message(radius.CODE_ACCESS_REQUEST, TEST_SECRET, attributes={}) self.assertLess(0, m.id) self.assertGreater(256, m.id) self.assertEqual(16, len(m.authenticator)) self.assertIsInstance(m.attributes, radius.Attributes)
def create_reply(m1, code=radius.CODE_ACCESS_REJECT, attributes={}): """ Helper function. """ m1_data = m1.pack() m2 = radius.Message(TEST_SECRET, code, id=m1.id, authenticator=m1.authenticator, attributes=attributes) # Pack the second message with an invalid authenticator. m2_data = m2.pack() # Then calculate the correct authenticator using the message data. # Replace the authenticator with the correct one. m2.authenticator = md5( m2_data[:4] + m1.authenticator + m2_data[20:] + TEST_SECRET ).digest() return m2