From 4c1cb77daa2a5be9d95a07d5af4151a0cc06d25f Mon Sep 17 00:00:00 2001 From: mazepeng <2695212419@qq.com> Date: Tue, 12 Sep 2023 10:59:22 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=20=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E5=AF=B9=E4=BA=8E=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=BA=A7=E5=88=AB=E7=9A=84=E4=BF=AE=E6=94=B9=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io.dongtai.log/IastPropertiesTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dongtai-log/src/test/java/io.dongtai.log/IastPropertiesTest.java b/dongtai-log/src/test/java/io.dongtai.log/IastPropertiesTest.java index 4cc8192e8..e444ae957 100644 --- a/dongtai-log/src/test/java/io.dongtai.log/IastPropertiesTest.java +++ b/dongtai-log/src/test/java/io.dongtai.log/IastPropertiesTest.java @@ -7,6 +7,7 @@ public class IastPropertiesTest { private final String oldTmpPath = System.getProperty("java.io.tmpdir.dongtai"); private final String oldLogPath = System.getProperty("dongtai.log.path"); + private final String LogLevel = System.getProperty("dongtai.log.level"); @Before public void setUp() { @@ -22,11 +23,15 @@ public void tearDown() { if (oldLogPath != null) { System.setProperty("dongtai.log.path", oldLogPath); } + if (LogLevel != null) { + System.setProperty("dongtai.log.level", LogLevel); + } } private void clear() { System.clearProperty("java.io.tmpdir.dongtai"); System.clearProperty("dongtai.log.path"); + System.clearProperty("dongtai.log.level"); } @Test @@ -49,4 +54,18 @@ public void getLogPathTest() { path = IastProperties.getLogDir(); Assert.assertEquals(File.separator + "foo", path); } + + @Test + public void getLogLevelTest() { + //默认使用info级别 + String logLevel = IastProperties.getLogLevel(); + Assert.assertEquals("log level:" + logLevel, "info", logLevel); + clear(); + //修改为debug级别 + System.setProperty("dongtai.log.level", "debug"); + logLevel = IastProperties.getLogLevel(); + Assert.assertEquals("log level:" + logLevel, "debug", logLevel); + + + } } From 329881654a28af50a9e0529e44ab2486c4e982d1 Mon Sep 17 00:00:00 2001 From: mazepeng <2695212419@qq.com> Date: Tue, 12 Sep 2023 16:11:31 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=20=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E5=AF=B9=E4=BA=8E=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=BA=A7=E5=88=AB=E7=9A=84=E4=BF=AE=E6=94=B9=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io.dongtai.log/IastPropertiesTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/dongtai-log/src/test/java/io.dongtai.log/IastPropertiesTest.java b/dongtai-log/src/test/java/io.dongtai.log/IastPropertiesTest.java index e444ae957..cc93b792b 100644 --- a/dongtai-log/src/test/java/io.dongtai.log/IastPropertiesTest.java +++ b/dongtai-log/src/test/java/io.dongtai.log/IastPropertiesTest.java @@ -9,6 +9,10 @@ public class IastPropertiesTest { private final String oldLogPath = System.getProperty("dongtai.log.path"); private final String LogLevel = System.getProperty("dongtai.log.level"); + private final String switchSign = System.getProperty("dongtai.log"); + + + @Before public void setUp() { clear(); @@ -26,12 +30,32 @@ public void tearDown() { if (LogLevel != null) { System.setProperty("dongtai.log.level", LogLevel); } + if (switchSign != null) { + System.setProperty("dongtai.log", switchSign); + } } private void clear() { System.clearProperty("java.io.tmpdir.dongtai"); System.clearProperty("dongtai.log.path"); System.clearProperty("dongtai.log.level"); + System.clearProperty("dongtai.log"); + } + + + @Test + public void isEnabledTest(){ + boolean enabled = IastProperties.isEnabled(); + //默认开启 + Assert.assertTrue("isEnabled:" + enabled, enabled); + + + //修改为关闭 + System.setProperty("dongtai.log", "false"); + enabled = IastProperties.isEnabled(); + Assert.assertFalse("isEnabled:" + enabled,enabled); + + } @Test From cb6c8221ebea1dc7ea49721e3d543228785737be Mon Sep 17 00:00:00 2001 From: mazepeng <2695212419@qq.com> Date: Tue, 12 Sep 2023 18:43:54 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=20=E6=B7=BB=E5=8A=A0=E4=BA=86agent?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=B7=A5=E5=85=B7=E7=9A=84=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iast/agent/util/ByteUtilsTest.java | 38 +++++++++++++++++++ .../iast/agent/util/FileUtilsTest.java | 35 +++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 dongtai-agent/src/test/java/io/dongtai/iast/agent/util/ByteUtilsTest.java create mode 100644 dongtai-agent/src/test/java/io/dongtai/iast/agent/util/FileUtilsTest.java diff --git a/dongtai-agent/src/test/java/io/dongtai/iast/agent/util/ByteUtilsTest.java b/dongtai-agent/src/test/java/io/dongtai/iast/agent/util/ByteUtilsTest.java new file mode 100644 index 000000000..31e15ae59 --- /dev/null +++ b/dongtai-agent/src/test/java/io/dongtai/iast/agent/util/ByteUtilsTest.java @@ -0,0 +1,38 @@ +package io.dongtai.iast.agent.util; + +import org.junit.Assert; +import org.junit.Test; + +public class ByteUtilsTest { + @Test + public void testFormatByteSize() { + // 测试formatByteSize方法是否返回正确的格式化字符串 + + // 测试不足1KB的情况 + Assert.assertEquals("0B", ByteUtils.formatByteSize(0)); + Assert.assertEquals("1023B", ByteUtils.formatByteSize(1023)); + + // 测试不足1MB的情况 + Assert.assertEquals("1KB", ByteUtils.formatByteSize(1024)); + Assert. assertEquals("1.5KB", ByteUtils.formatByteSize(1536)); + Assert.assertEquals("1023.5KB", ByteUtils.formatByteSize(1023 * 1024 + 512)); + + // 测试不足1GB的情况 + Assert.assertEquals("1MB", ByteUtils.formatByteSize(1024 * 1024)); + Assert.assertEquals("1.5MB", ByteUtils.formatByteSize(1536 * 1024)); + Assert.assertEquals("1023.5MB", ByteUtils.formatByteSize(1023 * 1024 * 1024 + 512 * 1024)); + + // 测试不足1TB的情况 + Assert.assertEquals("1GB", ByteUtils.formatByteSize(1024 * 1024 * 1024)); + Assert.assertEquals("1.5GB", ByteUtils.formatByteSize(1536 * 1024 * 1024)); + Assert.assertEquals("1023.5GB", ByteUtils.formatByteSize(1023L * 1024 * 1024 * 1024 + 512 * 1024 * 1024)); + + // 测试不足1PB的情况 + Assert.assertEquals("1TB", ByteUtils.formatByteSize(1024L * 1024 * 1024 * 1024)); + Assert.assertEquals("1.5TB", ByteUtils.formatByteSize(1536L * 1024 * 1024 * 1024)); + Assert.assertEquals("1023.5TB", ByteUtils.formatByteSize(1023L * 1024 * 1024 * 1024 * 1024 + 512L * 1024 * 1024 * 1024)); + + // 测试超过1PB的情况 + Assert.assertEquals(">PB", ByteUtils.formatByteSize(Long.MAX_VALUE)); + } +} diff --git a/dongtai-agent/src/test/java/io/dongtai/iast/agent/util/FileUtilsTest.java b/dongtai-agent/src/test/java/io/dongtai/iast/agent/util/FileUtilsTest.java new file mode 100644 index 000000000..e8c27dc62 --- /dev/null +++ b/dongtai-agent/src/test/java/io/dongtai/iast/agent/util/FileUtilsTest.java @@ -0,0 +1,35 @@ +package io.dongtai.iast.agent.util; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; + +public class FileUtilsTest { + @Test + public void testGetResourceToFile() { + // 测试getResourceToFile方法是否能正确地将资源文件复制到指定的文件路径 + + //获取临时文件路径 + String tempDirectoryPath = org.apache.commons.io.FileUtils.getTempDirectoryPath(); + + String resourceName = "iast.properties.example"; // 假设存在名为test_resource.txt的资源文件 + String fileName = tempDirectoryPath + "test.example"; // 替换为实际的目标文件路径 + + boolean result = false; + try { + result = FileUtils.getResourceToFile(resourceName, fileName); + } catch (IOException e) { + throw new RuntimeException(e); + } + + Assert.assertTrue(result); // 验证复制操作是否成功 + + // 验证目标文件是否存在 + java.io.File targetFile = new java.io.File(fileName); + Assert.assertTrue(targetFile.exists()); + + // 清理测试产生的文件 + targetFile.delete(); + } +} From 39ae022c39c4b4bdebd29e770cceb5bfcbe7b7c6 Mon Sep 17 00:00:00 2001 From: mazepeng <2695212419@qq.com> Date: Tue, 12 Sep 2023 18:44:43 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=20=E6=B7=BB=E5=8A=A0=E4=BA=86agent?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=B7=A5=E5=85=B7=E7=9A=84=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/io/dongtai/iast/agent/util/FileUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dongtai-agent/src/test/java/io/dongtai/iast/agent/util/FileUtilsTest.java b/dongtai-agent/src/test/java/io/dongtai/iast/agent/util/FileUtilsTest.java index e8c27dc62..caa5a538b 100644 --- a/dongtai-agent/src/test/java/io/dongtai/iast/agent/util/FileUtilsTest.java +++ b/dongtai-agent/src/test/java/io/dongtai/iast/agent/util/FileUtilsTest.java @@ -16,7 +16,7 @@ public void testGetResourceToFile() { String resourceName = "iast.properties.example"; // 假设存在名为test_resource.txt的资源文件 String fileName = tempDirectoryPath + "test.example"; // 替换为实际的目标文件路径 - boolean result = false; + boolean result; try { result = FileUtils.getResourceToFile(resourceName, fileName); } catch (IOException e) {