Skip to content

Commit

Permalink
Add one more test
Browse files Browse the repository at this point in the history
  • Loading branch information
CaelmBleidd committed Nov 2, 2023
1 parent d837cca commit 4480143
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,11 @@ data class TaintMethodSource(
val actionsAfter: List<Action>,
) : TaintConfigurationItem

data class TaintFieldSource(
val fieldInfo: JcField,
val condition: Condition,
val actionsAfter: List<Action>,
) : 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,4 +99,14 @@ class ConfigurationTest : BaseTest() {

assertTrue(rules.singleOrNull() != null)
}

@Test
fun testParametersMatches() {
val method = cp.findClass<java.lang.StringBuilder>().constructors.first {
it.parameters.singleOrNull()?.type?.typeName == "java.lang.String"
}
val rules = taintFeature.getConfigForMethod(method)

assertTrue(rules.singleOrNull() != null)
}
}
58 changes: 58 additions & 0 deletions jacodb-taint-configuration/src/test/resources/testJsonConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
}
]

0 comments on commit 4480143

Please sign in to comment.