Skip to content

Commit

Permalink
Merge pull request #54 from Betree/fix-doctests
Browse files Browse the repository at this point in the history
Burnex: fix providers doctest
  • Loading branch information
Betree committed Dec 9, 2020
2 parents 88def9c + f397262 commit b24b031
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
5 changes: 1 addition & 4 deletions README.md
Expand Up @@ -42,10 +42,7 @@ iex> Burnex.is_burner? "\"this is a valid address! crazy right ?\"@yopmail.fr"
true

iex> Burnex.providers
#MapSet<["mysunrise.tech", "gmailom.co", "renwoying.org",
"xn--c3cralk2a3ak7a5gghbv.com", "ghork.live", "wellnessmarketing.solutions",
"zerograv.top", "votenoonnov6.com", "b45win.org", "muslimahcollection.online",
...]>
#MapSet<["mysunrise.tech", "gmailom.co", "renwoying.org", "xn--c3cralk2a3ak7a5gghbv.com", "ghork.live", "wellnessmarketing.solutions", "zerograv.top", "votenoonnov6.com", "b45win.org", "muslimahcollection.online", "barcntenef.ml", "lpi1iyi7m3zfb0i.gq", "ceco3kvloj5s3.tk", "outlettomsshoesstore.com", "kebabishcosladacoslada.com", "utoo.email", "pedia-egypt.org", "bestmemory.net", "8263813.com", "hz6m.com", "anocor.gq", "qvady.network", "2v3vjqapd6itot8g4z.gq", "yliora.site", "ectseep.site", "2m46.space", "godrejpropertiesforestgrove.com", "smart-thailand.com", "takebacktheregent.com", "dozarb.online", "mail22.space", "ttsbcq.us", "clubhowse.com", "gayflorida.net", "specialsshorts.info", "dubainaturalsoap.com", "carolynlove.website", "jlqiqd.tokyo", "kulitlumpia8.cf", "adastralflying.com", "superstachel.de", "diyarbakirengelliler.xyz", "notatempmail.info", "directproductinvesting.com", "francisxkelly.com", "saclouisvuittonboutiquefrance.com", "mainpokemon.com", "16up.ru", "upelmail.com", "374kj.com", ...]>
```

### With an Ecto changeset
Expand Down
7 changes: 2 additions & 5 deletions lib/burnex.ex
Expand Up @@ -72,15 +72,12 @@ defmodule Burnex do
end

@doc """
Returns the list of all blacklisted domains providers.
Returns the list of all blocked domains providers.
## Examples
iex> Burnex.providers()
#MapSet<["mysunrise.tech", "gmailom.co", "renwoying.org",
"xn--c3cralk2a3ak7a5gghbv.com", "ghork.live", "wellnessmarketing.solutions",
"zerograv.top", "votenoonnov6.com", "b45win.org", "muslimahcollection.online",
...]>
#MapSet<["mysunrise.tech", "gmailom.co", "renwoying.org", "xn--c3cralk2a3ak7a5gghbv.com", "ghork.live", "wellnessmarketing.solutions", "zerograv.top", "votenoonnov6.com", "b45win.org", "muslimahcollection.online", "barcntenef.ml", "lpi1iyi7m3zfb0i.gq", "ceco3kvloj5s3.tk", "outlettomsshoesstore.com", "kebabishcosladacoslada.com", "utoo.email", "pedia-egypt.org", "bestmemory.net", "8263813.com", "hz6m.com", "anocor.gq", "qvady.network", "2v3vjqapd6itot8g4z.gq", "yliora.site", "ectseep.site", "2m46.space", "godrejpropertiesforestgrove.com", "smart-thailand.com", "takebacktheregent.com", "dozarb.online", "mail22.space", "ttsbcq.us", "clubhowse.com", "gayflorida.net", "specialsshorts.info", "dubainaturalsoap.com", "carolynlove.website", "jlqiqd.tokyo", "kulitlumpia8.cf", "adastralflying.com", "superstachel.de", "diyarbakirengelliler.xyz", "notatempmail.info", "directproductinvesting.com", "francisxkelly.com", "saclouisvuittonboutiquefrance.com", "mainpokemon.com", "16up.ru", "upelmail.com", "374kj.com", ...]>
"""
def providers do
Expand Down
51 changes: 28 additions & 23 deletions test/burnex_test.exs
Expand Up @@ -8,69 +8,71 @@ defmodule BurnexTest do
doctest Burnex

test "example: filters jetable.org" do
assert Burnex.is_burner? "test@jetable.org"
assert Burnex.is_burner?("test@jetable.org")
end

test "strictly compare domain" do
providers = Burnex.providers()
refute Burnex.is_burner? "myemail@not_temporary_" <> Enum.random(providers)
refute Burnex.is_burner?("myemail@not_temporary_" <> Enum.random(providers))
end

test "with strange emails" do
# As ugly as it is, these are valid email formats
assert Burnex.is_burner? "\"forbidden@email\"@yopmail.fr"
assert Burnex.is_burner? "\"this is valid! crazy right ?\"@yopmail.fr"
assert Burnex.is_burner?("\"forbidden@email\"@yopmail.fr")
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"
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)
refute Enum.empty?(Burnex.providers())
end

test "providers list should not contains empty values" do
refute Enum.any?(Burnex.providers, &(String.length(&1) == 0))
refute Enum.any?(Burnex.providers(), &(String.length(&1) == 0))
end

test "providers should always be lowercase" do
refute Enum.any?(Burnex.providers, &(String.downcase(&1) != &1))
refute Enum.any?(Burnex.providers(), &(String.downcase(&1) != &1))
end

property "doesn't explode if email has bad format" do
check all email <- StreamData.string(:alphanumeric) do
refute Burnex.is_burner? email
check all(email <- StreamData.string(:alphanumeric)) do
refute Burnex.is_burner?(email)
end
end

property "should always detect emails with blacklisted providers" do
check all email <- email_generator(Burnex.providers) do
assert Burnex.is_burner? email
property "should always detect emails with blocked providers" do
check all(email <- email_generator(Burnex.providers())) do
assert Burnex.is_burner?(email)
end
end

property "is not fooled by uppercase domains" do
check all email <- email_generator(Burnex.providers) do
assert Burnex.is_burner? String.upcase(email)
check all(email <- email_generator(Burnex.providers())) do
assert Burnex.is_burner?(String.upcase(email))
end
end

@valid_providers ["gmail.com", "live.fr", "protonmail.com", "outlook.com"]
property "should always return false for valid providers" do
check all email <- email_generator(@valid_providers) do
refute Burnex.is_burner? email
check all(email <- email_generator(@valid_providers)) do
refute Burnex.is_burner?(email)
end
end

describe "mx record validation" do
test "correctly resolves domains with bad MX records" do
assert Burnex.check_domain_mx_record("jetable.org") == {:error, "Forbidden MX server(s): mx.jetable.org"}
assert Burnex.check_domain_mx_record("jetable.org") ==
{:error, "Forbidden MX server(s): mx.jetable.org"}
end

test "correctly resolves domains missing MX records" do
assert Burnex.check_domain_mx_record("somenonesensedomain.blahblahblah") == {:error, "Cannot find MX record"}
assert Burnex.check_domain_mx_record("somenonesensedomain.blahblahblah") ==
{:error, "Cannot find MX record"}
end

test "correctly resolves domains with 'good' MX records" do
Expand All @@ -79,16 +81,19 @@ defmodule BurnexTest do
"hotmail.com"
]
|> Enum.each(fn good_domain ->
assert Burnex.check_domain_mx_record(good_domain) == :ok, "#{good_domain} should have a good mailserver with valid MX record"
assert Burnex.check_domain_mx_record(good_domain) == :ok,
"#{good_domain} should have a good mailserver with valid MX record"
end)
end
end

# ---- Helpers ----

defp email_generator(providers) do
ExUnitProperties.gen all name <- StreamData.string(:alphanumeric),
domain <- StreamData.member_of(providers) do
ExUnitProperties.gen all(
name <- StreamData.string(:alphanumeric),
domain <- StreamData.member_of(providers)
) do
name <> "@" <> domain
end
end
Expand Down

0 comments on commit b24b031

Please sign in to comment.