Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CaelmBleidd committed Nov 2, 2023
1 parent d837cca commit 9ae7569
Show file tree
Hide file tree
Showing 3 changed files with 153 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,24 @@ 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)
}

@Test
fun testPrimitiveParametersInMatcher() {
val method = cp.findClass<java.io.Writer>().methods.first {
it.name.startsWith("write") && it.parameters.firstOrNull()?.type?.typeName == "int"
}
val rules = taintFeature.getConfigForMethod(method)

assertTrue(rules.singleOrNull() != null)
}
}
132 changes: 132 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,137 @@
}
}
]
},
{
"_": "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"
}
}
]
},
{
"_": "MethodSink",
"ruleNote": "System Information Leak",
"cwe": [
497
],
"methodInfo": {
"cls": {
"packageMatcher": {
"_": "NameIsEqualTo",
"name": "java.io"
},
"classNameMatcher": {
"_": "NameMatches",
"pattern": "Writer|OutputStream"
}
},
"functionName": {
"_": "NameMatches",
"pattern": "write.*"
},
"parametersMatchers": [
{
"index": 0,
"typeMatcher": {
"_": "PrimitiveNameMatches",
"name": "int"
}
}
],
"returnTypeMatcher": {
"_": "AnyTypeMatches"
},
"applyToOverrides": true,
"functionLabel": null,
"modifier": -1,
"exclude": [
]
},
"condition": {
"_": "And",
"args": [
{
"_": "IsType",
"position": {
"_": "Argument",
"number": 0
},
"type": {
"_": "PrimitiveNameMatches",
"name": "int"
}
},
{
"_": "IsConstant",
"position": {
"_": "Argument",
"number": 0
}
},
{
"_": "ConstantEq",
"position": {
"_": "Argument",
"number": 0
},
"constant": {
"_": "IntValue",
"value": 0
}
}
]
}
}
]

0 comments on commit 9ae7569

Please sign in to comment.