Commit f59c6ed2 authored by Adameck's avatar Adameck

added list for error codes

parent b8cca557
Pipeline #6598 failed with stage
in 6 minutes and 20 seconds
......@@ -31,7 +31,7 @@ class TestFuzzing(BaseTest):
except socket.timeout:
break
self.assertResponse(500, 'FAIL\r\n')
self.assertResponse([x for x in range(500, 510)], 'FAIL\r\n')
def test_fuzzing(self):
random.seed(42)
......
......@@ -9,17 +9,17 @@ class TestMail(BaseTest):
self.assertResponse(250, 'RCPT TO:<firstAddress@{}>\r\n'.format(self.test_server.domain))
self.assertResponse(250, 'RCPT TO:<secondAddress@{}>\r\n'.format(self.test_server.domain))
self.assertResponse(354, 'DATA\r\n' + \
'Date: Thu, 10 May 2018 10:33:29 -0100\r\n' + \
'FROM: Leonard Marschke<leonard@marschke.me>\r\n' + \
'Subject: Testmail\r\n' + \
'To: firstaddress@{}\r\n'.format(self.test_server.domain) + \
'\r\n' + \
'Hi all, this is\r\n' + \
'a second line.\r\n' + \
'And a third.\r\n' + \
'Single point incoming.\r\n' + \
'..\r\n' + \
'BR\r\n')
'Date: Thu, 10 May 2018 10:33:29 -0100\r\n' + \
'FROM: Leonard Marschke<leonard@marschke.me>\r\n' + \
'Subject: Testmail\r\n' + \
'To: firstaddress@{}\r\n'.format(self.test_server.domain) + \
'\r\n' + \
'Hi all, this is\r\n' + \
'a second line.\r\n' + \
'And a third.\r\n' + \
'Single point incoming.\r\n' + \
'..\r\n' + \
'BR\r\n')
self.assertResponse(250, '.\r\n')
self.assertResponse(221, 'QUIT\r\n')
......@@ -29,17 +29,17 @@ class TestMail(BaseTest):
self.assertResponse(250, 'rcpt to:<firstAddress@{}>\r\n'.format(self.test_server.domain))
self.assertResponse(250, 'rcpt to:<secondAddress@{}>\r\n'.format(self.test_server.domain))
self.assertResponse(354, 'data\r\n' + \
'Date: Thu, 10 May 2018 10:33:29 -0100\r\n' + \
'FROM: Leonard Marschke<leonard@marschke.me>\r\n' + \
'Subject: Testmail\r\n' + \
'To: firstaddress@{}\r\n'.format(self.test_server.domain) + \
'\r\n' + \
'Hi all, this is\r\n' + \
'a second line.\r\n' + \
'And a third.\r\n' + \
'Single point incoming.\r\n' + \
'..\r\n' + \
'BR\r\n')
'Date: Thu, 10 May 2018 10:33:29 -0100\r\n' + \
'FROM: Leonard Marschke<leonard@marschke.me>\r\n' + \
'Subject: Testmail\r\n' + \
'To: firstaddress@{}\r\n'.format(self.test_server.domain) + \
'\r\n' + \
'Hi all, this is\r\n' + \
'a second line.\r\n' + \
'And a third.\r\n' + \
'Single point incoming.\r\n' + \
'..\r\n' + \
'BR\r\n')
self.assertResponse(250, '.\r\n')
self.assertResponse(221, 'quit\r\n')
......@@ -49,17 +49,17 @@ class TestMail(BaseTest):
self.assertResponse(250, 'RcpT To:<firstAddress@{}>\r\n'.format(self.test_server.domain))
self.assertResponse(250, 'rCPt tO:<secondAddress@{}>\r\n'.format(self.test_server.domain))
self.assertResponse(354, 'dATa\r\n' + \
'Date: Thu, 10 May 2018 10:33:29 -0100\r\n' + \
'FROM: Leonard Marschke<leonard@marschke.me>\r\n' + \
'Subject: Testmail\r\n' + \
'To: firstaddress@{}\r\n'.format(self.test_server.domain) + \
'\r\n' + \
'Hi all, this is\r\n' + \
'a second line.\r\n' + \
'And a third.\r\n' + \
'Single point incoming.\r\n' + \
'..\r\n' + \
'BR\r\n')
'Date: Thu, 10 May 2018 10:33:29 -0100\r\n' + \
'FROM: Leonard Marschke<leonard@marschke.me>\r\n' + \
'Subject: Testmail\r\n' + \
'To: firstaddress@{}\r\n'.format(self.test_server.domain) + \
'\r\n' + \
'Hi all, this is\r\n' + \
'a second line.\r\n' + \
'And a third.\r\n' + \
'Single point incoming.\r\n' + \
'..\r\n' + \
'BR\r\n')
self.assertResponse(250, '.\r\n')
self.assertResponse(221, 'quIT\r\n')
......@@ -70,17 +70,17 @@ class TestMail(BaseTest):
self.assertResponse(250, 'RCPT TO:<firstAddress@{}>\r\n'.format(self.test_server.domain))
self.assertResponse(250, 'RCPT TO:<secondAddress@{}>\r\n'.format(self.test_server.domain))
self.assertResponse(354, 'DATA\r\n' + \
'Date: Thu, 10 May 2018 10:33:29 -0100\r\n' + \
'FROM: Leonard Marschke<leonard@marschke.me>\r\n' + \
'Subject: Testmail\r\n' + \
'To: firstaddress@{}\r\n'.format(self.test_server.domain) + \
'\r\n' + \
'Hi all, this is\r\n' + \
'a second line.\r\n' + \
'And a third.\r\n' + \
'Single point incoming.\r\n' + \
'..\r\n' + \
'BR\r\n')
'Date: Thu, 10 May 2018 10:33:29 -0100\r\n' + \
'FROM: Leonard Marschke<leonard@marschke.me>\r\n' + \
'Subject: Testmail\r\n' + \
'To: firstaddress@{}\r\n'.format(self.test_server.domain) + \
'\r\n' + \
'Hi all, this is\r\n' + \
'a second line.\r\n' + \
'And a third.\r\n' + \
'Single point incoming.\r\n' + \
'..\r\n' + \
'BR\r\n')
self.assertResponse(250, '.\r\n')
self.assertResponse(221, 'QUIT\r\n')
......
......@@ -15,7 +15,13 @@ class BaseTest(unittest.TestCase):
def tearDown(self):
self.client.close()
def assertResponse(self, expectedCode, message=None): # pylint: disable=invalid-name
def assertValueListEqual(self, value, expected_list, msg=None):
for expected in expected_list:
if value == expected:
return
raise self.failureException("{} not in {}: {}".format(value, expected_list, msg))
def assertResponse(self, expected_code, message=None): # pylint: disable=invalid-name
def format_message(message):
if not message or isinstance(message, bytes):
return message
......@@ -25,21 +31,26 @@ class BaseTest(unittest.TestCase):
return message
if isinstance(expected_code, int):
expected_code = [expected_code]
if message:
if isinstance(message, str):
self.client.send(message.encode('ASCII'))
else:
self.client.send(message)
message = format_message(message)
response = ''
while not response.endswith('\r\n'):
try:
byte = self.client.recv(1)
except socket.timeout:
raise self.failureException("Timeout with message <{}>".format(format_message(message)))
raise self.failureException("Timeout with message <{}>".format(message))
if byte == b'':
raise self.failureException("No code raised, but expected {}, message <{}>".format(
expectedCode, format_message(message)))
expected_code, message))
response += byte.decode('ASCII')
self.assertEqual(int(response[:3]), expectedCode, msg="Message <{}>".format(format_message(message)))
self.assertValueListEqual(int(response[:3]), expected_code, msg="Message <{}>".format(message))
if response[3] == '-':
self.assertResponse(expectedCode)
self.assertResponse(expected_code)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment