Kotlin tests

This commit is contained in:
rick.parker 2023-04-06 12:11:25 +01:00
parent 6b7da055f3
commit 0f4eae15c6
5 changed files with 59 additions and 5 deletions

View File

@ -1,5 +1,6 @@
plugins {
id 'java'
id 'kotlin'
id 'jacoco'
id 'eclipse'
id 'signing'
@ -32,6 +33,7 @@ dependencies {
}
testImplementation "com.google.guava:guava:$guava_version"
testImplementation "org.yaml:snakeyaml:1.33"
testImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
sourceCompatibility = 8

View File

@ -0,0 +1,41 @@
/* Copyright (c) 2022, Daniel Gredler. All rights reserved. */
package net.gredler.aegis4j;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Tests Kotlin blocking.
*/
public class CVE_2020_29582 {
@AfterAll
public static void uninstallAgent() throws Exception {
System.clearProperty("aegis4j.additional.args");
}
@Test
public void testDir() throws Exception {
TestUtils.installAgent("path=../resources/test/kotlin-mods.properties");
try {
new KotlinStdLibUtils().kotlinCreateTempDir();
fail("Exception expected");
} catch (RuntimeException e) {
assertEquals("Kotlin createTempDir blocked by aegis4j", e.getMessage());
}
}
@Test
public void testFile() throws Exception {
TestUtils.installAgent("path=../resources/test/kotlin-mods.properties");
try {
new KotlinStdLibUtils().kotlinCreateTempFile();
fail("Exception expected");
} catch (RuntimeException e) {
assertEquals("Kotlin createTempFile blocked by aegis4j", e.getMessage());
}
}
}

View File

@ -0,0 +1,12 @@
package net.gredler.aegis4j
class KotlinStdLibUtils {
fun kotlinCreateTempDir() {
createTempDir()
}
fun kotlinCreateTempFile() {
createTempFile()
}
}

View File

@ -0,0 +1,4 @@
# format: <feature>.<class-name>.<method-name>=<replacement-code>
# CVE-2020-29582
KOTLIN.kotlin.io.FilesKt__UtilsKt.createTempDir=throw new java.lang.RuntimeException("Kotlin createTempDir blocked by aegis4j");
KOTLIN.kotlin.io.FilesKt__UtilsKt.createTempFile=throw new java.lang.RuntimeException("Kotlin createTempFile blocked by aegis4j");

View File

@ -1,8 +1,3 @@
# format: <feature>.<class-name>.<method-name>=<replacement-code>
# CVE-2022-1471
SNAKEYAML.org.yaml.snakeyaml.constructor.Constructor.Constructor=throw new java.lang.RuntimeException("SnakeYAML Constructor blocked by aegis4j");
# CVE-2020-29582
#KOTLIN.kotlin.io.FilesKt__UtilsKt.createTempDir=throw new java.lang.RuntimeException("Kotlin createTempDir blocked by aegis4j");
#KOTLIN.kotlin.io.FilesKt__UtilsKt.createTempFile=throw new java.lang.RuntimeException("Kotlin createTempFile blocked by aegis4j");
# CVE-2020-8908
#GUAVA.com.google.common.io.Files.createTempDir=throw new java.lang.RuntimeException("Guava createTempDir blocked by aegis4j");