Skip to content

Commit

Permalink
CI: test a static message generated with dkimpy
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerysong committed Oct 12, 2024
1 parent a41cf9e commit bd3e303
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
9 changes: 9 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ def private_key(scope='session'):
res = subprocess.run(binargs, capture_output=True, text=True)
with open(pubpath, 'w') as f:
key = ''.join(res.stdout.splitlines()[1:-1])
f.write((
'sel._domainkey.dkimpy.example.com v=DKIM1; k=rsa; '
'p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqf/MoqRqzK3/bcCyLSx5'
'CDvyPotNDBjLLFHdMmcWDiSZ8saslFyNR6FkFxuNtw843m7MkwOSJ9TRd9p+OoRLDv'
'H0jDR1Dqq22QOJKiG5XQ91aZwin9jpWKkuoRoRZRhWrzUOJWAybHarsEQm9iCPh2zn'
'dbSPSzPQL1OsjURIuw5G9+/nr5rhJ72Qi6v86zofWUKdXhLf+oVmho79D0xGMFFm0f'
'b98xIeZlgJTnmrj/zuxIKHeVmGKI1j6L3xttdcDiUVRGxoubkFzg9TIBGhdeFkpa0C'
'ZuhB/1/U3f1oG3Upx5o/jXTQk/dwVaaeEXnRmTsfGYn4GQ9ziity1ijLsQIDAQAB\n'
))
f.write(f'elpmaxe._domainkey.example.com v=DKIM1; k=rsa; p={key}\n')


Expand Down
57 changes: 48 additions & 9 deletions test/test_milter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@

@pytest.fixture
def run_miltertest(request, milter, milter_config):
def _run_miltertest(headers=None):
def _run_miltertest(headers=None, standard_headers=True, body='test body\r\n'):
headers = headers or []
headers.extend(
[
['From', '[email protected]\n'],
['Date', 'Fri, 04 Oct 2024 10:11:12 -0400'],
['Subject', request.function.__name__],
]
)
if standard_headers:
headers.extend(
[
['From', '[email protected]\n'],
['Date', 'Fri, 04 Oct 2024 10:11:12 -0400'],
['Subject', request.function.__name__],
]
)

# Connect
sock = socket.socket(family=socket.AF_UNIX)
Expand All @@ -36,7 +37,7 @@ def _run_miltertest(headers=None):
conn.send(libmilter.SMFIC_EOH)

# Send body
conn.send_body('test body\r\n')
conn.send_body(body)
resp = conn.send_eom()
ins_headers = []
for msg in resp:
Expand Down Expand Up @@ -65,6 +66,44 @@ def test_milter_basic(run_miltertest):
assert res['headers'][3] == ['ARC-Authentication-Results', 'i=1; example.com; arc=none']


def test_milter_staticmsg(run_miltertest):
headers = [
['ARC-Seal', (
'i=1; cv=none; a=rsa-sha256; d=dkimpy.example.com; s=sel;\r\n'
' t=1728713840;\r\n'
' b=jmHJmDXHe4eFAurv+yXz1RTRLj+XNaHedD4GYWPt0XntR94pMNSFlU2TxT0rzkMcE4Nkt\r\n'
' xFrz0OYVfexpgNJ393tO8czBH4OwEwV2E5h+U/8N1vM+KHKfcg2n02SOxUa991Z1+CXUrO6\r\n'
' lUnIx7gN+iz3x2muWG6hm6d1J0h4+yaQCuVlNImf3PM/M7l57GbfHvQpbYI9m4hf6IMncRS\r\n'
' sOuXyTaH8NrWpqqM0KctxR4x+kC/Y3dKNYcL5VwbajlXletkmHO79sbuGD0HsK8HUdzfE1Z\r\n'
' gGinobwxRu7skmTPq0TSlBQQ/1fuxpSOpocjnY+E/g3FH3ZsAtbOG2jVYd9w=='
)],
['ARC-Message-Signature', (
'i=1; a=rsa-sha256; c=relaxed/relaxed;\r\n'
' d=dkimpy.example.com; s=sel; t=1728713840; h=content-type :\r\n'
' mime-version : content-transfer-encoding : subject : from : to : from;\r\n'
' bh=Pb6s/Xlf4u1eDlYyO0NCaMRMrCg6xDNkK5byz8RDY1s=;\r\n'
' b=dmFKbeiAEsaA/gnLQyuRBcX72pvARuJMrZIptplgCGp9vqudMP2ngI/g8eo63nQYMB0md\r\n'
' AaofYsl5lD8qE/B20FDgn66jTHQIGsPi0Fv06Mf45NaTFpeaEyexjZunYXSLao3RY5Cqtac\r\n'
' m0BcCS/MaaiMBoDmcRa5GOzBi02coJG5IsDt+ZWT6P7nHQHrDNsuLBeJBX7+vJ0bM9QHbCE\r\n'
' Q+eZZxcT7W2MWaByV2Jjz4B+sh0IzfX2wPNsGOsNpD+MvpehQsa9ig7eEndNWw7V1qpaMN+\r\n'
' vtOnb5H80nu0K4H7fvrNUI4h4b+UTumqR/HhiNTFRobUGiwuvrP4CWHj3dtQ==\r\n'
)],
['ARC-Authentication-Results', 'i=1; dkimpy.example.com'],
['Content-Type', 'text/plain; charset="us-ascii"'],
['MIME-Version', '1.0'],
['Content-Transfer-Encoding', '7bit'],
['Subject', 'test message from dkimpy'],
['From', '[email protected]'],
['To', '[email protected]'],
]
res = run_miltertest(headers, False, 'test message\r\n')
assert res['headers'][0] == ['Authentication-Results', 'example.com; arc=pass smtp.remote-ip=127.0.0.1']
assert res['headers'][1][0] == 'ARC-Seal'
assert 'cv=pass' in res['headers'][1][1]
assert res['headers'][2][0] == 'ARC-Message-Signature'
assert res['headers'][3] == ['ARC-Authentication-Results', 'i=2; example.com; arc=pass']


def test_milter_resign(run_miltertest):
"""Extend the chain as much as possible"""
res = run_miltertest()
Expand Down

0 comments on commit bd3e303

Please sign in to comment.