Skip to content

Commit

Permalink
tests: clean up minor nits
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerysong committed Oct 19, 2024
1 parent 854d92e commit 7977005
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 53 deletions.
4 changes: 2 additions & 2 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +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((
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; h=sha256; p={key}\n')


Expand Down
112 changes: 61 additions & 51 deletions test/test_milter.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,32 @@ def test_milter_v2(run_miltertest):

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-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'],
Expand Down Expand Up @@ -151,7 +157,7 @@ def test_milter_resign(run_miltertest):
# quick and dirty parsing
ams = {x[0].strip(): x[1].strip() for x in [y.split('=', 1) for y in ''.join(res['headers'][2][1].splitlines()).split(';')]}
ams_h = [x.strip() for x in ams['h'].lower().split(':')]
assert not any([x in ams_h for x in ['authentication-results', 'arc-seal', 'arc-message-signature', 'arc-authentication-results']])
assert not any(x in ams_h for x in ['authentication-results', 'arc-seal', 'arc-message-signature', 'arc-authentication-results'])
else:
assert len(res['headers']) == 1

Expand Down Expand Up @@ -202,12 +208,14 @@ def test_milter_mode_none_sign(run_miltertest):
[
# Single header
[
[(
'example.com;'
' iprev=pass\n\tpolicy.iprev=192.0.2.1 (mail.example.com);'
'\n\tspf=pass (domain of [email protected]\n\t designates 192.0.2.1 as permitted sender);'
' dkim=pass [email protected] header.s=foo'
)],
[
(
'example.com;'
' iprev=pass\n\tpolicy.iprev=192.0.2.1 (mail.example.com);'
'\n\tspf=pass (domain of [email protected]\n\t designates 192.0.2.1 as permitted sender);'
' dkim=pass [email protected] header.s=foo'
)
],
(
'iprev=pass policy.iprev=192.0.2.1 (mail.example.com);'
'\n\tspf=pass (domain of [email protected] designates 192.0.2.1 as permitted sender);'
Expand Down Expand Up @@ -245,28 +253,30 @@ def test_milter_mode_none_sign(run_miltertest):
],
# Header with more results than we're willing to store
[
[(
'example.com;'
' dkim=pass [email protected] header.s=foo;'
' dkim=pass [email protected] header.s=bar;'
' dkim=pass [email protected] header.s=baz;'
' dkim=pass [email protected] header.s=qux;'
' dkim=pass [email protected] header.s=quux;'
' dkim=pass [email protected] header.s=quuux;'
' dkim=fail [email protected] header.s=foo;'
' dkim=fail [email protected] header.s=bar;'
' dkim=fail [email protected] header.s=baz;'
' dkim=fail [email protected] header.s=qux;'
' dkim=fail [email protected] header.s=quux;'
' dkim=fail [email protected] header.s=quuux;'
' dkim=policy [email protected] header.s=foo;'
' dkim=policy [email protected] header.s=bar;'
' dkim=policy [email protected] header.s=baz;'
' dkim=policy [email protected] header.s=qux;'
' dkim=policy [email protected] header.s=quux;'
' dkim=policy [email protected] header.s=quuux;'
' spf=pass'
)],
[
(
'example.com;'
' dkim=pass [email protected] header.s=foo;'
' dkim=pass [email protected] header.s=bar;'
' dkim=pass [email protected] header.s=baz;'
' dkim=pass [email protected] header.s=qux;'
' dkim=pass [email protected] header.s=quux;'
' dkim=pass [email protected] header.s=quuux;'
' dkim=fail [email protected] header.s=foo;'
' dkim=fail [email protected] header.s=bar;'
' dkim=fail [email protected] header.s=baz;'
' dkim=fail [email protected] header.s=qux;'
' dkim=fail [email protected] header.s=quux;'
' dkim=fail [email protected] header.s=quuux;'
' dkim=policy [email protected] header.s=foo;'
' dkim=policy [email protected] header.s=bar;'
' dkim=policy [email protected] header.s=baz;'
' dkim=policy [email protected] header.s=qux;'
' dkim=policy [email protected] header.s=quux;'
' dkim=policy [email protected] header.s=quuux;'
' spf=pass'
)
],
(
'dkim=pass [email protected] header.s=foo;'
'\n\tdkim=pass [email protected] header.s=bar;'
Expand All @@ -285,7 +295,7 @@ def test_milter_mode_none_sign(run_miltertest):
'\n\tdkim=policy [email protected] header.s=baz;'
'\n\tdkim=policy [email protected] header.s=qux;'
'\n\tarc=none smtp.remote-ip=127.0.0.1'
)
),
],
# Non-matching authserv-id
[
Expand Down Expand Up @@ -387,7 +397,7 @@ def test_milter_mode_none_sign(run_miltertest):
],
'arc=none smtp.remote-ip=127.0.0.1',
],
]
],
)
def test_milter_ar(run_miltertest, data):
"""Test Authentication-Results parsing"""
Expand Down

0 comments on commit 7977005

Please sign in to comment.