Skip to content

Commit

Permalink
Validate subdomains (#46)
Browse files Browse the repository at this point in the history
* test subdomain validation (fails)

* Get test passing
  • Loading branch information
peaceful-james committed Nov 7, 2020
1 parent 7889ce0 commit bbb5169
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/burnex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,19 @@ defmodule Burnex do
"""
@spec is_burner_domain?(binary()) :: boolean()
def is_burner_domain?(domain) do
MapSet.member?(@providers, domain)
case MapSet.member?(@providers, domain) do
false ->
case Regex.run(~r/^[^.]+[.](.*)$/, domain) do
[_ | [higher_domain]] ->
is_burner_domain?(higher_domain)

nil ->
false
end

true ->
true
end
end

@doc """
Expand Down
5 changes: 5 additions & 0 deletions test/burnex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ defmodule BurnexTest do
assert Burnex.is_burner? "\"this is valid! crazy right ?\"@yopmail.fr"
end

test "with subdomains" do
assert Burnex.is_burner? "hello@mail2.mailinator.com"
assert Burnex.is_burner? "hello@reject2.maildrop.cc"
end

test "providers list should never be empty" do
refute Enum.empty?(Burnex.providers)
end
Expand Down

0 comments on commit bbb5169

Please sign in to comment.