@@ -296,10 +296,44 @@ def testSPFMissingARecord(self):
296296 spf_record = '"v=spf1 a ~all"'
297297 domain = "cardinalhealth.net"
298298 results = checkdmarc .spf .parse_spf_record (spf_record , domain )
299- self .assertIn (
300- "An a mechanism points to cardinalhealth.net, but that domain/subdomain does not have any A/AAAA records." ,
301- results ["warnings" ],
302- )
299+ snipit = "that domain/subdomain does not have any A/AAAA records."
300+ self .assertTrue (any (snipit in s for s in results ["warnings" ]))
301+
302+ @unittest .skipUnless (os .path .exists ("/etc/resolv.conf" ), "no network" )
303+ def testSPFMXMechanism (self ):
304+ """Addresses are included in the output for SPF records with an mx lookup"""
305+ spf_record = "v=spf1 mx:proton.me ~all"
306+ domain = "example.com"
307+ results = checkdmarc .spf .parse_spf_record (spf_record , domain )
308+ for mechanism in results ["parsed" ]["mechanisms" ]:
309+ if mechanism ["mechanism" ] == "mx" :
310+ self .assertTrue (len (mechanism ["hosts" ] ) > 0 )
311+ for host in mechanism ["hosts" ]:
312+ self .assertTrue (len (host ) > 0 )
313+
314+ def testSPFMacrosExists (self ):
315+ """SPF macros can be used with the exists mechanism"""
316+ record = "v=spf1 exists:exists:%{i}.spf.hc0000-xx.iphmx.com ~all"
317+ domain = "example.com"
318+ results = checkdmarc .spf .parse_spf_record (record , domain )
319+ self .assertTrue (len (results ["parsed" ]["mechanisms" ]) > 0 )
320+
321+ def testSPFMacrosInclude (self ):
322+ """SPF macros can be used with the exists mechanism"""
323+ record = "v=spf1 include:include:%{ir}.%{v}.%{d}.spf.has.pphosted.com ~all"
324+ domain = "example.com"
325+ results = checkdmarc .spf .parse_spf_record (record , domain )
326+ self .assertTrue (len (results ["parsed" ]["mechanisms" ]) > 0 )
327+
328+
329+ def testSPFAMechanism (self ):
330+ """Addresses are included in the output for SPF records with an a lookup"""
331+ spf_record = "v=spf1 a ~all"
332+ domain = "example.com"
333+ results = checkdmarc .spf .parse_spf_record (spf_record , domain )
334+ for mechanism in results ["parsed" ]["mechanisms" ]:
335+ if mechanism ["mechanism" ] == "a" :
336+ self .assertTrue (len (mechanism ["addresses" ] ) > 0 )
303337
304338 @unittest .skipUnless (os .path .exists ("/etc/resolv.conf" ), "no network" )
305339 def testDMARCPctLessThan100Warning (self ):
0 commit comments