-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0557b27
commit 7b50b46
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
src/test/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowSnykScanListenerLSlTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package io.snyk.plugin.ui.toolwindow | ||
|
||
import com.intellij.openapi.application.WriteAction | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.testFramework.fixtures.BasePlatformTestCase | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.unmockkAll | ||
import io.snyk.plugin.Severity | ||
import io.snyk.plugin.SnykFile | ||
import io.snyk.plugin.resetSettings | ||
import io.snyk.plugin.ui.toolwindow.nodes.root.RootOssTreeNode | ||
import io.snyk.plugin.ui.toolwindow.nodes.root.RootQualityIssuesTreeNode | ||
import io.snyk.plugin.ui.toolwindow.nodes.root.RootSecurityIssuesTreeNode | ||
import org.eclipse.lsp4j.Position | ||
import org.eclipse.lsp4j.Range | ||
import snyk.common.ProductType | ||
import snyk.common.lsp.CommitChangeLine | ||
import snyk.common.lsp.DataFlow | ||
import snyk.common.lsp.ExampleCommitFix | ||
import snyk.common.lsp.ScanIssue | ||
import javax.swing.JTree | ||
import javax.swing.tree.DefaultMutableTreeNode | ||
|
||
class SnykToolWindowSnykScanListenerLSlTest : BasePlatformTestCase() { | ||
private lateinit var cut: SnykToolWindowSnykScanListenerLS | ||
private lateinit var snykToolWindowPanel: SnykToolWindowPanel | ||
private lateinit var vulnerabilitiesTree: JTree | ||
private lateinit var rootOssIssuesTreeNode: DefaultMutableTreeNode | ||
private lateinit var rootSecurityIssuesTreeNode: DefaultMutableTreeNode | ||
private lateinit var rootQualityIssuesTreeNode: DefaultMutableTreeNode | ||
|
||
private lateinit var snykFile: SnykFile | ||
private lateinit var issue: ScanIssue | ||
|
||
private val fileName = "app.js" | ||
|
||
override fun setUp() { | ||
super.setUp() | ||
unmockkAll() | ||
resetSettings(project) | ||
|
||
snykToolWindowPanel = SnykToolWindowPanel(project) | ||
rootOssIssuesTreeNode = RootOssTreeNode(project) | ||
rootSecurityIssuesTreeNode = RootSecurityIssuesTreeNode(project) | ||
rootQualityIssuesTreeNode = RootQualityIssuesTreeNode(project) | ||
|
||
val file = myFixture.copyFileToProject(fileName) | ||
val psiFile = WriteAction.computeAndWait<PsiFile, Throwable> { psiManager.findFile(file)!! } | ||
snykFile = SnykFile(psiFile.project, psiFile.virtualFile) | ||
|
||
issue = mockk<ScanIssue>() | ||
every { issue.getSeverityAsEnum() } returns Severity.CRITICAL | ||
every { issue.title() } returns "title" | ||
every { issue.issueNaming() } returns "issueNaming" | ||
every { issue.cwes() } returns emptyList() | ||
every { issue.cves() } returns emptyList() | ||
every { issue.cvssV3() } returns null | ||
every { issue.cvssScore() } returns null | ||
every { issue.id() } returns "id" | ||
every { issue.additionalData.getProductType() } returns ProductType.CODE_SECURITY | ||
every { issue.additionalData.message } returns "Test message" | ||
every { issue.additionalData.repoDatasetSize } returns 1 | ||
every { issue.additionalData.exampleCommitFixes } returns | ||
listOf( | ||
ExampleCommitFix( | ||
"https://commit-url", | ||
listOf( | ||
CommitChangeLine("1", 1, "lineChange"), | ||
), | ||
), | ||
) | ||
every { | ||
issue.additionalData.dataFlow | ||
} returns listOf(DataFlow(0, getTestDataPath(), Range(Position(1, 1), Position(1, 1)), "")) | ||
} | ||
|
||
fun testDisplaySnykCodeResults() { | ||
cut = | ||
SnykToolWindowSnykScanListenerLS( | ||
project, | ||
snykToolWindowPanel, | ||
vulnerabilitiesTree, | ||
rootSecurityIssuesTreeNode, | ||
rootQualityIssuesTreeNode, | ||
rootOssIssuesTreeNode, | ||
) | ||
|
||
val snykResults: MutableMap<SnykFile, List<ScanIssue>> = mutableMapOf() | ||
snykResults[snykFile] = listOf(issue) | ||
cut.displaySnykCodeResults(snykResults) | ||
} | ||
} |