Polish E2E testing script and make it configurable
This commit is contained in:
parent
f3f56a47bc
commit
7a063a91b8
|
@ -0,0 +1,6 @@
|
||||||
|
PYTHON = python2.7
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
|
||||||
|
test:
|
||||||
|
$(PYTHON) test/e2e_test.py
|
|
@ -39,9 +39,14 @@ import traceback
|
||||||
from M2Crypto import BIO, Rand, SMIME, X509
|
from M2Crypto import BIO, Rand, SMIME, X509
|
||||||
from email.mime.message import MIMEMessage
|
from email.mime.message import MIMEMessage
|
||||||
|
|
||||||
|
# Environment variable name we read to retrieve configuration path. This is to
|
||||||
|
# enable non-root users to set up and run GPG Mailgate and to make the software
|
||||||
|
# testable.
|
||||||
|
CONFIG_PATH_ENV = "GPG_MAILGATE_CONFIG"
|
||||||
|
|
||||||
# Read configuration from /etc/gpg-mailgate.conf
|
# Read configuration from /etc/gpg-mailgate.conf
|
||||||
_cfg = RawConfigParser()
|
_cfg = RawConfigParser()
|
||||||
_cfg.read('/etc/gpg-mailgate.conf')
|
_cfg.read(os.getenv(CONFIG_PATH_ENV, '/etc/gpg-mailgate.conf'))
|
||||||
cfg = dict()
|
cfg = dict()
|
||||||
for sect in _cfg.sections():
|
for sect in _cfg.sections():
|
||||||
cfg[sect] = dict()
|
cfg[sect] = dict()
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
[relay]
|
||||||
|
port = 2500
|
||||||
|
|
||||||
|
[tests]
|
||||||
|
cases = 1
|
||||||
|
|
||||||
|
[case-1]
|
||||||
|
from = alice@localhost
|
||||||
|
in = test/msgin/clear2clear.msg
|
||||||
|
out = test/msgout/clear2clear.msg
|
|
@ -8,8 +8,6 @@ import difflib
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
TEST_PORT = 2500
|
|
||||||
|
|
||||||
EOL = "\n"
|
EOL = "\n"
|
||||||
|
|
||||||
RELAY_SCRIPT = "test/relay.py"
|
RELAY_SCRIPT = "test/relay.py"
|
||||||
|
@ -66,17 +64,17 @@ def compare(result, expected):
|
||||||
fromfile='expected',
|
fromfile='expected',
|
||||||
tofile='output')
|
tofile='output')
|
||||||
|
|
||||||
def report_result(message_file, test_output):
|
def report_result(message_file, expected_file, test_output):
|
||||||
expected = load_file(message_file)
|
expected = load_file(expected_file)
|
||||||
diff = compare(test_output, expected)
|
diff = compare(test_output, expected)
|
||||||
if len(list(diff)) > 0:
|
if len(list(diff)) > 0:
|
||||||
print "Output and the expected message don't match:"
|
print "Output and the expected message (%s) don't match:" % (expected_file)
|
||||||
else:
|
else:
|
||||||
print "Message %s processed properly" % (message_file)
|
print "Message %s processed properly" % (message_file)
|
||||||
for diff_line in diff:
|
for diff_line in diff:
|
||||||
print diff_line
|
print diff_line
|
||||||
|
|
||||||
def execute_e2e_test(message_file, **kwargs):
|
def execute_e2e_test(message_file, expected_file, **kwargs):
|
||||||
test_command = "%s gpg-mailgate.py %s < %s" % (PYTHON_BIN, kwargs["from_addr"], message_file)
|
test_command = "%s gpg-mailgate.py %s < %s" % (PYTHON_BIN, kwargs["from_addr"], message_file)
|
||||||
result_command = "%s %s %d" % (PYTHON_BIN, RELAY_SCRIPT, kwargs["port"])
|
result_command = "%s %s %d" % (PYTHON_BIN, RELAY_SCRIPT, kwargs["port"])
|
||||||
|
|
||||||
|
@ -93,18 +91,30 @@ def execute_e2e_test(message_file, **kwargs):
|
||||||
|
|
||||||
logging.debug("Read %d characters of test output: '%s'" % (len(testout), testout))
|
logging.debug("Read %d characters of test output: '%s'" % (len(testout), testout))
|
||||||
|
|
||||||
report_result(message_file, testout)
|
report_result(message_file, expected_file, testout)
|
||||||
|
|
||||||
|
def load_config():
|
||||||
|
cp = ConfigParser.ConfigParser()
|
||||||
|
cp.read("test/e2e.ini")
|
||||||
|
|
||||||
|
return cp
|
||||||
|
|
||||||
|
|
||||||
|
config = load_config()
|
||||||
|
|
||||||
logging.basicConfig(filename = "e2e_test.log",
|
logging.basicConfig(filename = "e2e_test.log",
|
||||||
|
format = "%(pathname)s:%(lineno)d %(levelname)s [%(funcName)s] %(message)s",
|
||||||
datefmt = "%Y-%m-%d %H:%M:%S",
|
datefmt = "%Y-%m-%d %H:%M:%S",
|
||||||
level = logging.DEBUG)
|
level = logging.DEBUG)
|
||||||
|
|
||||||
write_test_config(os.getcwd() + "/" + CONFIG_FILE,
|
write_test_config(os.getcwd() + "/" + CONFIG_FILE,
|
||||||
port = TEST_PORT,
|
port = config.getint("relay", "port"),
|
||||||
gpg_keyhome = "test/keyhome",
|
gpg_keyhome = "test/keyhome",
|
||||||
smime_certpath = "test/certs")
|
smime_certpath = "test/certs")
|
||||||
|
|
||||||
execute_e2e_test("test.msg",
|
for case_no in range(1, config.getint("tests", "cases")+1):
|
||||||
from_addr = "alice@localhost",
|
case_name = "case-%d" % (case_no)
|
||||||
port = TEST_PORT)
|
|
||||||
|
execute_e2e_test(config.get(case_name, "in"), config.get(case_name, "out"),
|
||||||
|
from_addr = config.get(case_name, "from"),
|
||||||
|
port = config.getint("relay", "port"))
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
From: Bob <bob@localhost>
|
||||||
|
To: Alice <alice@localhost>
|
||||||
|
Subject: Test
|
||||||
|
|
||||||
|
Body of the message.
|
|
@ -0,0 +1,5 @@
|
||||||
|
From: Bob <bob@localhost>
|
||||||
|
To: Alice <alice@localhost>
|
||||||
|
Subject: Test
|
||||||
|
|
||||||
|
Body of the message.
|
Loading…
Reference in New Issue