-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #590 from HXSecurity/develop
merge Develop
- Loading branch information
Showing
87 changed files
with
1,670 additions
and
74,193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
dongtai-agent/src/test/java/io/dongtai/iast/agent/fallback/checker/CpuUsageCheckerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.dongtai.iast.agent.fallback.checker; | ||
|
||
import io.dongtai.iast.agent.IastProperties; | ||
import io.dongtai.iast.agent.fallback.checker.impl.CpuUsageChecker; | ||
import io.dongtai.iast.common.entity.performance.PerformanceMetrics; | ||
import io.dongtai.iast.common.entity.performance.metrics.CpuInfoMetrics; | ||
import io.dongtai.iast.common.enums.MetricsKey; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.Properties; | ||
|
||
/** | ||
* 检查CPU使用率 | ||
*/ | ||
public class CpuUsageCheckerTest { | ||
|
||
@Test | ||
public void testIsPerformanceOverLimit() { | ||
|
||
|
||
// 创建配置参数对象 | ||
Properties cfg = new Properties(); | ||
cfg.setProperty("iast.remoteSync.performanceLimit.maxThreshold.cpuUsage", "{\"cpuUsagePercentage\":80.0}"); | ||
|
||
//初始化临时目录 | ||
IastProperties.initTmpDir(); | ||
|
||
// 创建测试用例对象 | ||
CpuUsageChecker cpuUsageChecker = new CpuUsageChecker(); | ||
// 创建模拟性能指标对象 | ||
PerformanceMetrics nowMetrics = new PerformanceMetrics(); | ||
CpuInfoMetrics cpuInfoMetrics = new CpuInfoMetrics(); | ||
cpuInfoMetrics.setCpuUsagePercentage(81.0); | ||
|
||
nowMetrics.setMetricsKey(MetricsKey.CPU_USAGE); | ||
nowMetrics.setMetricsValue(cpuInfoMetrics); | ||
|
||
// CPU使用率超过阈值,应该返回true | ||
Assert.assertTrue(cpuUsageChecker.isPerformanceOverLimit(nowMetrics, cfg)); | ||
|
||
// 修改性能指标对象的CPU使用率为70% | ||
cpuInfoMetrics.setCpuUsagePercentage(70.0); | ||
// CPU使用率未超过阈值,应该返回false | ||
Assert.assertFalse(cpuUsageChecker.isPerformanceOverLimit(nowMetrics, cfg)); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
dongtai-agent/src/test/java/io/dongtai/iast/agent/fallback/checker/MemUsageCheckerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.dongtai.iast.agent.fallback.checker; | ||
|
||
import io.dongtai.iast.agent.IastProperties; | ||
import io.dongtai.iast.agent.fallback.checker.impl.MemUsageChecker; | ||
import io.dongtai.iast.common.entity.performance.PerformanceMetrics; | ||
import io.dongtai.iast.common.entity.performance.metrics.MemoryUsageMetrics; | ||
import io.dongtai.iast.common.enums.MetricsKey; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.Properties; | ||
|
||
public class MemUsageCheckerTest { | ||
|
||
|
||
/** | ||
* 测试内存检查 | ||
*/ | ||
@Test | ||
public void testIsPerformanceOverLimit() { | ||
// 配置参数 | ||
Properties cfg = new Properties(); | ||
// 设置配置内存阈值 | ||
cfg.setProperty("iast.remoteSync.performanceLimit.maxThreshold.memoryUsage", "{\"committed\":1024," + | ||
"\"init\":1024,\"max\":1024,\"memUsagePercentage\":80.0,\"systemMaxLimit\":-1," + | ||
"\"trulyMaxMem\":1024,\"used\":1024}\n"); | ||
//初始化临时目录 | ||
IastProperties.initTmpDir(); | ||
// 创建检查器对象 | ||
MemUsageChecker memUsageChecker = new MemUsageChecker(); | ||
// 创建模拟性能指标对象 | ||
PerformanceMetrics nowMetrics = new PerformanceMetrics(); | ||
nowMetrics.setMetricsKey(MetricsKey.MEM_USAGE); | ||
nowMetrics.setMetricsValue(new MemoryUsageMetrics(1024L, 1024L, 1024L, 1024L)); | ||
// 内存使用率超过阈值,应该返回true | ||
Assert.assertTrue(memUsageChecker.isPerformanceOverLimit(nowMetrics, cfg)); | ||
|
||
|
||
// 修改性能指标对象的内存使用率为70% | ||
nowMetrics.setMetricsValue(new MemoryUsageMetrics(1024L, 500L, 1024L, 1024L)); | ||
// 内存使用率未超过阈值,应该返回false | ||
Assert.assertFalse(memUsageChecker.isPerformanceOverLimit(nowMetrics, cfg)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.