-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This also adds some small unit tests for DMARC parsing.
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright: 2024, ECP, NLnet Labs and the Internet.nl contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import pytest | ||
from pyparsing import ParseException | ||
|
||
from checks.tasks.dmarc_parser import _check_dmarc_uri, parse | ||
|
||
|
||
def test__check_dmarc_uri(): | ||
""" | ||
Check if None is returned on valid URI | ||
""" | ||
assert _check_dmarc_uri(["mailto:[email protected]"]) is None | ||
|
||
|
||
def test__check_dmarc_uri_detect_missing_uri_scheme(): | ||
""" | ||
Many people forget to add the mailto: scheme to their DMARC URI. | ||
This common error should be detected. | ||
""" | ||
with pytest.raises(ParseException): | ||
_check_dmarc_uri(["[email protected]"]) | ||
|
||
|
||
def test_parse(): | ||
sample_record = "v=DMARC1; p=none; rua=mailto:[email protected]" | ||
result = parse(sample_record) | ||
assert result.version == "v=DMARC1" | ||
assert result.directives.request == "p=none" | ||
assert result.directives.auri == "rua=mailto:[email protected]" |