Vladsz83 commented on a change in pull request #9269:
URL: https://github.com/apache/ignite/pull/9269#discussion_r687916208



##########
File path: 
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/EncryptedSnapshotTest.java
##########
@@ -0,0 +1,255 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.snapshot;
+
+import java.util.Collections;
+import java.util.function.Function;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.encryption.AbstractEncryptionTest;
+import org.apache.ignite.internal.util.distributed.FullMessage;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+import org.junit.runners.Parameterized;
+
+/**
+ * Snapshot test for encrypted snapshots.
+ */
+public class EncryptedSnapshotTest extends AbstractSnapshotSelfTest {
+    /** Parameters. */
+    @Parameterized.Parameters(name = "Encryption is enabled.")
+    public static Iterable<Boolean> enableEncryption() {
+        return Collections.singletonList(true);
+    }
+
+    /** Name of additional encrypted cache. */
+    private static final String NOT_ENCRYPTED_CACHE_NAME = "notEncryptedCache";
+
+    /** {@inheritDoc} */
+    @Override protected Function<Integer, Object> valueBuilder() {
+        return (i -> new Account(i, i));
+    }
+
+    /** Checks re-encryption fails during snapshot restoration. */
+    @Test
+    public void testReencryptDuringRestore() throws Exception {
+        checkActionFailsDuringSnapshotOperation(true, 
this::chageCacheGroupKey, "Cache group key change was " +
+            "rejected.", IgniteException.class);
+    }
+
+    /** Checks master key changing failes during snapshot restoration. */
+    @Test
+    public void testMasterKeyChangeDuringRestore() throws Exception {
+        checkActionFailsDuringSnapshotOperation(true, this::chageMasterKey, 
"Master key change was rejected.",
+            IgniteException.class);
+    }
+
+    /** Checks re-encryption fails during snapshot creation. */
+    @Test
+    public void testReencryptDuringSnapshot() throws Exception {
+        checkActionFailsDuringSnapshotOperation(false, 
this::chageCacheGroupKey, "Cache group key change was " +
+            "rejected.", IgniteException.class);
+    }
+
+    /** Checks master key changing fails during snapshot creation. */
+    @Test
+    public void testMasterKeyChangeDuringSnapshot() throws Exception {
+        checkActionFailsDuringSnapshotOperation(false, this::chageMasterKey, 
"Master key change was rejected.",
+            IgniteException.class);
+    }
+
+    /** Checks snapshot action fail during cache group key change. */
+    @Test
+    public void testSnapshotFailsDuringCacheKeyChange() throws Exception {
+        checkSnapshotActionFailsDuringReencryption(this::chageCacheGroupKey);
+    }
+
+    /** Checks snapshot action fail during master key cnahge. */
+    @Test
+    public void testSnapshotFailsDuringMasterKeyChange() throws Exception {
+        checkSnapshotActionFailsDuringReencryption(this::chageMasterKey);
+    }
+
+    /** Checks snapshot restoration fails if different master key is contained 
in the snapshot. */
+    @Test
+    public void testStartFromSnapshotFailedWithOtherMasterKey() throws 
Exception {
+        IgniteEx ig = startGridsWithCache(1, CACHE_KEYS_RANGE, valueBuilder(), 
dfltCacheCfg);
+
+        ig.snapshot().createSnapshot(SNAPSHOT_NAME).get();
+
+        ig.destroyCache(dfltCacheCfg.getName());
+
+        ensureCacheAbsent(dfltCacheCfg);
+
+        stopAllGrids(false);
+
+        masterKeyName = AbstractEncryptionTest.MASTER_KEY_NAME_2;
+
+        GridTestUtils.assertThrowsAnyCause(
+            log,
+            () -> startGridsFromSnapshot(1, SNAPSHOT_NAME),
+            IgniteCheckedException.class,
+            "bad key is used during decryption"
+        );
+    }
+
+    /** Checks it is unavailable to register snapshot task for encrypted 
caches witout metastore. */
+    @Test
+    public void testSnapshotTaskIsBlockedWithoutMetastore() throws Exception {
+        // Start grid node with data before each test.
+        IgniteEx ig = startGridsWithCache(1, CACHE_KEYS_RANGE, valueBuilder(), 
dfltCacheCfg);
+
+        GridTestUtils.assertThrowsAnyCause(log,
+            () -> snp(ig).registerSnapshotTask(SNAPSHOT_NAME, 
ig.localNode().id(), F.asMap(CU.cacheId(dfltCacheCfg.getName()), null),
+                false, 
snp(ig).localSnapshotSenderFactory().apply(SNAPSHOT_NAME)).get(TIMEOUT),
+            IgniteCheckedException.class,
+            "Metastore is requird because it contains encryption keys");

Review comment:
       Fixed




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to