From 4480143d4a4d0dcb29ae71a3bbdf77491c03aadc Mon Sep 17 00:00:00 2001 From: Alexey Menshutin Date: Thu, 2 Nov 2023 14:13:37 +0300 Subject: [PATCH] Add one more test --- .../configuration/TaintConfigurationItem.kt | 11 ---- .../jacodb/configuration/ConfigurationTest.kt | 11 ++++ .../src/test/resources/testJsonConfig.json | 58 +++++++++++++++++++ 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/jacodb-taint-configuration/src/main/kotlin/org/jacodb/configuration/TaintConfigurationItem.kt b/jacodb-taint-configuration/src/main/kotlin/org/jacodb/configuration/TaintConfigurationItem.kt index 474594a16..fedfe2fd4 100644 --- a/jacodb-taint-configuration/src/main/kotlin/org/jacodb/configuration/TaintConfigurationItem.kt +++ b/jacodb-taint-configuration/src/main/kotlin/org/jacodb/configuration/TaintConfigurationItem.kt @@ -33,22 +33,11 @@ data class TaintMethodSource( val actionsAfter: List, ) : TaintConfigurationItem -data class TaintFieldSource( - val fieldInfo: JcField, - val condition: Condition, - val actionsAfter: List, -) : TaintConfigurationItem - data class TaintMethodSink( val condition: Condition, val methodInfo: JcMethod, ) : TaintConfigurationItem -data class TaintFieldSink( - val condition: Condition, - val fieldInfo: JcField, -) : TaintConfigurationItem - data class TaintPassThrough( val methodInfo: JcMethod, val condition: Condition, diff --git a/jacodb-taint-configuration/src/test/kotlin/org/jacodb/configuration/ConfigurationTest.kt b/jacodb-taint-configuration/src/test/kotlin/org/jacodb/configuration/ConfigurationTest.kt index 9d4590a94..354e83bc9 100644 --- a/jacodb-taint-configuration/src/test/kotlin/org/jacodb/configuration/ConfigurationTest.kt +++ b/jacodb-taint-configuration/src/test/kotlin/org/jacodb/configuration/ConfigurationTest.kt @@ -18,6 +18,7 @@ package org.jacodb.configuration import kotlinx.coroutines.runBlocking import org.jacodb.api.JcClasspath +import org.jacodb.api.ext.constructors import org.jacodb.api.ext.findClass import org.jacodb.api.ext.methods import org.jacodb.api.ext.objectType @@ -98,4 +99,14 @@ class ConfigurationTest : BaseTest() { assertTrue(rules.singleOrNull() != null) } + + @Test + fun testParametersMatches() { + val method = cp.findClass().constructors.first { + it.parameters.singleOrNull()?.type?.typeName == "java.lang.String" + } + val rules = taintFeature.getConfigForMethod(method) + + assertTrue(rules.singleOrNull() != null) + } } diff --git a/jacodb-taint-configuration/src/test/resources/testJsonConfig.json b/jacodb-taint-configuration/src/test/resources/testJsonConfig.json index 55a995049..451c41a7a 100644 --- a/jacodb-taint-configuration/src/test/resources/testJsonConfig.json +++ b/jacodb-taint-configuration/src/test/resources/testJsonConfig.json @@ -347,5 +347,63 @@ } } ] + }, + { + "_": "PassThrough", + "methodInfo": { + "cls": { + "packageMatcher": { + "_": "NameIsEqualTo", + "name": "java.lang" + }, + "classNameMatcher": { + "_": "NameIsEqualTo", + "name": "StringBuilder" + } + }, + "functionName": { + "_": "NameIsEqualTo", + "name": "init^" + }, + "parametersMatchers": [ + { + "index": 0, + "typeMatcher": { + "_": "ClassMatcher", + "packageMatcher": { + "_": "NameIsEqualTo", + "name": "java.lang" + }, + "classNameMatcher": { + "_": "NameIsEqualTo", + "name": "String" + } + } + } + ], + "returnTypeMatcher": { + "_": "AnyTypeMatches" + }, + "applyToOverrides": true, + "functionLabel": null, + "modifier": -1, + "exclude": [ + ] + }, + "condition": { + "_": "ConstantTrue" + }, + "actionsAfter": [ + { + "_": "CopyAllMarks", + "from": { + "_": "Argument", + "number": 0 + }, + "to": { + "_": "This" + } + } + ] } ] \ No newline at end of file