Set up ground for E2E tests
- Use an environment variable to point at the configuration file while strating gpg-mailgate.py. - Unify paths: store temporary config, logs and anything else under 'test' directory. - Configure more tests (RSA, Ed25519). - Add test descriptions to be shown before they're started.
This commit is contained in:
parent
7a063a91b8
commit
27d7481078
16
Makefile
16
Makefile
|
@ -1,6 +1,18 @@
|
||||||
PYTHON = python2.7
|
PYTHON = python2.7
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test pre-clean clean
|
||||||
|
|
||||||
test:
|
test: test/tmp test/logs pre-clean
|
||||||
$(PYTHON) test/e2e_test.py
|
$(PYTHON) test/e2e_test.py
|
||||||
|
|
||||||
|
pre-clean:
|
||||||
|
rm -fv test/gpg-mailgate.conf
|
||||||
|
|
||||||
|
test/tmp:
|
||||||
|
mkdir test/tmp
|
||||||
|
|
||||||
|
test/logs:
|
||||||
|
mkdir test/logs
|
||||||
|
|
||||||
|
clean: pre-clean
|
||||||
|
rm -rfv test/tmp test/logs
|
||||||
|
|
17
test/e2e.ini
17
test/e2e.ini
|
@ -2,9 +2,22 @@
|
||||||
port = 2500
|
port = 2500
|
||||||
|
|
||||||
[tests]
|
[tests]
|
||||||
cases = 1
|
cases = 3
|
||||||
|
|
||||||
[case-1]
|
[case-1]
|
||||||
from = alice@localhost
|
descr = Clear text message to a user without a key
|
||||||
|
to = carlos@disposlab
|
||||||
in = test/msgin/clear2clear.msg
|
in = test/msgin/clear2clear.msg
|
||||||
out = test/msgout/clear2clear.msg
|
out = test/msgout/clear2clear.msg
|
||||||
|
|
||||||
|
[case-2]
|
||||||
|
descr = Clear text message to a user with an RSA key
|
||||||
|
to = alice@disposlab
|
||||||
|
in = test/msgin/clear2rsa.msg
|
||||||
|
out = test/msgout/clear2rsa.msg
|
||||||
|
|
||||||
|
[case-3]
|
||||||
|
descr = Clear text message to a user with an Ed25519 key
|
||||||
|
to = bob@disposlab
|
||||||
|
in = test/msgin/clear2ed.msg
|
||||||
|
out = test/msgout/clear2ed.msg
|
||||||
|
|
|
@ -8,8 +8,12 @@ import difflib
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
EOL = "\n"
|
EOL = "\n"
|
||||||
|
|
||||||
|
DELAY = 3
|
||||||
|
|
||||||
RELAY_SCRIPT = "test/relay.py"
|
RELAY_SCRIPT = "test/relay.py"
|
||||||
CONFIG_FILE = "test/gpg-mailgate.conf"
|
CONFIG_FILE = "test/gpg-mailgate.conf"
|
||||||
|
|
||||||
|
@ -19,7 +23,7 @@ def build_config(config):
|
||||||
cp = ConfigParser.ConfigParser()
|
cp = ConfigParser.ConfigParser()
|
||||||
|
|
||||||
cp.add_section("logging")
|
cp.add_section("logging")
|
||||||
cp.set("logging", "file", "/dev/stout")
|
cp.set("logging", "file", config["log_file"])
|
||||||
cp.set("logging", "verbose", "yes")
|
cp.set("logging", "verbose", "yes")
|
||||||
|
|
||||||
cp.add_section("gpg")
|
cp.add_section("gpg")
|
||||||
|
@ -75,7 +79,7 @@ def report_result(message_file, expected_file, test_output):
|
||||||
print diff_line
|
print diff_line
|
||||||
|
|
||||||
def execute_e2e_test(message_file, expected_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 = "GPG_MAILGATE_CONFIG=%s %s gpg-mailgate.py %s < %s" % (kwargs["config_path"], PYTHON_BIN, kwargs["to_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"])
|
||||||
|
|
||||||
logging.debug("Spawning: '%s'" % (result_command))
|
logging.debug("Spawning: '%s'" % (result_command))
|
||||||
|
@ -102,19 +106,26 @@ def load_config():
|
||||||
|
|
||||||
config = load_config()
|
config = load_config()
|
||||||
|
|
||||||
logging.basicConfig(filename = "e2e_test.log",
|
logging.basicConfig(filename = "test/logs/e2e.log",
|
||||||
format = "%(pathname)s:%(lineno)d %(levelname)s [%(funcName)s] %(message)s",
|
format = "%(asctime)s %(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,
|
config_path = os.getcwd() + "/" + CONFIG_FILE
|
||||||
|
|
||||||
|
write_test_config(config_path,
|
||||||
port = config.getint("relay", "port"),
|
port = config.getint("relay", "port"),
|
||||||
gpg_keyhome = "test/keyhome",
|
gpg_keyhome = "test/keyhome",
|
||||||
smime_certpath = "test/certs")
|
smime_certpath = "test/certs",
|
||||||
|
log_file = "test/logs/gpg-mailgate.log")
|
||||||
|
|
||||||
for case_no in range(1, config.getint("tests", "cases")+1):
|
for case_no in range(1, config.getint("tests", "cases")+1):
|
||||||
case_name = "case-%d" % (case_no)
|
case_name = "case-%d" % (case_no)
|
||||||
|
print "Executing: %s" % (config.get(case_name, "descr"))
|
||||||
|
|
||||||
execute_e2e_test(config.get(case_name, "in"), config.get(case_name, "out"),
|
execute_e2e_test(config.get(case_name, "in"), config.get(case_name, "out"),
|
||||||
from_addr = config.get(case_name, "from"),
|
config_path = config_path,
|
||||||
port = config.getint("relay", "port"))
|
to_addr = config.get(case_name, "to"),
|
||||||
|
port = config.getint("relay", "port"))
|
||||||
|
|
||||||
|
sleep(DELAY)
|
||||||
|
|
|
@ -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.
|
|
@ -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.
|
|
@ -12,6 +12,8 @@ import sys
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
|
||||||
|
EXIT_UNAVAILABLE = 1
|
||||||
|
|
||||||
BUFFER_SIZE = 4096
|
BUFFER_SIZE = 4096
|
||||||
EOM = "\r\n.\r\n"
|
EOM = "\r\n.\r\n"
|
||||||
LAST_LINE = -3
|
LAST_LINE = -3
|
||||||
|
@ -32,8 +34,12 @@ def receive_and_confirm(session):
|
||||||
|
|
||||||
def serve(port):
|
def serve(port):
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
s.bind(('', port))
|
try:
|
||||||
s.listen(1)
|
s.bind(('', port))
|
||||||
|
s.listen(1)
|
||||||
|
except socket.error, e:
|
||||||
|
print "Cannot connect", e
|
||||||
|
sys.exit(EXIT_UNAVAILABLE)
|
||||||
|
|
||||||
(conn, addr) = s.accept()
|
(conn, addr) = s.accept()
|
||||||
conn.sendall(welcome("TEST SERVER"))
|
conn.sendall(welcome("TEST SERVER"))
|
||||||
|
|
Loading…
Reference in New Issue