aboutsummaryrefslogtreecommitdiffstats
path: root/test/lithium_spf_lexer_test.exs
diff options
context:
space:
mode:
authorGravatar Johannes Christ <[email protected]>2025-04-21 18:17:33 +0200
committerGravatar Johannes Christ <[email protected]>2025-04-30 21:03:42 +0200
commit8e07e0005c4c440ee118d4673bb9962954683532 (patch)
tree0eb3718929a2842b5af98642112be2e71bc516cd /test/lithium_spf_lexer_test.exs
parentAdd GNU Guix manifest for development (diff)
WIP: RFC 7208 Sender Policy Framework implementationspf-bootstrap
Diffstat (limited to 'test/lithium_spf_lexer_test.exs')
-rw-r--r--test/lithium_spf_lexer_test.exs40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/lithium_spf_lexer_test.exs b/test/lithium_spf_lexer_test.exs
new file mode 100644
index 0000000..47ab9bf
--- /dev/null
+++ b/test/lithium_spf_lexer_test.exs
@@ -0,0 +1,40 @@
+# SPDX-FileCopyrightText: 2025 Johannes Christ
+# SPDX-License-Identifier: AGPL-3.0-or-later
+defmodule :lithium_spf_lexer_test do
+ use ExUnit.Case, async: true
+
+ test "parses simple record" do
+ record = ~c"v=spf1 include:_spf.google.com ~all"
+
+ assert {:ok,
+ [
+ unknown_modifier: {~c"v", ~c"spf1"},
+ directive: {:pass, {~c"include", ~c"_spf.google.com"}},
+ directive: {:softfail, {~c"all", []}}
+ ], 1} = :lithium_spf_lexer.string(record)
+ end
+
+ test "parses ip4 record" do
+ record = ~c"v=spf1 ip4:193.57.144.0/24 ip6:2a0f:85c0::/4 -all"
+
+ assert {:ok,
+ [
+ unknown_modifier: {~c"v", ~c"spf1"},
+ directive: {:pass, {{193, 57, 144, 0}, 24}},
+ directive: {:pass, {{10767, 34240, 0, 0, 0, 0, 0, 0}, 4}},
+ directive: {:fail, {~c"all", []}}
+ ], 1} = :lithium_spf_lexer.string(record)
+ end
+
+ test "parses awful record" do
+ record = ~c"v=spf1 exists:%{ir}.%{v}.arpa.%{o}._spf.lmax.com include:%{o}._spf.lmax.com -all"
+
+ assert {:ok,
+ [
+ unknown_modifier: {~c"v", ~c"spf1"},
+ directive: {:pass, {~c"exists", ~c"%{ir}.%{v}.arpa.%{o}._spf.lmax.com"}},
+ directive: {:pass, {~c"include", ~c"%{o}._spf.lmax.com"}},
+ directive: {:fail, {~c"all", []}}
+ ], 1} = :lithium_spf_lexer.string(record)
+ end
+end