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

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


The following commit(s) were added to refs/heads/master by this push:
     new 8b220c9219c modify encrypt type and related tests (#14273)
8b220c9219c is described below

commit 8b220c9219c4a720026e24bcdeeefd1ae94ee7d4
Author: jintao zhu <[email protected]>
AuthorDate: Fri Dec 13 13:19:08 2024 +0800

    modify encrypt type and related tests (#14273)
    
    * modify encrypt type and related tests
    
    * spotless check
    
    * delete AES related tests
    
    * change set config way
    
    * change tsfile version
---
 .../db/it/query/IoTDBEncryptionValueQueryIT.java   |   2 +-
 .../db/it/query/IoTDBLoadEncryptedTsFileIT.java    |  55 +-------
 .../iotdb/db/it/query/IoTDBLoadPlainTsFileIT.java  | 145 ---------------------
 .../org/apache/iotdb/db/conf/IoTDBDescriptor.java  |  36 ++---
 .../conf/iotdb-system.properties.template          |  15 ---
 5 files changed, 23 insertions(+), 230 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBEncryptionValueQueryIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBEncryptionValueQueryIT.java
index b2f6a950170..3f9b234665d 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBEncryptionValueQueryIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBEncryptionValueQueryIT.java
@@ -128,7 +128,7 @@ public class IoTDBEncryptionValueQueryIT {
         .getConfig()
         .getCommonConfig()
         .setEncryptFlag(true)
-        .setEncryptType("org.apache.tsfile.encrypt.AES128");
+        .setEncryptType("UNENCRYPTED");
     EnvFactory.getEnv().initClusterEnvironment();
     importData();
   }
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadEncryptedTsFileIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadEncryptedTsFileIT.java
index bbb2f173c36..7ff81f934cb 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadEncryptedTsFileIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadEncryptedTsFileIT.java
@@ -52,7 +52,7 @@ public class IoTDBLoadEncryptedTsFileIT {
         .getConfig()
         .getCommonConfig()
         .setEncryptFlag(true)
-        .setEncryptType("org.apache.tsfile.encrypt.AES128");
+        .setEncryptType("UNENCRYPTED");
     EnvFactory.getEnv().initClusterEnvironment();
   }
 
@@ -98,25 +98,10 @@ public class IoTDBLoadEncryptedTsFileIT {
         cnt++;
       }
       Assert.assertEquals(3, cnt);
-    } catch (Exception e) {
-      Assert.fail(e.getMessage());
-    }
-  }
-
-  @Test
-  public void loadAnotherWayEncryptedTsFileTest() {
-    String unrecognizedType = "org.apache.tsfile.encrypt.SM4128";
-    try (Connection connection = EnvFactory.getEnv().getConnection();
-        Statement statement = connection.createStatement()) {
-      statement.execute("CREATE DATABASE root.tesgsg1");
-      statement.execute("CREATE TIMESERIES root.testsg1.d1.s1 WITH 
DATATYPE=INT32, ENCODING=PLAIN");
-      File tsfile = generateAnotherWayEncryptedFile(unrecognizedType);
-      statement.execute(String.format("load \"%s\"", 
tsfile.getParentFile().getAbsolutePath()));
-      ResultSet resultSet = statement.executeQuery("select s1 from 
root.testsg1.d1");
-      Assert.fail();
     } catch (Exception e) {
       Assert.assertTrue(
-          e.getMessage().contains("The encryption way of the TsFile is not 
supported."));
+          e.getMessage()
+              .contains("TSFile encryption is enabled, and the Load TSFile 
function is disabled"));
     }
   }
 
@@ -129,7 +114,7 @@ public class IoTDBLoadEncryptedTsFileIT {
     Files.createFile(tsfile.toPath());
     TSFileConfig config = TSFileDescriptor.getInstance().getConfig();
     config.setEncryptFlag("true");
-    config.setEncryptType("org.apache.tsfile.encrypt.AES128");
+    config.setEncryptType("UNENCRYPTED");
 
     try (TsFileIOWriter writer = new TsFileIOWriter(tsfile, config)) {
       
writer.startChunkGroup(IDeviceID.Factory.DEFAULT_FACTORY.create("root.testsg.d1"));
@@ -151,38 +136,6 @@ public class IoTDBLoadEncryptedTsFileIT {
     return tsfile;
   }
 
-  private File generateAnotherWayEncryptedFile(String unrecognizedType) throws 
IOException {
-    Path tempDir = Files.createTempDirectory("");
-    tempDir.toFile().deleteOnExit();
-    String tsfileName =
-        TsFileNameGenerator.generateNewTsFileName(System.currentTimeMillis(), 
1, 0, 0);
-    File tsfile = new File(tempDir + File.separator + tsfileName);
-    Files.createFile(tsfile.toPath());
-    TSFileConfig config = TSFileDescriptor.getInstance().getConfig();
-    config.setEncryptFlag("true");
-    config.setEncryptType("org.apache.tsfile.encrypt.AES128");
-
-    try (TsFileIOWriter writer = new TsFileIOWriter(tsfile, config)) {
-      
writer.startChunkGroup(IDeviceID.Factory.DEFAULT_FACTORY.create("root.testsg1.d1"));
-      ChunkWriterImpl chunkWriter =
-          new ChunkWriterImpl(
-              new MeasurementSchema("s1", TSDataType.INT32),
-              EncryptUtils.getEncryptParameter(config));
-      chunkWriter.write(2, 1);
-      chunkWriter.write(3, 1);
-      chunkWriter.write(4, 1);
-      chunkWriter.sealCurrentPage();
-
-      chunkWriter.writeToFileWriter(writer);
-      writer.endChunkGroup();
-      writer.setEncryptParam("2", unrecognizedType, 
EncryptUtils.getNormalKeyStr(config));
-      writer.endFile();
-    }
-    config.setEncryptFlag("false");
-    config.setEncryptType("org.apache.tsfile.encrypt.UNENCRYPTED");
-    return tsfile;
-  }
-
   private List<Integer> checkHeader(
       ResultSetMetaData resultSetMetaData, String expectedHeaderStrings, int[] 
expectedTypes)
       throws SQLException {
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadPlainTsFileIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadPlainTsFileIT.java
deleted file mode 100644
index bdff3fb463c..00000000000
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadPlainTsFileIT.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * 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.iotdb.db.it.query;
-
-import 
org.apache.iotdb.db.storageengine.dataregion.tsfile.generator.TsFileNameGenerator;
-import org.apache.iotdb.it.env.EnvFactory;
-
-import org.apache.tsfile.enums.TSDataType;
-import org.apache.tsfile.file.metadata.IDeviceID;
-import org.apache.tsfile.write.chunk.ChunkWriterImpl;
-import org.apache.tsfile.write.schema.MeasurementSchema;
-import org.apache.tsfile.write.writer.TsFileIOWriter;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.sql.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class IoTDBLoadPlainTsFileIT {
-  @BeforeClass
-  public static void setUp() throws Exception {
-    EnvFactory.getEnv()
-        .getConfig()
-        .getCommonConfig()
-        .setEncryptFlag(true)
-        .setEncryptType("org.apache.tsfile.encrypt.AES128");
-    EnvFactory.getEnv().initClusterEnvironment();
-  }
-
-  @AfterClass
-  public static void tearDown() throws Exception {
-    EnvFactory.getEnv().cleanClusterEnvironment();
-  }
-
-  @Test
-  public void loadNormalTsFileTest() {
-    String[] retArray =
-        new String[] {
-          "2,1,", "3,1,", "4,1,",
-        };
-    try (Connection connection = EnvFactory.getEnv().getConnection();
-        Statement statement = connection.createStatement()) {
-      statement.execute("CREATE DATABASE root.tesgsg");
-      statement.execute("CREATE TIMESERIES root.testsg.d1.s1 WITH 
DATATYPE=INT32, ENCODING=PLAIN");
-      File tsfile = generateNormalFile();
-      statement.execute(String.format("load \"%s\"", 
tsfile.getParentFile().getAbsolutePath()));
-      ResultSet resultSet = statement.executeQuery("select s1 from 
root.testsg.d1");
-      ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
-      List<Integer> actualIndexToExpectedIndexList =
-          checkHeader(
-              resultSetMetaData,
-              "Time,root.testsg.d1.s1,",
-              new int[] {
-                Types.TIMESTAMP, Types.INTEGER,
-              });
-
-      int cnt = 0;
-      while (resultSet.next()) {
-        String[] expectedStrings = retArray[cnt].split(",");
-        StringBuilder expectedBuilder = new StringBuilder();
-        StringBuilder actualBuilder = new StringBuilder();
-        for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
-          actualBuilder.append(resultSet.getString(i)).append(",");
-          expectedBuilder
-              .append(expectedStrings[actualIndexToExpectedIndexList.get(i - 
1)])
-              .append(",");
-        }
-        Assert.assertEquals(expectedBuilder.toString(), 
actualBuilder.toString());
-        cnt++;
-      }
-      Assert.assertEquals(3, cnt);
-    } catch (Exception e) {
-      Assert.assertTrue(
-          e.getMessage().contains("The encryption way of the TsFile is not 
supported."));
-    }
-  }
-
-  private File generateNormalFile() throws IOException {
-    Path tempDir = Files.createTempDirectory("");
-    tempDir.toFile().deleteOnExit();
-    String tsfileName =
-        TsFileNameGenerator.generateNewTsFileName(System.currentTimeMillis(), 
1, 0, 0);
-    File tsfile = new File(tempDir + File.separator + tsfileName);
-    Files.createFile(tsfile.toPath());
-
-    try (TsFileIOWriter writer = new TsFileIOWriter(tsfile)) {
-      
writer.startChunkGroup(IDeviceID.Factory.DEFAULT_FACTORY.create("root.testsg.d1"));
-      ChunkWriterImpl chunkWriter =
-          new ChunkWriterImpl(new MeasurementSchema("s1", TSDataType.INT32));
-      chunkWriter.write(2, 1);
-      chunkWriter.write(3, 1);
-      chunkWriter.write(4, 1);
-      chunkWriter.sealCurrentPage();
-
-      chunkWriter.writeToFileWriter(writer);
-      writer.endChunkGroup();
-      writer.endFile();
-    }
-    return tsfile;
-  }
-
-  private List<Integer> checkHeader(
-      ResultSetMetaData resultSetMetaData, String expectedHeaderStrings, int[] 
expectedTypes)
-      throws SQLException {
-    String[] expectedHeaders = expectedHeaderStrings.split(",");
-    Map<String, Integer> expectedHeaderToTypeIndexMap = new HashMap<>();
-    for (int i = 0; i < expectedHeaders.length; ++i) {
-      expectedHeaderToTypeIndexMap.put(expectedHeaders[i], i);
-    }
-
-    List<Integer> actualIndexToExpectedIndexList = new ArrayList<>();
-    for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
-      Integer typeIndex = 
expectedHeaderToTypeIndexMap.get(resultSetMetaData.getColumnName(i));
-      Assert.assertNotNull(typeIndex);
-      Assert.assertEquals(expectedTypes[typeIndex], 
resultSetMetaData.getColumnType(i));
-      actualIndexToExpectedIndexList.add(typeIndex);
-    }
-    return actualIndexToExpectedIndexList;
-  }
-}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
index 2264cb5ba3b..9590c5fd908 100755
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
@@ -1395,6 +1395,24 @@ public class IoTDBDescriptor {
                 .map(String::trim)
                 .orElse(conf.getKerberosPrincipal()));
     
TSFileDescriptor.getInstance().getConfig().setBatchSize(conf.getBatchSize());
+    TSFileDescriptor.getInstance()
+        .getConfig()
+        .setEncryptFlag(
+            Optional.ofNullable(properties.getProperty("encrypt_flag", 
"false"))
+                .map(String::trim)
+                .orElse("false"));
+    TSFileDescriptor.getInstance()
+        .getConfig()
+        .setEncryptType(
+            Optional.ofNullable(properties.getProperty("encrypt_type", 
"UNENCRYPTED"))
+                .map(String::trim)
+                .orElse("UNENCRYPTED"));
+    TSFileDescriptor.getInstance()
+        .getConfig()
+        .setEncryptKeyFromPath(
+            
Optional.ofNullable(properties.getProperty("encrypt_key_from_path", ""))
+                .map(String::trim)
+                .orElse(""));
 
     conf.setCoordinatorReadExecutorSize(
         Integer.parseInt(
@@ -2503,24 +2521,6 @@ public class IoTDBDescriptor {
                         
ConfigurationFileUtils.getConfigurationDefaultValue("compressor")))
                 .map(String::trim)
                 
.orElse(ConfigurationFileUtils.getConfigurationDefaultValue("compressor")));
-    TSFileDescriptor.getInstance()
-        .getConfig()
-        .setEncryptFlag(
-            properties.getProperty(
-                "encrypt_flag",
-                
ConfigurationFileUtils.getConfigurationDefaultValue("encrypt_flag")));
-    TSFileDescriptor.getInstance()
-        .getConfig()
-        .setEncryptType(
-            properties.getProperty(
-                "encrypt_type",
-                
ConfigurationFileUtils.getConfigurationDefaultValue("encrypt_type")));
-    TSFileDescriptor.getInstance()
-        .getConfig()
-        .setEncryptKeyFromPath(
-            properties.getProperty(
-                "encrypt_key_path",
-                
ConfigurationFileUtils.getConfigurationDefaultValue("encrypt_key_path")));
     TSFileDescriptor.getInstance()
         .getConfig()
         .setMaxTsBlockSizeInBytes(
diff --git 
a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
 
b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
index c26b6f5d6ae..f370aebbfa6 100644
--- 
a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
+++ 
b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
@@ -1583,21 +1583,6 @@ value_encoder=PLAIN
 # effectiveMode: hot_reload
 compressor=LZ4
 
-# Encryption configuration
-# Data encryption function switch.
-# effectiveMode: restart
-encrypt_flag=false
-
-# Encryption configuration
-# Data encryption method, supports org.apache.tsfile.encrypt.UNENCRYPTED, 
org.apache.tsfile.encrypt.AES128.
-# effectiveMode: restart
-encrypt_type=org.apache.tsfile.encrypt.UNENCRYPTED
-
-# Encryption configuration
-# Data encryption key source. The key should be 16 byte String.
-# effectiveMode: restart
-encrypt_key_path=
-
 ####################
 ### Authorization Configuration
 ####################

Reply via email to