Skip to content

Commit 21e502b

Browse files
authored
Add sandbox failures to SARIF report (#1364)
1 parent 304b48b commit 21e502b

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

utbot-framework-test/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ package org.utbot.sarif
22

33
import org.junit.Test
44
import org.mockito.Mockito
5-
import org.utbot.framework.plugin.api.ExecutableId
6-
import org.utbot.framework.plugin.api.UtExecution
7-
import org.utbot.framework.plugin.api.UtImplicitlyThrownException
8-
import org.utbot.framework.plugin.api.UtPrimitiveModel
9-
import org.utbot.framework.plugin.api.UtMethodTestSet
10-
import org.utbot.framework.plugin.api.UtSymbolicExecution
5+
import org.utbot.framework.plugin.api.*
116

127
class SarifReportTest {
138

@@ -137,6 +132,19 @@ class SarifReportTest {
137132
}
138133
}
139134

135+
@Test
136+
fun testProcessSandboxFailure() {
137+
mockUtMethodNames()
138+
139+
val uncheckedException = Mockito.mock(java.security.AccessControlException::class.java)
140+
Mockito.`when`(uncheckedException.stackTrace).thenReturn(arrayOf())
141+
Mockito.`when`(mockUtExecution.result).thenReturn(UtSandboxFailure(uncheckedException))
142+
143+
val report = sarifReportMain.createReport()
144+
val result = report.runs.first().results.first()
145+
assert(result.message.text.contains("AccessControlException"))
146+
}
147+
140148
@Test
141149
fun testCodeFlowsStartsWithMethodCall() {
142150
mockUtMethodNames()

utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class SarifReport(
207207

208208
// prepending stack trace by `method` call in generated tests
209209
val methodCallLocation: SarifPhysicalLocation? =
210-
findMethodCallInTestBody(utExecution.testMethodName, method.name)
210+
findMethodCallInTestBody(utExecution.testMethodName, method.name, utExecution)
211211
if (methodCallLocation != null) {
212212
val testFileName = sourceFinding.testsRelativePath.toPath().fileName
213213
val testClassName = testFileName.nameWithoutExtension
@@ -255,9 +255,15 @@ class SarifReport(
255255
generatedTestsCode.split('\n')
256256
}
257257

258-
private fun findMethodCallInTestBody(testMethodName: String?, methodName: String): SarifPhysicalLocation? {
258+
private fun findMethodCallInTestBody(
259+
testMethodName: String?,
260+
methodName: String,
261+
utExecution: UtExecution,
262+
): SarifPhysicalLocation? {
259263
if (testMethodName == null)
260264
return null
265+
if (utExecution.result is UtSandboxFailure) // if there is no method call in test
266+
return getRelatedLocations(utExecution).firstOrNull()?.physicalLocation
261267

262268
// searching needed test
263269
val testMethodStartsAt = testsBodyLines.indexOfFirst { line ->
@@ -342,6 +348,7 @@ class SarifReport(
342348
val implicitlyThrown = result is UtImplicitlyThrownException
343349
val overflowFailure = result is UtOverflowFailure && UtSettings.treatOverflowAsError
344350
val assertionError = result is UtExplicitlyThrownException && result.exception is AssertionError
345-
return implicitlyThrown || overflowFailure || assertionError
351+
val sandboxFailure = result is UtSandboxFailure
352+
return implicitlyThrown || overflowFailure || assertionError || sandboxFailure
346353
}
347354
}

0 commit comments

Comments
 (0)