james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [5/6] james-project git commit: JAMES-2420 Fix DLP item hashCode
Date Thu, 06 Sep 2018 07:54:48 GMT
JAMES-2420 Fix DLP item hashCode

We should not depend on a compiled pattern but rather on the underlying string.


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b1062f35
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b1062f35
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b1062f35

Branch: refs/heads/master
Commit: b1062f3501faf103e446de1056dbb309baefe4d6
Parents: f1ca57c
Author: Benoit Tellier <btellier@linagora.com>
Authored: Fri Aug 31 15:48:40 2018 +0700
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Thu Sep 6 09:54:20 2018 +0200

----------------------------------------------------------------------
 .../apache/james/dlp/api/DLPConfigurationItem.java  |  2 +-
 .../james/dlp/api/DLPConfigurationItemTest.java     | 16 ++++++++++++++++
 .../webadmin/routes/DLPConfigurationRoutesTest.java |  5 ++++-
 3 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b1062f35/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
index 9d4dbe6..e8dc4e2 100644
--- a/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
+++ b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
@@ -273,7 +273,7 @@ public class DLPConfigurationItem {
 
     @Override
     public final int hashCode() {
-        return Objects.hash(id, explanation, regexp, targets);
+        return Objects.hash(id, explanation, regexp.pattern(), targets);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1062f35/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
index 2cd7296..f5237e0 100644
--- a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
+++ b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
@@ -106,6 +106,22 @@ public class DLPConfigurationItemTest {
     }
 
     @Test
+    void hashCodeShouldBeEqualForSimilarRules() {
+        assertThat(
+            DLPConfigurationItem.builder()
+                .id(UNIQUE_ID)
+                .expression(REGEX)
+                .build()
+                .hashCode())
+            .isEqualTo(
+                DLPConfigurationItem.builder()
+                    .id(UNIQUE_ID)
+                    .expression(REGEX)
+                    .build()
+                    .hashCode());
+    }
+
+    @Test
     void expressionShouldBeValidPattern() {
         assertThatThrownBy(() ->
             DLPConfigurationItem.builder()

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1062f35/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DLPConfigurationRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DLPConfigurationRoutesTest.java
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DLPConfigurationRoutesTest.java
index 2abefc8..e2d4c40 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DLPConfigurationRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DLPConfigurationRoutesTest.java
@@ -55,6 +55,7 @@ import org.mockito.Mockito;
 import io.restassured.RestAssured;
 import io.restassured.http.ContentType;
 import io.restassured.specification.RequestSpecification;
+import net.javacrumbs.jsonunit.core.Option;
 
 class DLPConfigurationRoutesTest {
 
@@ -409,7 +410,9 @@ class DLPConfigurationRoutesTest {
             .extract()
                 .body().asString();
 
-            assertThatJson(retrievedBody).isEqualTo(updatedBody);
+            assertThatJson(retrievedBody)
+                .when(Option.IGNORING_ARRAY_ORDER)
+                .isEqualTo(updatedBody);
         }
         
         @Test


---------------------------------------------------------------------
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