Skip to content

Rename taint configuration classes #1955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.utbot.taint.parser.constants.*
import org.utbot.taint.parser.model.*
import org.utbot.taint.parser.yaml.ConfigurationParseError
import org.utbot.taint.parser.yaml.TaintParseError

class TaintAnalysisConfigurationParserTest {

Expand All @@ -27,7 +27,7 @@ class TaintAnalysisConfigurationParserTest {
@Test
fun `parse should throw exception on incorrect yaml`() {
val incorrectYamlInput = yamlInput.replace(k_not, "net")
assertThrows<ConfigurationParseError> {
assertThrows<TaintParseError> {
TaintAnalysisConfigurationParser.parse(incorrectYamlInput)
}
}
Expand Down Expand Up @@ -72,50 +72,50 @@ class TaintAnalysisConfigurationParserTest {
$k_marks: environment
""".trimIndent()

private val expectedConfiguration = Configuration(
private val expectedConfiguration = DtoTaintConfiguration(
sources = listOf(
Source(
methodFqn = MethodFqn(listOf("java", "lang"), "System", "getenv"),
addTo = TaintEntitiesSet(setOf(ReturnValue)),
marks = TaintMarksSet(setOf(TaintMark("environment"))),
signature = SignatureList(listOf(ArgumentTypeString("java.lang.String"))),
conditions = NoConditions
DtoTaintSource(
methodFqn = DtoMethodFqn(listOf("java", "lang"), "System", "getenv"),
addTo = DtoTaintEntitiesSet(setOf(DtoTaintEntityReturn)),
marks = DtoTaintMarksSet(setOf(DtoTaintMark("environment"))),
signature = DtoTaintSignatureList(listOf(DtoArgumentTypeString("java.lang.String"))),
conditions = DtoNoTaintConditions
)
),
passes = listOf(
Pass(
methodFqn = MethodFqn(listOf("java", "lang"), "String", "concat"),
getFrom = TaintEntitiesSet(setOf(ThisObject)),
addTo = TaintEntitiesSet(setOf(ReturnValue)),
marks = TaintMarksSet(setOf(TaintMark("sensitive-data"))),
signature = AnySignature,
conditions = ConditionsMap(mapOf(ThisObject to NotCondition(ValueCondition(ArgumentValueString("")))))
DtoTaintPass(
methodFqn = DtoMethodFqn(listOf("java", "lang"), "String", "concat"),
getFrom = DtoTaintEntitiesSet(setOf(DtoTaintEntityThis)),
addTo = DtoTaintEntitiesSet(setOf(DtoTaintEntityReturn)),
marks = DtoTaintMarksSet(setOf(DtoTaintMark("sensitive-data"))),
signature = DtoTaintSignatureAny,
conditions = DtoTaintConditionsMap(mapOf(DtoTaintEntityThis to DtoTaintConditionNot(DtoTaintConditionEqualValue(DtoArgumentValueString("")))))
),
Pass(
methodFqn = MethodFqn(listOf("java", "lang"), "String", "concat"),
getFrom = TaintEntitiesSet(setOf(MethodArgument(1u))),
addTo = TaintEntitiesSet(setOf(ReturnValue)),
marks = TaintMarksSet(setOf(TaintMark("sensitive-data"))),
signature = AnySignature,
conditions = ConditionsMap(mapOf(MethodArgument(1u) to NotCondition(ValueCondition(ArgumentValueString("")))))
DtoTaintPass(
methodFqn = DtoMethodFqn(listOf("java", "lang"), "String", "concat"),
getFrom = DtoTaintEntitiesSet(setOf(DtoTaintEntityArgument(1u))),
addTo = DtoTaintEntitiesSet(setOf(DtoTaintEntityReturn)),
marks = DtoTaintMarksSet(setOf(DtoTaintMark("sensitive-data"))),
signature = DtoTaintSignatureAny,
conditions = DtoTaintConditionsMap(mapOf(DtoTaintEntityArgument(1u) to DtoTaintConditionNot(DtoTaintConditionEqualValue(DtoArgumentValueString("")))))
)
),
cleaners = listOf(
Cleaner(
methodFqn = MethodFqn(listOf("java", "lang"), "String", "isEmpty"),
removeFrom = TaintEntitiesSet(setOf(ThisObject)),
marks = TaintMarksSet(setOf(TaintMark("sql-injection"), TaintMark("xss"))),
signature = AnySignature,
conditions = ConditionsMap(mapOf(ReturnValue to ValueCondition(ArgumentValueBoolean(true))))
DtoTaintCleaner(
methodFqn = DtoMethodFqn(listOf("java", "lang"), "String", "isEmpty"),
removeFrom = DtoTaintEntitiesSet(setOf(DtoTaintEntityThis)),
marks = DtoTaintMarksSet(setOf(DtoTaintMark("sql-injection"), DtoTaintMark("xss"))),
signature = DtoTaintSignatureAny,
conditions = DtoTaintConditionsMap(mapOf(DtoTaintEntityReturn to DtoTaintConditionEqualValue(DtoArgumentValueBoolean(true))))
)
),
sinks = listOf(
Sink(
methodFqn = MethodFqn(listOf("org", "example"), "util", "unsafe"),
check = TaintEntitiesSet(setOf(MethodArgument(2u))),
marks = TaintMarksSet(setOf(TaintMark("environment"))),
signature = SignatureList(argumentTypes = listOf(ArgumentTypeAny, ArgumentTypeString("java.lang.Integer"))),
conditions = ConditionsMap(mapOf(MethodArgument(2u) to ValueCondition(ArgumentValueLong(0L))))
DtoTaintSink(
methodFqn = DtoMethodFqn(listOf("org", "example"), "util", "unsafe"),
check = DtoTaintEntitiesSet(setOf(DtoTaintEntityArgument(2u))),
marks = DtoTaintMarksSet(setOf(DtoTaintMark("environment"))),
signature = DtoTaintSignatureList(argumentTypes = listOf(DtoArgumentTypeAny, DtoArgumentTypeString("java.lang.Integer"))),
conditions = DtoTaintConditionsMap(mapOf(DtoTaintEntityArgument(2u) to DtoTaintConditionEqualValue(DtoArgumentValueLong(0L))))
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class MethodArgumentParserTest {
@Test
fun `should parse underscore as ArgumentTypeAny`() {
val yamlScalar = Yaml.default.parseToYamlNode(k__)
val expectedArgumentType = ArgumentTypeAny
val expectedArgumentType = DtoArgumentTypeAny

val actualArgumentType = MethodArgumentParser.parseArgumentType(yamlScalar)
assertEquals(expectedArgumentType, actualArgumentType)
Expand All @@ -82,7 +82,7 @@ class MethodArgumentParserTest {
@Test
fun `should parse type fqn in brackets`() {
val yamlScalar = Yaml.default.parseToYamlNode("${k_lt}double${k_gt}")
val expectedArgumentType = ArgumentTypeString("double")
val expectedArgumentType = DtoArgumentTypeString("double")

val actualArgumentType = MethodArgumentParser.parseArgumentType(yamlScalar)
assertEquals(expectedArgumentType, actualArgumentType)
Expand All @@ -92,7 +92,7 @@ class MethodArgumentParserTest {
fun `should fail on another yaml type`() {
val yamlMap = Yaml.default.parseToYamlNode("type: ${k_lt}double${k_gt}")

assertThrows<ConfigurationParseError> {
assertThrows<TaintParseError> {
MethodArgumentParser.parseArgumentType(yamlMap)
}
}
Expand All @@ -104,7 +104,7 @@ class MethodArgumentParserTest {
@Test
fun `should parse yaml null as ArgumentValueNull`() {
val yamlNull = Yaml.default.parseToYamlNode("null")
val expectedArgumentValue = ArgumentValueNull
val expectedArgumentValue = DtoArgumentValueNull

val actualArgumentValue = MethodArgumentParser.parseArgumentValue(yamlNull)
assertEquals(expectedArgumentValue, actualArgumentValue)
Expand All @@ -113,7 +113,7 @@ class MethodArgumentParserTest {
@Test
fun `should parse boolean yaml scalar`() {
val yamlScalar = Yaml.default.parseToYamlNode("false")
val expectedArgumentValue = ArgumentValueBoolean(false)
val expectedArgumentValue = DtoArgumentValueBoolean(false)

val actualArgumentValue = MethodArgumentParser.parseArgumentValue(yamlScalar)
assertEquals(expectedArgumentValue, actualArgumentValue)
Expand All @@ -122,7 +122,7 @@ class MethodArgumentParserTest {
@Test
fun `should parse long yaml scalar`() {
val yamlScalar = Yaml.default.parseToYamlNode("17")
val expectedArgumentValue = ArgumentValueLong(17L)
val expectedArgumentValue = DtoArgumentValueLong(17L)

val actualArgumentValue = MethodArgumentParser.parseArgumentValue(yamlScalar)
assertEquals(expectedArgumentValue, actualArgumentValue)
Expand All @@ -131,7 +131,7 @@ class MethodArgumentParserTest {
@Test
fun `should parse double yaml scalar`() {
val yamlScalar = Yaml.default.parseToYamlNode("1.2")
val expectedArgumentValue = ArgumentValueDouble(1.2)
val expectedArgumentValue = DtoArgumentValueDouble(1.2)

val actualArgumentValue = MethodArgumentParser.parseArgumentValue(yamlScalar)
assertEquals(expectedArgumentValue, actualArgumentValue)
Expand All @@ -140,7 +140,7 @@ class MethodArgumentParserTest {
@Test
fun `should parse string yaml scalar`() {
val yamlScalar = Yaml.default.parseToYamlNode("some-string")
val expectedArgumentValue = ArgumentValueString("some-string")
val expectedArgumentValue = DtoArgumentValueString("some-string")

val actualArgumentValue = MethodArgumentParser.parseArgumentValue(yamlScalar)
assertEquals(expectedArgumentValue, actualArgumentValue)
Expand All @@ -150,7 +150,7 @@ class MethodArgumentParserTest {
fun `should fail on another yaml type`() {
val yamlList = Yaml.default.parseToYamlNode("[ some-string ]")

assertThrows<ConfigurationParseError> {
assertThrows<TaintParseError> {
MethodArgumentParser.parseArgumentValue(yamlList)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,97 +9,97 @@ import org.junit.jupiter.api.assertThrows
import org.utbot.taint.parser.constants.*
import org.utbot.taint.parser.model.*

class ConditionParserTest {
class TaintConditionParserTest {

@Nested
@DisplayName("parseCondition")
inner class ParseConditionTest {
@Test
fun `should parse yaml null as ValueCondition`() {
val yamlNull = Yaml.default.parseToYamlNode("null")
val expectedCondition = ValueCondition(ArgumentValueNull)
val expectedCondition = DtoTaintConditionEqualValue(DtoArgumentValueNull)

val actualCondition = ConditionParser.parseCondition(yamlNull)
val actualCondition = TaintConditionParser.parseCondition(yamlNull)
assertEquals(expectedCondition, actualCondition)
}

@Test
fun `should parse yaml scalar with argument value as ValueCondition`() {
val yamlScalar = Yaml.default.parseToYamlNode("some-string")
val expectedCondition = ValueCondition(ArgumentValueString("some-string"))
val expectedCondition = DtoTaintConditionEqualValue(DtoArgumentValueString("some-string"))

val actualCondition = ConditionParser.parseCondition(yamlScalar)
val actualCondition = TaintConditionParser.parseCondition(yamlScalar)
assertEquals(expectedCondition, actualCondition)
}

@Test
fun `should parse yaml scalar with argument type as TypeCondition`() {
val yamlScalar = Yaml.default.parseToYamlNode("${k_lt}java.lang.Integer${k_gt}")
val expectedCondition = TypeCondition(ArgumentTypeString("java.lang.Integer"))
val expectedCondition = DtoTaintConditionIsType(DtoArgumentTypeString("java.lang.Integer"))

val actualCondition = ConditionParser.parseCondition(yamlScalar)
val actualCondition = TaintConditionParser.parseCondition(yamlScalar)
assertEquals(expectedCondition, actualCondition)
}

@Test
fun `should parse yaml list as OrCondition`() {
val yamlList = Yaml.default.parseToYamlNode("[ 1, true, ${k_lt}java.lang.Integer${k_gt} ]")
val expectedCondition = OrCondition(listOf(
ValueCondition(ArgumentValueLong(1L)),
ValueCondition(ArgumentValueBoolean(true)),
TypeCondition(ArgumentTypeString("java.lang.Integer")),
val expectedCondition = DtoTaintConditionOr(listOf(
DtoTaintConditionEqualValue(DtoArgumentValueLong(1L)),
DtoTaintConditionEqualValue(DtoArgumentValueBoolean(true)),
DtoTaintConditionIsType(DtoArgumentTypeString("java.lang.Integer")),
))

val actualCondition = ConditionParser.parseCondition(yamlList)
val actualCondition = TaintConditionParser.parseCondition(yamlList)
assertEquals(expectedCondition, actualCondition)
}

@Test
fun `should parse yaml map with a key 'not' as NotCondition`() {
val yamlMap = Yaml.default.parseToYamlNode("$k_not: ${k_lt}int${k_gt}")
val expectedCondition = NotCondition(TypeCondition(ArgumentTypeString("int")))
val expectedCondition = DtoTaintConditionNot(DtoTaintConditionIsType(DtoArgumentTypeString("int")))

val actualCondition = ConditionParser.parseCondition(yamlMap)
val actualCondition = TaintConditionParser.parseCondition(yamlMap)
assertEquals(expectedCondition, actualCondition)
}

@Test
fun `should fail on yaml map without a key 'not'`() {
val yamlMap = Yaml.default.parseToYamlNode("net: ${k_lt}int${k_gt}")

assertThrows<ConfigurationParseError> {
ConditionParser.parseCondition(yamlMap)
assertThrows<TaintParseError> {
TaintConditionParser.parseCondition(yamlMap)
}
}

@Test
fun `should fail on yaml map with unknown keys`() {
val yamlMap = Yaml.default.parseToYamlNode("{ $k_not: ${k_lt}int${k_gt}, unknown-key: 0 }")

assertThrows<ConfigurationParseError> {
ConditionParser.parseCondition(yamlMap)
assertThrows<TaintParseError> {
TaintConditionParser.parseCondition(yamlMap)
}
}

@Test
fun `should parse complicated yaml node`() {
val yamlMap = Yaml.default.parseToYamlNode("$k_not: [ { $k_not: 0 }, ${k_lt}int${k_gt}, { $k_not: null } ]")
val expectedCondition = NotCondition(OrCondition(listOf(
NotCondition(ValueCondition(ArgumentValueLong(0L))),
TypeCondition(ArgumentTypeString("int")),
NotCondition(ValueCondition(ArgumentValueNull))
val expectedCondition = DtoTaintConditionNot(DtoTaintConditionOr(listOf(
DtoTaintConditionNot(DtoTaintConditionEqualValue(DtoArgumentValueLong(0L))),
DtoTaintConditionIsType(DtoArgumentTypeString("int")),
DtoTaintConditionNot(DtoTaintConditionEqualValue(DtoArgumentValueNull))
)))

val actualCondition = ConditionParser.parseCondition(yamlMap)
val actualCondition = TaintConditionParser.parseCondition(yamlMap)
assertEquals(expectedCondition, actualCondition)
}

@Test
fun `should fail on another yaml type`() {
val yamlTaggedNode = YamlTaggedNode("some-tag", YamlNull(YamlPath.root))

assertThrows<ConfigurationParseError> {
ConditionParser.parseCondition(yamlTaggedNode)
assertThrows<TaintParseError> {
TaintConditionParser.parseCondition(yamlTaggedNode)
}
}
}
Expand All @@ -110,31 +110,31 @@ class ConditionParserTest {
@Test
fun `should parse correct yaml map as Conditions`() {
val yamlMap = Yaml.default.parseToYamlNode("{ $k_this: \"\", ${k_arg}2: { $k_not: ${k_lt}int${k_gt} }, $k_return: [ 0, 1 ] }")
val expectedConditions = ConditionsMap(mapOf(
ThisObject to ValueCondition(ArgumentValueString("")),
MethodArgument(2u) to NotCondition(TypeCondition(ArgumentTypeString("int"))),
ReturnValue to OrCondition(listOf(ValueCondition(ArgumentValueLong(0L)), ValueCondition(ArgumentValueLong(1L))))
val expectedConditions = DtoTaintConditionsMap(mapOf(
DtoTaintEntityThis to DtoTaintConditionEqualValue(DtoArgumentValueString("")),
DtoTaintEntityArgument(2u) to DtoTaintConditionNot(DtoTaintConditionIsType(DtoArgumentTypeString("int"))),
DtoTaintEntityReturn to DtoTaintConditionOr(listOf(DtoTaintConditionEqualValue(DtoArgumentValueLong(0L)), DtoTaintConditionEqualValue(DtoArgumentValueLong(1L))))
))

val actualConditions = ConditionParser.parseConditions(yamlMap)
val actualConditions = TaintConditionParser.parseConditions(yamlMap)
assertEquals(expectedConditions, actualConditions)
}

@Test
fun `should parse empty yaml map as NoConditions`() {
val yamlMap = Yaml.default.parseToYamlNode("{}")
val expectedConditions = NoConditions
val expectedConditions = DtoNoTaintConditions

val actualConditions = ConditionParser.parseConditions(yamlMap)
val actualConditions = TaintConditionParser.parseConditions(yamlMap)
assertEquals(expectedConditions, actualConditions)
}

@Test
fun `should fail on another yaml type`() {
val yamlList = Yaml.default.parseToYamlNode("[]")

assertThrows<ConfigurationParseError> {
ConditionParser.parseConditions(yamlList)
assertThrows<TaintParseError> {
TaintConditionParser.parseConditions(yamlList)
}
}
}
Expand All @@ -145,18 +145,18 @@ class ConditionParserTest {
@Test
fun `should parse yaml map with a key 'conditions'`() {
val yamlMap = Yaml.default.parseToYamlNode("$k_conditions: { $k_return: null }").yamlMap
val expectedConditions = ConditionsMap(mapOf(ReturnValue to ValueCondition(ArgumentValueNull)))
val expectedConditions = DtoTaintConditionsMap(mapOf(DtoTaintEntityReturn to DtoTaintConditionEqualValue(DtoArgumentValueNull)))

val actualConditions = ConditionParser.parseConditionsKey(yamlMap)
val actualConditions = TaintConditionParser.parseConditionsKey(yamlMap)
assertEquals(expectedConditions, actualConditions)
}

@Test
fun `should parse yaml map without a key 'conditions' as NoConditions`() {
val yamlMap = Yaml.default.parseToYamlNode("$k_marks: []").yamlMap
val expectedConditions = NoConditions
val expectedConditions = DtoNoTaintConditions

val actualConditions = ConditionParser.parseConditionsKey(yamlMap)
val actualConditions = TaintConditionParser.parseConditionsKey(yamlMap)
assertEquals(expectedConditions, actualConditions)
}
}
Expand Down
Loading