diff --git a/myconext-server/src/main/java/myconext/cron/DisposableEmailProviders.java b/myconext-server/src/main/java/myconext/cron/DisposableEmailProviders.java index c6605448..4a809358 100644 --- a/myconext-server/src/main/java/myconext/cron/DisposableEmailProviders.java +++ b/myconext-server/src/main/java/myconext/cron/DisposableEmailProviders.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import myconext.exceptions.DisposableEmailProviderException; +import myconext.model.IdentityProvider; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -14,6 +15,7 @@ import org.springframework.stereotype.Component; import java.net.URL; +import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -55,7 +57,8 @@ public void resolveIDisposableEmailProviders() { objectMapper.readValue(new ClassPathResource(localLocation).getInputStream(), mapTypeReference) : objectMapper.readValue(new URL(remoteLocation), mapTypeReference); - disposableEmailProviders = ((Map) emailProviders.get("domains")).keySet(); + Map domains = (Map) emailProviders.get("domains"); + disposableEmailProviders = parseDisposableEmailProviders(domains); LOG.info(String.format("Resolved %s disposable email providers %s in %s ms", disposableEmailProviders.size(), this.testEnvironment ? localLocation : remoteLocation, System.currentTimeMillis() - start)); } catch (Exception e) { @@ -63,6 +66,19 @@ public void resolveIDisposableEmailProviders() { } } + @SuppressWarnings("unchecked") + private HashSet parseDisposableEmailProviders(Map domains) { + Set> entries = domains.entrySet(); + HashSet newDisposableEmailProviders = new HashSet<>(); + entries.forEach(entry -> { + String domain = entry.getKey(); + Map provider = (Map) entry.getValue(); + newDisposableEmailProviders.add(domain.toLowerCase()); + newDisposableEmailProviders.add(((String) provider.get("provider")).toLowerCase()); + }); + return newDisposableEmailProviders; + } + public void verifyDisposableEmailProviders(String email) { if (!denyDisposableEmailProviders) { return; diff --git a/myconext-server/src/test/java/myconext/cron/DisposableEmailProvidersTest.java b/myconext-server/src/test/java/myconext/cron/DisposableEmailProvidersTest.java index 8fd0dbf4..52dda9aa 100644 --- a/myconext-server/src/test/java/myconext/cron/DisposableEmailProvidersTest.java +++ b/myconext-server/src/test/java/myconext/cron/DisposableEmailProvidersTest.java @@ -17,6 +17,7 @@ void isDisposableEmailProviders() { Environment environment = new MockEnvironment(); DisposableEmailProviders subject = new DisposableEmailProviders(objectMapper, environment, true); assertThrows(DisposableEmailProviderException.class, () -> subject.verifyDisposableEmailProviders("jdoe@TRASHMAIL.WS")); + assertThrows(DisposableEmailProviderException.class, () -> subject.verifyDisposableEmailProviders("jdoe@fakermail.COM")); subject.verifyDisposableEmailProviders("jdoe@gmail.com"); DisposableEmailProviders subjectFeatureOff = new DisposableEmailProviders(objectMapper, environment, false); @@ -29,5 +30,6 @@ void isDisposableEmailProvidersLocalEnvironment() { environment.addActiveProfile("test"); DisposableEmailProviders subject = new DisposableEmailProviders(objectMapper, environment, true); assertThrows(DisposableEmailProviderException.class, () -> subject.verifyDisposableEmailProviders("jdoe@UJIXLAXPROS.tech")); + assertThrows(DisposableEmailProviderException.class, () -> subject.verifyDisposableEmailProviders("jdoe@kopeechka.STORE")); } } \ No newline at end of file