|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import os |
| 4 | +import subprocess |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture() |
| 10 | +def private_key(scope='session'): |
| 11 | + filepath = os.path.dirname(os.path.realpath(__file__)) |
| 12 | + filepath = os.path.join(filepath, 'files', 'private.key') |
| 13 | + binargs = [ |
| 14 | + 'openssl', |
| 15 | + 'genrsa', |
| 16 | + '-out', filepath, |
| 17 | + '2048', |
| 18 | + ] |
| 19 | + subprocess.run(binargs) |
| 20 | + |
| 21 | + |
| 22 | +@pytest.fixture() |
| 23 | +def tool_path(scope='session'): |
| 24 | + def _tool_path(tool): |
| 25 | + binpath = os.path.dirname(os.path.realpath(__file__)) |
| 26 | + binpath = os.path.join(binpath, '..', tool) |
| 27 | + return os.path.realpath(binpath) |
| 28 | + return _tool_path |
| 29 | + |
| 30 | + |
| 31 | +@pytest.fixture() |
| 32 | +def milter_config(request, private_key): |
| 33 | + base_path = os.path.join(request.fspath.dirname, 'files') |
| 34 | + for candidate in [ |
| 35 | + request.fspath.basename, # test file |
| 36 | + request.function.__name__, # test function |
| 37 | + ]: |
| 38 | + fname = os.path.join(base_path, '.'.join([candidate, 'conf'])) |
| 39 | + if os.path.isfile(fname): |
| 40 | + return fname |
| 41 | + |
| 42 | + return os.path.join(base_path, 'milter.conf') |
| 43 | + |
| 44 | + |
| 45 | +@pytest.fixture() |
| 46 | +def milter_cmdline(tmp_path, tool_path, milter_config): |
| 47 | + return [ |
| 48 | + tool_path('openarc/openarc'), |
| 49 | + '-f', |
| 50 | + '-v', |
| 51 | + '-c', milter_config, |
| 52 | + '-p', tmp_path.joinpath('milter.sock'), |
| 53 | + ] |
| 54 | + |
| 55 | + |
| 56 | +@pytest.fixture() |
| 57 | +def milter(milter_cmdline): |
| 58 | + milter_proc = subprocess.Popen(milter_cmdline) |
| 59 | + |
| 60 | + yield milter_proc |
| 61 | + |
| 62 | + milter_proc.terminate() |
0 commit comments