james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1240986 - in /james/server/trunk: data-hbase/src/main/java/org/apache/james/domainlist/hbase/ data-jpa/src/main/java/org/apache/james/domainlist/jpa/ data-library/src/test/java/org/apache/james/domainlist/lib/
Date Mon, 06 Feb 2012 11:42:31 GMT
Author: eric
Date: Mon Feb  6 11:42:31 2012
New Revision: 1240986

URL: http://svn.apache.org/viewvc?rev=1240986&view=rev
Log:
Disallow the insertion of two same domains that are with different cases (JAMES-1369)

Modified:
    james/server/trunk/data-hbase/src/main/java/org/apache/james/domainlist/hbase/HBaseDomainList.java
    james/server/trunk/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java
    james/server/trunk/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java

Modified: james/server/trunk/data-hbase/src/main/java/org/apache/james/domainlist/hbase/HBaseDomainList.java
URL: http://svn.apache.org/viewvc/james/server/trunk/data-hbase/src/main/java/org/apache/james/domainlist/hbase/HBaseDomainList.java?rev=1240986&r1=1240985&r2=1240986&view=diff
==============================================================================
--- james/server/trunk/data-hbase/src/main/java/org/apache/james/domainlist/hbase/HBaseDomainList.java
(original)
+++ james/server/trunk/data-hbase/src/main/java/org/apache/james/domainlist/hbase/HBaseDomainList.java
Mon Feb  6 11:42:31 2012
@@ -52,10 +52,14 @@ public class HBaseDomainList extends Abs
      */
     @Override
     public boolean containsDomain(String domain) throws DomainListException {
+        String lowerCasedDomain = domain.toLowerCase();
+        if (containsDomain(lowerCasedDomain)) {
+            throw new DomainListException(lowerCasedDomain + " already exists.");
+        }
         HTable table = null;
         try {
             table = TablePool.getInstance().getDomainlistTable();
-            Get get = new Get(Bytes.toBytes(domain));
+            Get get = new Get(Bytes.toBytes(lowerCasedDomain));
             Result result = table.get(get);
             if (! result.isEmpty()) {
                 return true;

Modified: james/server/trunk/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java
URL: http://svn.apache.org/viewvc/james/server/trunk/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java?rev=1240986&r1=1240985&r2=1240986&view=diff
==============================================================================
--- james/server/trunk/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java
(original)
+++ james/server/trunk/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java
Mon Feb  6 11:42:31 2012
@@ -120,11 +120,15 @@ public class JPADomainList extends Abstr
      * org.apache.james.domainlist.api.DomainList#addDomain(java.lang.String)
      */
     public void addDomain(String domain) throws DomainListException {
+        String lowerCasedDomain = domain.toLowerCase();
+        if (containsDomain(lowerCasedDomain)) {
+            throw new DomainListException(lowerCasedDomain + " already exists.");
+        }
         EntityManager entityManager = entityManagerFactory.createEntityManager();
         final EntityTransaction transaction = entityManager.getTransaction();
         try {
             transaction.begin();
-            JPADomain jpaDomain = new JPADomain(domain);
+            JPADomain jpaDomain = new JPADomain(lowerCasedDomain);
             entityManager.persist(jpaDomain);
             transaction.commit();
         } catch (PersistenceException e) {

Modified: james/server/trunk/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java?rev=1240986&r1=1240985&r2=1240986&view=diff
==============================================================================
--- james/server/trunk/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java
(original)
+++ james/server/trunk/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java
Mon Feb  6 11:42:31 2012
@@ -21,6 +21,7 @@ package org.apache.james.domainlist.lib;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
+import junit.framework.Assert;
 import junit.framework.TestCase;
 
 import org.apache.james.dnsservice.api.DNSService;
@@ -35,6 +36,7 @@ public abstract class AbstractDomainList
 
     // Domains we will play with.
     private final String DOMAIN_1 = "domain1.tld";
+    private final String DOMAIN_1_UPPER_CASE = "Domain1.tld";
     private final String DOMAIN_2 = "domain2.tld";
     private final String DOMAIN_3 = "domain3.tld";
     private final String DOMAIN_4 = "domain4.tld";
@@ -91,6 +93,24 @@ public abstract class AbstractDomainList
     }
 
     /**
+     * Add two same domains with different cases, and check we've got an exception.
+     * 
+     * @throws DomainListException
+     */
+    public void testUpperCaseSameDomain() throws DomainListException {
+        domainList.addDomain(DOMAIN_1);
+        assertEquals(1, domainList.getDomains().length);
+        try {
+            domainList.addDomain(DOMAIN_1_UPPER_CASE);
+        }
+        catch (DomainListException domainListException) {
+            Assert.assertTrue(domainListException.getMessage().contains(DOMAIN_1));
+            return;
+        }
+        Assert.fail("We should not be able to insert same domains, even with different caxes");
+    }
+
+    /**
      * Add a domain and remove another domain, and check first domain is still
      * present.
      * 



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message