Skip to content

Commit 45cbb91

Browse files
committed
CI: add basic framework
1 parent 0676227 commit 45cbb91

File tree

10 files changed

+157
-26
lines changed

10 files changed

+157
-26
lines changed

.github/workflows/build.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: build
2+
on:
3+
push:
4+
pull_request:
5+
6+
jobs:
7+
flake8:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Check out code
11+
uses: actions/checkout@v4
12+
13+
- name: Install flake8
14+
run: sudo pip install flake8
15+
16+
- name: Lint Python code
17+
run: flake8 --max-line-length=160
18+
19+
check:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Check out code
23+
uses: actions/checkout@v4
24+
25+
- name: apt update
26+
run: sudo apt update
27+
28+
- name: Install dependencies
29+
run: sudo apt install libbsd-dev liblua5.4-dev libmilter-dev libssl-dev
30+
31+
- name: Install Python dependencies
32+
run: sudo pip install pytest
33+
34+
- name: Build OpenARC
35+
run: |
36+
autoreconf -fiv
37+
CFLAGS='-Wall' ./configure
38+
make -j4
39+
40+
- name: Check out miltertest
41+
uses: actions/checkout@v4
42+
with:
43+
repository: flowerysong/miltertest
44+
path: miltertest
45+
46+
- name: Build miltertest
47+
run: |
48+
autoreconf -fiv
49+
./configure
50+
make
51+
working-directory: ${{ github.workspace }}/miltertest
52+
53+
- name: Test OpenARC
54+
run: |
55+
make check
56+
57+
- name: Build OpenARC with clang
58+
run: |
59+
make distclean
60+
CC=clang ./configure
61+
make -j4
62+
63+
- name: Build OpenARC without milter
64+
run: |
65+
make distclean
66+
CC=clang ./configure --disable-filter
67+
make -j4

Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
AUTOMAKE_OPTIONS = foreign
55
ACLOCAL_AMFLAGS = -I m4
66

7-
SUBDIRS = libopenarc contrib docs openarc
7+
SUBDIRS = libopenarc contrib docs openarc test
88
dist_doc_DATA = LICENSE LICENSE.Sendmail RELEASE_NOTES
99
dist_noinst_SCRIPTS = libtool
1010

configure.ac

+1-25
Original file line numberDiff line numberDiff line change
@@ -888,31 +888,6 @@ AC_SUBST(LIBOPENARC_INC)
888888
AC_DEFINE_UNQUOTED([LIBOPENARC_FEATURE_STRING], "$LIBOPENARC_FEATURE_STRING",
889889
[Feature string for printing])
890890

891-
#
892-
# setup for testing
893-
#
894-
895-
AC_ARG_ENABLE([live-testing],
896-
AS_HELP_STRING([--disable-live-testing],
897-
[disable tests that require Internet access]),
898-
[live_tests="$enable_live_testing"], [live_tests="yes"])
899-
AM_CONDITIONAL(LIVE_TESTS, test x"$live_tests" = x"yes")
900-
901-
#
902-
# specify test socket
903-
#
904-
905-
AC_ARG_WITH([test-socket],
906-
AS_HELP_STRING([--with-test-socket],
907-
[specify socket to use for all tests]),
908-
[testsocket="$withval"], [testsocket=""])
909-
AM_CONDITIONAL(TEST_SOCKET, test x"$testsocket" != x"")
910-
if test x"$testsocket" != x""
911-
then
912-
TESTSOCKET=$testsocket
913-
AC_SUBST(TESTSOCKET)
914-
fi
915-
916891
#
917892
# Platform Specific Configuration
918893
#
@@ -983,5 +958,6 @@ AC_CONFIG_FILES([
983958
openarc/openarc.8
984959
openarc/openarc.conf.5
985960
openarc/openarc.conf.simple
961+
test/Makefile
986962
])
987963
AC_OUTPUT

test/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

test/Makefile.am

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
EXTRA_DIST = files pytest.ini *.py
2+
3+
check:
4+
pytest -vv

test/conftest.py

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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()

test/files/milter.conf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Domain example.com
2+
KeyFile private.key
3+
Selector elpmaxe

test/files/test_config_fail.conf

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Domain example.com
2+
Selector elpmaxe

test/pytest.ini

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
console_output_style = count
3+
log_file = pytest.log

test/test_config.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python3
2+
3+
import subprocess
4+
5+
6+
def test_config(milter):
7+
pass
8+
9+
10+
def test_config_fail(milter_cmdline):
11+
res = subprocess.run(milter_cmdline, capture_output=True, text=True, timeout=4)
12+
assert res.returncode != 0
13+
assert 'parameter "KeyFile" required when signing' in res.stderr

0 commit comments

Comments
 (0)