def test_process(self): exp = ExpectAlert() state = ConnectionState() msg = Message(ContentType.alert, bytearray(2)) exp.process(state, msg)
def test_process_with_values_not_matching_anything(self): exp = ExpectAlert(AlertLevel.warning, AlertDescription.bad_record_mac) state = ConnectionState() msg = Message(ContentType.alert, bytearray(b'\xff\xff')) with self.assertRaises(AssertionError): exp.process(state, msg)
def test_process_with_values(self): exp = ExpectAlert(AlertLevel.warning, AlertDescription.unknown_psk_identity) state = ConnectionState() msg = Message(ContentType.alert, bytearray(b'\x01\x73')) exp.process(state, msg)
def test_process_with_values_and_not_matching_level(self): exp = ExpectAlert(AlertLevel.fatal, AlertDescription.unknown_psk_identity) state = ConnectionState() msg = Message(ContentType.alert, bytearray(b'\x01\x73')) with self.assertRaises(AssertionError): exp.process(state, msg)
def test_process_with_multiple_values_one_matching_description(self): exp = ExpectAlert(AlertLevel.fatal, [AlertDescription.record_overflow, AlertDescription.decompression_failure]) state = ConnectionState() msg = Message(ContentType.alert, bytearray(b'\x02\x16')) # does NOT raise exception exp.process(state, msg)
def test_process_with_values_not_matching_anything(self): exp = ExpectAlert(AlertLevel.warning, AlertDescription.bad_record_mac) state = ConnectionState() msg = Message(ContentType.alert, bytearray(b'\xff\xff')) with self.assertRaises(AssertionError) as e: exp.process(state, msg) self.assertEqual( str(e.exception), "Alert level 255 != 1, " "Expected alert description " "\"bad_record_mac\" does not match received " "\"255\"")