diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/lithium_spf_lexer_test.exs | 40 | ||||
-rw-r--r-- | test/lithium_spf_test.exs | 33 |
2 files changed, 73 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 diff --git a/test/lithium_spf_test.exs b/test/lithium_spf_test.exs new file mode 100644 index 0000000..9843009 --- /dev/null +++ b/test/lithium_spf_test.exs @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2025 Johannes Christ +# SPDX-License-Identifier: AGPL-3.0-or-later +defmodule :lithium_spf_test do + use ExUnit.Case + + @ip {127, 0, 0, 127} + @sender ~c"mike@localhost" + + defp check_domain(domain) do + :lithium_spf.check_host(@ip, domain, @sender) + end + + describe "domain validation" do + test "rejects empty domain" do + assert {:none, [invalid_domain: :not_multi_label]} = check_domain(~c"") + end + + test "rejects empty label" do + assert {:none, [invalid_domain: :label_empty]} = check_domain(~c".host") + end + + test "rejects non-multi label domain name" do + assert {:none, [invalid_domain: :not_multi_label]} = check_domain(~c"host") + end + + test "rejects too long label" do + over_sixty_three_chars = + ~c"hellojoehellomikesystemworkingseemstobeokayfineletrytrathatagainbutintroduceabug.localhost" + + assert {:none, [invalid_domain: :label_too_long]} = check_domain(over_sixty_three_chars) + end + end +end |