You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ip...@apache.org on 2019/12/24 12:28:14 UTC

[ignite] branch master updated: IGNITE-12469: Sensitive data hidden for CorruptedTreeException. - Fixes #7163.

This is an automated email from the ASF dual-hosted git repository.

ipavlukhin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new db0e507  IGNITE-12469: Sensitive data hidden for CorruptedTreeException. - Fixes #7163.
db0e507 is described below

commit db0e507e824895daab2568071cb4c8142b2275e6
Author: Evgeny Stanilovskiy <es...@gridgain.com>
AuthorDate: Tue Dec 24 15:27:34 2019 +0300

    IGNITE-12469: Sensitive data hidden for CorruptedTreeException. - Fixes #7163.
    
    Signed-off-by: ipavlukhin <vo...@gmail.com>
---
 .../apache/ignite/testframework/GridTestUtils.java | 24 ++++++++
 .../processors/query/h2/opt/H2CacheRow.java        |  8 ++-
 .../index/H2TreeCorruptedTreeExceptionTest.java    | 72 +++++++++++++++++-----
 3 files changed, 87 insertions(+), 17 deletions(-)

diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
index fd51fa7..1c4baf5 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
@@ -34,8 +34,10 @@ import java.net.InetAddress;
 import java.net.MulticastSocket;
 import java.net.ServerSocket;
 import java.nio.file.attribute.PosixFilePermission;
+import java.security.AccessController;
 import java.security.GeneralSecurityException;
 import java.security.KeyStore;
+import java.security.PrivilegedAction;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
@@ -1541,6 +1543,28 @@ public final class GridTestUtils {
     }
 
     /**
+     * Change static final fields.
+     * @param field Need to be changed.
+     * @param newVal New value.
+     * @throws Exception If failed.
+     */
+    public static void setFieldValue(Field field, Object newVal) throws Exception {
+        field.setAccessible(true);
+        Field modifiersField = Field.class.getDeclaredField("modifiers");
+
+        AccessController.doPrivileged(new PrivilegedAction() {
+            @Override
+            public Object run() {
+                modifiersField.setAccessible(true);
+                return null;
+            }
+        });
+
+        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
+        field.set(null, newVal);
+    }
+
+    /**
      * Get inner class by its name from the enclosing class.
      *
      * @param parentCls Parent class to resolve inner class for.
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/H2CacheRow.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/H2CacheRow.java
index 4bd584f..b9998a6 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/H2CacheRow.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/H2CacheRow.java
@@ -26,10 +26,13 @@ import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
 import org.apache.ignite.internal.processors.query.QueryUtils;
 import org.apache.ignite.internal.processors.query.h2.H2Utils;
+import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.SB;
 import org.h2.value.Value;
 import org.h2.value.ValueNull;
 
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_TO_STRING_INCLUDE_SENSITIVE;
+
 /**
  * Table row implementation based on {@link GridQueryTypeDescriptor}.
  */
@@ -310,7 +313,8 @@ public class H2CacheRow extends H2Row implements CacheDataRow {
         sb.a("[ key: ").a(v == null ? "nil" : v.getString());
 
         v = valueWrapped();
-        sb.a(", val: ").a(v == null ? "nil" : v.getString());
+        sb.a(", val: ").a(v == null ? "nil" : (S.INCLUDE_SENSITIVE ? v.getString() :
+            "Data hidden due to " + IGNITE_TO_STRING_INCLUDE_SENSITIVE + " flag."));
 
         sb.a(" ][ ");
 
@@ -322,7 +326,7 @@ public class H2CacheRow extends H2Row implements CacheDataRow {
                     sb.a(", ");
 
                 if (!desc.isKeyValueOrVersionColumn(i))
-                    sb.a(v == null ? "nil" : v.getString());
+                    sb.a(v == null ? "nil" : (S.INCLUDE_SENSITIVE ? v.getString() : "data hidden"));
             }
         }
 
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2TreeCorruptedTreeExceptionTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2TreeCorruptedTreeExceptionTest.java
index 1b8fdd6..203fa7b 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2TreeCorruptedTreeExceptionTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2TreeCorruptedTreeExceptionTest.java
@@ -33,13 +33,15 @@ import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHan
 import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandlerWrapper;
 import org.apache.ignite.internal.processors.query.h2.database.H2Tree;
 import org.apache.ignite.internal.util.typedef.X;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.ListeningTestLogger;
 import org.apache.ignite.testframework.LogListener;
 import org.apache.ignite.testframework.MessageOrderLogListener;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.junit.Test;
 
-import static java.lang.String.format;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_TO_STRING_INCLUDE_SENSITIVE;
 
 /** */
 public class H2TreeCorruptedTreeExceptionTest extends GridCommonAbstractTest {
@@ -50,6 +52,9 @@ public class H2TreeCorruptedTreeExceptionTest extends GridCommonAbstractTest {
     private static final String GRP_NAME = "cacheGrp";
 
     /** */
+    private static final String VERY_SENS_STR_DATA = "here_comes_very_sensitive_data@#123#321#@";
+
+    /** */
     private final AtomicBoolean failWithCorruptTree = new AtomicBoolean(false);
 
     /** */
@@ -57,9 +62,13 @@ public class H2TreeCorruptedTreeExceptionTest extends GridCommonAbstractTest {
 
     /** */
     private final LogListener logListener = new MessageOrderLogListener(
-        format(".*?Tree is corrupted.*?cacheId=65, cacheName=A, indexName=%s, groupName=%s.*", IDX_NAME, GRP_NAME)
+        String.format(".*?Tree is corrupted.*?cacheId=65, cacheName=A, indexName=%s, groupName=%s.*%s.*",
+            IDX_NAME, GRP_NAME, IGNITE_TO_STRING_INCLUDE_SENSITIVE)
     );
 
+    /** */
+    private final LogListener logSensListener = new MessageOrderLogListener(String.format(".*%s.*", VERY_SENS_STR_DATA));
+
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
@@ -76,6 +85,8 @@ public class H2TreeCorruptedTreeExceptionTest extends GridCommonAbstractTest {
 
         listeningTestLog.registerListener(logListener);
 
+        listeningTestLog.registerListener(logSensListener);
+
         cfg.setGridLogger(listeningTestLog);
 
         return cfg;
@@ -137,26 +148,57 @@ public class H2TreeCorruptedTreeExceptionTest extends GridCommonAbstractTest {
     /** */
     @Test
     public void testCorruptedTree() throws Exception {
-        IgniteEx srv = startGrid(0);
+        boolean curSensVal = S.INCLUDE_SENSITIVE;
 
-        srv.cluster().active(true);
+        try {
+            IgniteEx srv = startGrid(0);
 
-        IgniteCache<Integer, Integer> cache = srv.getOrCreateCache(DEFAULT_CACHE_NAME);
+            srv.cluster().active(true);
 
-        cache.query(new SqlFieldsQuery("create table a (id integer primary key, a integer) with \"CACHE_GROUP=" + GRP_NAME + "\""));
-        cache.query(new SqlFieldsQuery("create index " + IDX_NAME + " on a(a)"));
+            GridTestUtils.setFieldValue(S.class.getField("INCLUDE_SENSITIVE"), false);
 
-        failWithCorruptTree.set(true);
+            IgniteCache<Integer, Integer> cache = srv.getOrCreateCache(DEFAULT_CACHE_NAME);
 
-        try {
-            cache.query(new SqlFieldsQuery("insert into a(id, a) values (11, 1)"));
+            cache.query(new SqlFieldsQuery("create table a (col1 varchar primary key, col2 varchar) with " +
+                "\"CACHE_GROUP=" + GRP_NAME + "\""));
+            cache.query(new SqlFieldsQuery("create index " + IDX_NAME + " on a(col2)"));
+
+            failWithCorruptTree.set(true);
+
+            try {
+                cache.query(new SqlFieldsQuery("insert into a(col1, col2) values (1, ?1)")
+                    .setArgs(VERY_SENS_STR_DATA));
+
+                fail("Cache operations are expected to fail");
+            }
+            catch (Throwable e) {
+                assertTrue(X.hasCause(e, CorruptedTreeException.class));
+            }
+
+            assertTrue(logListener.check());
+
+            assertFalse(logSensListener.check());
+
+            GridTestUtils.setFieldValue(S.class.getField("INCLUDE_SENSITIVE"), true);
+
+            logListener.reset();
+
+            logSensListener.reset();
 
-            fail("Cache operations are expected to fail");
+            try {
+                cache.query(new SqlFieldsQuery("insert into a(col1, col2) values (2, ?1)")
+                    .setArgs(VERY_SENS_STR_DATA));
+            }
+            catch (Throwable e) {
+                assertTrue(X.hasCause(e, CorruptedTreeException.class));
+            }
+
+            assertFalse(logListener.check());
+
+            assertTrue(logSensListener.check());
         }
-        catch (Throwable e) {
-            assertTrue(X.hasCause(e, CorruptedTreeException.class));
+        finally {
+            GridTestUtils.setFieldValue(S.class.getField("INCLUDE_SENSITIVE"), curSensVal);
         }
-
-        assertTrue(logListener.check());
     }
 }