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

« back to all changes in this revision

Viewing changes to authres/tests

  • Committer: Scott Kitterman
  • Date: 2015-03-10 02:19:33 UTC
  • Revision ID: scott@kitterman.com-20150310021933-mnenhdmfmkaf19bx
Add rrvs to 'all features'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""
19
19
Package for parsing ``Authentication-Results`` headers as defined in RFC 5451.
20
20
Optional support for authentication methods defined in RFCs 5617, 6008, 6212,
21
 
7489 and draft-ietf-dmarc-arc-protocol-05.
 
21
and draft-kucherawy-dmarc-base-01.
22
22
>>> import authres
23
23
>>> str(authres.AuthenticationResultsHeader('test.example.org', version=1))
24
24
'Authentication-Results: test.example.org 1; none'
422
422
>>> str(arobj.results[1].properties[1].value)
423
423
'voucher.example.org'
424
424
 
425
 
# RFC 7489 DMARC example from opendmarc
 
425
# draft-kucherawy-dmarc-base-01 example from opendmarc
426
426
>>> import authres
427
427
>>> import authres.dmarc
428
428
>>> new_context = authres.FeatureContext(authres.dmarc)
525
525
... results = [mfrom_pass, helo_none]))
526
526
'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
527
 
528
 
# Create header field with ARC results (draft-ietf-dmarc-arc-protocol-05)
529
 
>>> import authres
530
 
>>> import authres.arc
531
 
>>> 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")
533
 
>>> str(authres.AuthenticationResultsHeader(authserv_id = 'example.com',
534
 
... 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'
536
 
 
537
528
# Parsing IP6 address.
538
529
>>> 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')
539
530
>>> str(arobj.results[0])
587
578
 
588
579
"""
589
580
 
590
 
# RFC 7293, The Require-Recipient-Valid-Since Header Field  and SMTP Service Extension, header field types
591
 
 
592
 
# Example 12.3 from RFC 7293
593
 
>>> import authres.rrvs
594
 
>>> rrvsarobj = authres_context.parse('Authentication-Results: mx.example.com; rrvs=pass smtp.rcptto=user@example.com')
595
 
>>> str(rrvsarobj.authserv_id)
596
 
'mx.example.com'
597
 
>>> str(rrvsarobj.results[0].method)
598
 
'rrvs'
599
 
>>> str(rrvsarobj.results[0].result)
600
 
'pass'
601
 
>>> str(rrvsarobj.results[0].reason)
602
 
'None'
603
 
>>> str(rrvsarobj.results[0].properties[0].type)
604
 
'smtp'
605
 
>>> str(rrvsarobj.results[0].properties[0].name)
606
 
'rcptto'
607
 
>>> str(rrvsarobj.results[0].properties[0].value)
608
 
'user@example.com'
609
 
 
610
 
>>> import authres.rrvs
611
 
>>> rrvs_fail = authres.rrvs.RRVSAuthenticationResult(result = 'fail', result_comment = 'Mail box expired.', smtp_rrvs = 'user@example.com', smtp_rrvs_comment = "These are not the droids you're looking for.")
612
 
>>> str(authres.AuthenticationResultsHeader(authserv_id='example.net',results = [rrvs_fail]))
613
 
"Authentication-Results: example.net; rrvs=fail (Mail box expired.) smtp.rrvs=user@example.com (These are not the droids you're looking for.)"
614
 
 
615
 
# New for RFC 7601 SMTP Auth Mail From
616
 
 
617
 
>>> import authres
618
 
>>> arobj = authres.AuthenticationResultsHeader.parse('Authentication-Results: example.com; auth=pass smtp.mailfrom=sender@example.net')
619
 
>>> str(arobj.authserv_id)
620
 
'example.com'
621
 
>>> str(arobj.results[0])
622
 
'auth=pass smtp.mailfrom=sender@example.net'
623
 
>>> str(arobj.results[0].method)
624
 
'auth'
625
 
>>> str(arobj.results[0].result)
626
 
'pass'
627
 
>>> str(arobj.results[0].smtp_mailfrom)
628
 
'sender@example.net'
629
 
>>> str(arobj.results[0].properties[0].type)
630
 
'smtp'
631
 
>>> str(arobj.results[0].properties[0].name)
632
 
'mailfrom'
633
 
>>> str(arobj.results[0].properties[0].value)
634
 
'sender@example.net'
635
 
 
636
 
# Create header field with RFC 7601 SMTP Auth Mail From
637
 
>>> import authres
638
 
>>> mfrom_auth = authres.SMTPAUTHAuthenticationResult(result = 'pass',
639
 
... smtp_mailfrom = 'mailauth@example.net')
640
 
>>> str(authres.AuthenticationResultsHeader(authserv_id = 'example.com',
641
 
... results = [mfrom_auth]))
642
 
'Authentication-Results: example.com; auth=pass smtp.mailfrom=mailauth@example.net'
643
 
 
644
581
# vim:sw=4 sts=4