~ar-python-hackers/authentication-results-python/trunk

« back to all changes in this revision

Viewing changes to authres/tests

  • Committer: Scott Kitterman
  • Date: 2018-10-30 03:44:32 UTC
  • Revision ID: scott@kitterman.com-20181030034432-mtoe0qvj31wavzjf
Tags: 1.1.1
--- 1.1.1 2018-10-30
  + Added ARC specific tags for draft-ietf-dmarc-arc-protocol-18 (as of IETF
    last call, still experimental), smtp.remote-ip and header.oldest-pass

Show diffs side-by-side

added added

removed removed

Lines of Context:
160
160
>>> dar_fail.match_signature('mail-router.example.net')
161
161
False
162
162
 
 
163
RFC 5451 B.6(1) modified to use d= instead of i= with header.a and header.s added
 
164
>>> import authres
 
165
>>> dsr_pass = authres.DKIMAuthenticationResult(result = 'pass', result_comment = 'good signature',
 
166
... header_d = 'mail-router.example.net', header_a = 'rsa-sha256', header_s = 'default')
 
167
>>> dsr_fail = authres.DKIMAuthenticationResult(result = 'fail',
 
168
... header_d = 'newyork.example.com', result_comment = 'bad signature')
 
169
>>> str(authres.AuthenticationResultsHeader(authserv_id = 'example.com',
 
170
... results = [dsr_pass, dsr_fail]))
 
171
'Authentication-Results: example.com; dkim=pass (good signature) header.d=mail-router.example.net header.a=rsa-sha256 header.s=default; dkim=fail (bad signature) header.d=newyork.example.com'
 
172
>>> dsr_pass.match_signature_algorithm('mail-router.example.net', 'rsa-sha256')
 
173
True
 
174
>>> dsr_fail.match_signature_algorithm('mail-router.example.net', 'rsa-sha256')
 
175
False
 
176
 
 
177
Header from dcrup testing
 
178
>>> import authres
 
179
>>> dss_pass = authres.DKIMAuthenticationResult(result = 'pass', result_comment = 'Good 256 bit ed25519-sha256 signature.',
 
180
... header_d = 'example.com', header_i = '@example.com', header_a = 'ed25519-sha256')
 
181
>>> dss_fail = authres.DKIMAuthenticationResult(result = 'fail', result_comment = 'Bad 1024 bit rsa-sha256 signature.',
 
182
... header_d = 'example.com', header_i = '@example.com', header_a = 'rsa-sha256')
 
183
>>> str(authres.AuthenticationResultsHeader(authserv_id = 'relay02.example.org',
 
184
... results = [dss_pass, dss_fail]))
 
185
'Authentication-Results: relay02.example.org; dkim=pass (Good 256 bit ed25519-sha256 signature.) header.d=example.com header.i=@example.com header.a=ed25519-sha256; dkim=fail (Bad 1024 bit rsa-sha256 signature.) header.d=example.com header.i=@example.com header.a=rsa-sha256'
 
186
 
163
187
# Missing parsing header comment.
164
188
#FIXME
165
189
>>> import authres
525
549
... results = [mfrom_pass, helo_none]))
526
550
'Authentication-Results: example.com; spf=pass smtp.mailfrom=authenticated@example.net; spf=none reason="No SPF record for HELO" smtp.helo=mailserver.example.net'
527
551
 
528
 
# Create header field with ARC results (draft-ietf-dmarc-arc-protocol-05)
 
552
# Create header field with ARC results (draft-ietf-dmarc-arc-protocol-18)
529
553
>>> import authres
530
554
>>> import authres.arc
531
555
>>> arc_pass = authres.arc.ARCAuthenticationResult(result = 'pass',
532
 
... header_ams_d = 'example.net', header_ams_s='valimail2016', header_as_d="example.com", header_as_s="valimail2017")
 
556
... header_ams_d = 'example.net', header_ams_s='valimail2016', header_as_d="example.com", header_as_s="valimail2017", header_oldest_pass='1', smtp_remote_ip='203.0.113.1')
533
557
>>> str(authres.AuthenticationResultsHeader(authserv_id = 'example.com',
534
558
... results = [arc_pass]))
535
 
'Authentication-Results: example.com; arc=pass header.ams-d=example.net header.ams-s=valimail2016 header.as-d=example.com header.as-s=valimail2017'
 
559
'Authentication-Results: example.com; arc=pass header.ams-d=example.net header.ams-s=valimail2016 header.as-d=example.com header.as-s=valimail2017 header.oldest-pass=1 smtp.remote-ip=203.0.113.1'
536
560
 
537
561
# Parsing IP6 address.
538
562
>>> arobj = authres_context.parse('Authentication-Results: mail.bmsi.com; iprev=pass policy.iprev="2001:748:100:40::2:2" (mout0.freenet.de); spf=none smtp.mailfrom=markuslaudi@freenet.de')
641
665
... results = [mfrom_auth]))
642
666
'Authentication-Results: example.com; auth=pass smtp.mailfrom=mailauth@example.net'
643
667
 
 
668
# Ignore unknown method (RFC 7601 2.7.6 SHOULD)
 
669
>>> import authres
 
670
>>> arobj = authres.AuthenticationResultsHeader.parse('Authentication-Results: mail.example.org; tls=pass smtp.TLSversion=TLSv1.2 smtp.TLScyper=ECDHE-RSA-CHACHA20-POLY1305 smtp.TLSbits=256')
 
671
>>> str(arobj.authserv_id)
 
672
'mail.example.org'
 
673
>>> str(arobj.results[0])
 
674
'tls=pass smtp.tlsversion=TLSv1.2 smtp.tlscyper=ECDHE-RSA-CHACHA20-POLY1305 smtp.tlsbits=256'
 
675
>>> str(arobj.results[0].method)
 
676
'tls'
 
677
>>> str(arobj.results[0].result)
 
678
'pass'
 
679
>>> try: str(arobj.results[0].smtp_mailfrom)
 
680
... except AttributeError as e: print(e)
 
681
'AuthenticationResult' object has no attribute 'smtp_mailfrom'
 
682
>>> str(arobj.results[0].properties[0].type)
 
683
'smtp'
 
684
>>> str(arobj.results[0].properties[0].name)
 
685
'tlsversion'
 
686
>>> str(arobj.results[0].properties[0].value)
 
687
'TLSv1.2'
 
688
 
 
689
 
 
690
# Invalid ptype (error) and unknown method (OK)
 
691
>>> import authres
 
692
>>> try: arobj = authres.AuthenticationResultsHeader.parse('Authentication-Results: mail.example.org; x-tls=pass version=TLSv1.2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256')
 
693
... except authres.SyntaxError as e: print(e)
 
694
 
 
695
>>> str(arobj.authserv_id)
 
696
'mail.example.org'
 
697
>>> str(arobj.results[0])
 
698
'x-tls=pass'
 
699
 
 
700
# Valid ptype (OK), unknown method (OK), unknown property (OKish)
 
701
>>> import authres
 
702
>>> try: arobj = authres.AuthenticationResultsHeader.parse('Authentication-Results: mail.example.org; x-tls=pass smtp.tlsversion=TLSv1.2')
 
703
... except authres.SyntaxError as e: print(e)
 
704
>>> str(arobj.authserv_id)
 
705
'mail.example.org'
 
706
>>> str(arobj.results[0])
 
707
'x-tls=pass smtp.tlsversion=TLSv1.2'
 
708
>>> str(arobj.results[0].method)
 
709
'x-tls'
 
710
>>> str(arobj.results[0].result)
 
711
'pass'
 
712
>>> try: str(arobj.results[0].smtp_mailfrom)
 
713
... except AttributeError as e: print(e)
 
714
'AuthenticationResult' object has no attribute 'smtp_mailfrom'
 
715
>>> try: str(arobj.results[0].smtp_tlsversion)
 
716
... except AttributeError as e: print(e)
 
717
'AuthenticationResult' object has no attribute 'smtp_tlsversion'
 
718
>>> str(arobj.results[0].properties[0].type)
 
719
'smtp'
 
720
>>> str(arobj.results[0].properties[0].name)
 
721
'tlsversion'
 
722
>>> str(arobj.results[0].properties[0].value)
 
723
'TLSv1.2'
 
724
 
 
725
# Parse multiple result header field and toss out unknown ptype
 
726
>>> import authres
 
727
>>> arobj = authres.AuthenticationResultsHeader.parse('Authentication-Results: mail.example.org; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=example.net header.i=@example.net header.b=Qgi/FoC0; dmarc=none (p=none) header.from=example.net; spf=none smtp.mailfrom=test@example.net smtp.helo=mail-wm0-x232.example.com; x-tls=pass version=TLSv1.2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256')
 
728
>>> for result in arobj.results:
 
729
...     result.method
 
730
...     result.result
 
731
'arc'
 
732
'none'
 
733
'dkim'
 
734
'pass'
 
735
'dmarc'
 
736
'none'
 
737
'spf'
 
738
'none'
 
739
'x-tls'
 
740
'pass'
 
741
 
 
742
# Repeat authserv_id for each result (invalid)
 
743
>>> import authres
 
744
>>> try: arobj = authres.AuthenticationResultsHeader.parse('authentication-results: thehesiod.com; dkim=none (message not signed) header.d=none;thehesiod.com; dmarc=none action=none header.from=hotmail.com;')
 
745
... except authres.SyntaxError as e: print(e)
 
746
Syntax error: Expected "=" at: ; dmarc=none action=none header.from=hot...
 
747
 
644
748
# vim:sw=4 sts=4