Commit 98a7ce12 authored by Pawel Boening's avatar Pawel Boening

Merge branch 'drop-tests' into 'master'

Drops test

See merge request sre18/break-it!10
parents ee3269f6 5af99cc3
Pipeline #6627 passed with stage
in 7 minutes and 16 seconds
# We want to break it!
at least the smtp servers of the other groups..
## Run Tests
`python3 run.py testing.marschke.me 9001 smtp-server-group-a 6666
python3 run.py testing.marschke.me 9001 smtp-server-group-b 8008
python3 run.py testing.marschke.me 9001 smtp-server-group-c 5555
python3 run.py testing.marschke.me 9001 smtp-server-group-d 25
python3 run.py testing.marschke.me 9001 julianweise/simplesmtp 4431 --ssl --wait-up 2`
......@@ -2,7 +2,7 @@ import argparse
import sys
import unittest
from tests import TestFuzzing, TestMail, TestSession
from tests import TestDrops, TestFuzzing, TestMail, TestSession
from util import TestServer
......@@ -24,7 +24,7 @@ def main():
test_server = None
try:
test_server = TestServer(args.domain, args.port, args.docker_template, args.docker_port, args.ssl, args.wait_up)
for clazz in [TestFuzzing, TestMail, TestSession]:
for clazz in [TestDrops, TestFuzzing, TestMail, TestSession]:
for method in dir(clazz):
if method[:5] == 'test_':
suite.addTest(clazz(test_server, method))
......
import random
import time
from util import BaseTest
class TestDrops(BaseTest):
def assertResponse(self, expected_code, message=None): # pylint: disable=invalid-name
if isinstance(message, str):
message = message.encode('ASCII')
while message:
sliceLen = random.randint(1, len(message))
self.client.send(message[0:sliceLen])
message = message[sliceLen:]
time.sleep(random.uniform(0.01, 0.1))
super(TestDrops, self).assertResponse(expected_code)
def test_silly_window_syndrome(self):
self.assertResponse(250, 'HELO marschke.me\r\n')
self.assertResponse(250, 'MAIL FROM:<leonard@marschke.me>\r\n')
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')
self.assertResponse(250, '.\r\n')
self.assertResponse(221, 'QUIT\r\n')
......@@ -18,7 +18,6 @@ class TestFuzzing(BaseTest):
'VRFY',
''
]
random.seed(42)
for _ in range(0, 1337):
command = random.choice(possible_commands)+' '
command += ''.join(chr(random.randint(1, 127)) for x in range(random.randint(0, 127)))
......@@ -33,8 +32,7 @@ class TestFuzzing(BaseTest):
self.assertResponse([x for x in range(500, 510)], 'FAIL\r\n')
def test_fuzzing(self):
random.seed(42)
def test_unrecognized_command(self):
self.assertResponse(500, 'FAIL\r\n')
def test_sentry_issue_49(self):
......
from .TestDrops import TestDrops
from .TestFuzzing import TestFuzzing
from .TestMail import TestMail
from .TestSession import TestSession
import socket
import unittest
import random
class BaseTest(unittest.TestCase):
......@@ -13,6 +14,7 @@ class BaseTest(unittest.TestCase):
try:
self.client = self.test_server.create_client()
self.assertResponse(220)
random.seed(42)
return
except (ConnectionRefusedError, self.failureException) as exception:
if i == 1:
......@@ -36,10 +38,8 @@ class BaseTest(unittest.TestCase):
def format_message(message):
if not message or isinstance(message, bytes):
return message
if message[-2:] == '\r\n':
return message[:-2]
return message
if isinstance(expected_code, int):
......@@ -47,8 +47,7 @@ class BaseTest(unittest.TestCase):
if message:
if isinstance(message, str):
self.client.send(message.encode('ASCII'))
else:
message = message.encode('ASCII')
self.client.send(message)
message = format_message(message)
......
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