From d1fd8b48692438873823558c6be0c2a2122a64dc Mon Sep 17 00:00:00 2001 From: Benjamin Piouffle Date: Sat, 20 Jan 2018 16:56:39 +1100 Subject: [PATCH] Not fooled anymore by uppercase domains --- lib/burnex.ex | 2 +- mix.exs | 2 +- test/burnex_test.exs | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/burnex.ex b/lib/burnex.ex index b290067..368b2cb 100644 --- a/lib/burnex.ex +++ b/lib/burnex.ex @@ -22,7 +22,7 @@ defmodule Burnex do """ @spec is_burner?(String.t) :: boolean() def is_burner?(email) do - case Regex.run(~r/@([^@]+)$/, email) do + case Regex.run(~r/@([^@]+)$/, String.downcase(email)) do [_ | [provider]] -> Enum.any?(@providers, &Kernel.==(provider, &1)) _ -> diff --git a/mix.exs b/mix.exs index e92eb7c..050d944 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Burnex.Mixfile do def project do [ app: :burnex, - version: "1.0.0", + version: "1.0.1", elixir: "~> 1.5", description: "Elixir burner email (temporary address) detector", start_permanent: Mix.env == :prod, diff --git a/test/burnex_test.exs b/test/burnex_test.exs index 06d7b10..a912613 100644 --- a/test/burnex_test.exs +++ b/test/burnex_test.exs @@ -27,6 +27,10 @@ defmodule BurnexTest do 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)) + end + property "doesn't explode if email has bad format" do check all email <- StreamData.string(:alphanumeric) do refute Burnex.is_burner? email @@ -39,6 +43,12 @@ defmodule BurnexTest do 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) + 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