Skip to content

Commit e28040e

Browse files
fix: get security and quality nodes if enabled (#241)
Co-authored-by: Bastian Doetsch <bastian.doetsch@snyk.io>
1 parent faf37b6 commit e28040e

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

plugin/src/main/java/io/snyk/languageserver/protocolextension/SnykExtendedLanguageClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ private void openToolView() {
399399
}
400400

401401
private Set<ProductTreeNode> getAffectedProductNodes(String snykScanProduct, String folderPath) {
402+
Preferences pref = Preferences.getInstance();
402403
Set<ProductTreeNode> affectedProductTreeNodes = new HashSet<>();
403404
var displayProduct = SCAN_PARAMS_TO_DISPLAYED.get(snykScanProduct);
404405
if (displayProduct != null) {
@@ -408,11 +409,11 @@ private Set<ProductTreeNode> getAffectedProductNodes(String snykScanProduct, Str
408409
}
409410
} else {
410411
ProductTreeNode productNode = toolView.getProductNode(DISPLAYED_CODE_SECURITY, folderPath);
411-
if (productNode != null) {
412+
if (productNode != null && pref.getBooleanPref(Preferences.ACTIVATE_SNYK_CODE_SECURITY)) {
412413
affectedProductTreeNodes.add(productNode);
413414
}
414415
productNode = toolView.getProductNode(DISPLAYED_CODE_QUALITY, folderPath);
415-
if (productNode != null) {
416+
if (productNode != null && pref.getBooleanPref(Preferences.ACTIVATE_SNYK_CODE_QUALITY)) {
416417
affectedProductTreeNodes.add(productNode);
417418
}
418419
}

tests/src/test/java/io/snyk/languageserver/protocolextension/SnykExtendedLanguageClientTest.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void testPublishDiagnosticsShouldChangeCache() {
191191
folderPath = "C://a/b";
192192
uri = "file:///" + folderPath + "/c/";
193193
}
194-
194+
195195

196196
File pathFromUri = LSPEclipseUtils.fromUri(URI.create(uri));
197197
var filePath = pathFromUri.getAbsolutePath();
@@ -237,6 +237,8 @@ void testSnykScanUpdatesRootNodeStatus() {
237237
param.setFolderPath("a/b/c");
238238
ProductTreeNode productNode = new ProductTreeNode(DISPLAYED_CODE_SECURITY);
239239
when(toolWindowMock.getProductNode(DISPLAYED_CODE_SECURITY, param.getFolderPath())).thenReturn(productNode);
240+
pref.store(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "true");
241+
pref.store(Preferences.ACTIVATE_SNYK_CODE_QUALITY, "true");
240242

241243
cut = new SnykExtendedLanguageClient();
242244
cut.setToolWindow(toolWindowMock);
@@ -253,6 +255,8 @@ void testSnykScanSuccessAddsInfoNodes_NoIssuesFound() {
253255
param.setStatus(SCAN_STATE_SUCCESS);
254256
param.setProduct(SCAN_PARAMS_CODE);
255257
param.setFolderPath("a/b/c");
258+
pref.store(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "true");
259+
pref.store(Preferences.ACTIVATE_SNYK_CODE_QUALITY, "true");
256260

257261
int issueCount = 0;
258262
String expectedFirstInfoNode = CONGRATS_NO_ISSUES_FOUND;
@@ -288,6 +292,8 @@ void testSnykScanSuccessAddsInfoNodes_IssuesFound_nothingFixable() {
288292

289293
pref.store(Preferences.FILTER_IGNORES_SHOW_IGNORED_ISSUES, "false");
290294
pref.store(Preferences.FILTER_IGNORES_SHOW_OPEN_ISSUES, "true");
295+
pref.store(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "true");
296+
pref.store(Preferences.ACTIVATE_SNYK_CODE_QUALITY, "true");
291297

292298
runInfoNodeTest(param, issueCount, 0, 0, 3, expectedFirstInfoNode, expectedSecondInfoNode,
293299
expectedThirdInfoNode);
@@ -305,6 +311,8 @@ void testSnykScanSuccessAddsInfoNodes_IssuesFound_singleFixable() {
305311

306312
pref.store(Preferences.FILTER_IGNORES_SHOW_IGNORED_ISSUES, "false");
307313
pref.store(Preferences.FILTER_IGNORES_SHOW_OPEN_ISSUES, "true");
314+
pref.store(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "true");
315+
pref.store(Preferences.ACTIVATE_SNYK_CODE_QUALITY, "true");
308316

309317
runInfoNodeTest(param, 1, 1, 0, 3, expectedFirstInfoNode, expectedSecondInfoNode, expectedThirdInfoNode);
310318
}
@@ -321,13 +329,17 @@ void testSnykScanSuccessAddsInfoNodes_IssuesFound_multipleFixable() {
321329

322330
pref.store(Preferences.FILTER_IGNORES_SHOW_IGNORED_ISSUES, "false");
323331
pref.store(Preferences.FILTER_IGNORES_SHOW_OPEN_ISSUES, "true");
332+
pref.store(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "true");
333+
pref.store(Preferences.ACTIVATE_SNYK_CODE_QUALITY, "true");
324334

325335
runInfoNodeTest(param, 4, 2, 0, 3, expectedFirstInfoNode, expectedSecondInfoNode, expectedThirdInfoNode);
326336
}
327337

328338
@Test
329339
void testSnykScanSuccessAddsInfoNodes_IssuesFound_oneIgnored() {
330340
var param = new SnykScanParam();
341+
pref.store(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "true");
342+
pref.store(Preferences.ACTIVATE_SNYK_CODE_QUALITY, "true");
331343
param.setStatus(SCAN_STATE_SUCCESS);
332344
param.setProduct(SCAN_PARAMS_CODE);
333345
param.setFolderPath("a/b/c");
@@ -348,6 +360,8 @@ void testSnykScanSuccessAddsInfoNodes_IssuesFound_onlyIgnoredDisplayed() {
348360
pref.store(Preferences.IS_GLOBAL_IGNORES_FEATURE_ENABLED, "true");
349361
pref.store(Preferences.FILTER_IGNORES_SHOW_OPEN_ISSUES, "true");
350362
pref.store(Preferences.FILTER_IGNORES_SHOW_IGNORED_ISSUES, "false");
363+
pref.store(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "true");
364+
pref.store(Preferences.ACTIVATE_SNYK_CODE_QUALITY, "true");
351365

352366
String expectedFirstInfoNode = "✋ 4 issues found by Snyk, 4 ignored";
353367
String expectedSecondInfoNode = "⚡️ 2 issues can be fixed automatically";
@@ -365,6 +379,8 @@ void testSnykScanSuccessAddsInfoNodes_IssuesFound_onlyOpenDisplayed() {
365379
pref.store(Preferences.IS_GLOBAL_IGNORES_FEATURE_ENABLED, "true");
366380
pref.store(Preferences.FILTER_IGNORES_SHOW_OPEN_ISSUES, "false");
367381
pref.store(Preferences.FILTER_IGNORES_SHOW_IGNORED_ISSUES, "true");
382+
pref.store(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "true");
383+
pref.store(Preferences.ACTIVATE_SNYK_CODE_QUALITY, "true");
368384

369385
String expectedFirstInfoNode = "✋ 4 issues found by Snyk";
370386
String expectedSecondInfoNode = "⚡️ 2 issues can be fixed automatically";
@@ -376,7 +392,7 @@ void testSnykScanSuccessAddsInfoNodes_IssuesFound_onlyOpenDisplayed() {
376392
private void runInfoNodeTest(SnykScanParam param, int issueCount, int fixableCount, int ignoredCount,
377393
int expectedInfoNodeUpdateCount, String expectedFirstInfoNode, String expectedSecondInfoNode,
378394
String expectedThirdInfoNode) {
379-
395+
380396
var productNodes = setupProductNodes(param);
381397

382398
var infoNodeCaptor = ArgumentCaptor.forClass(InfoTreeNode.class);
@@ -568,4 +584,4 @@ void testGetTotal() throws IOException {
568584
private AdditionalData getSecurityIssue() {
569585
return Instancio.of(AdditionalData.class).set(Select.field(AdditionalData::isSecurityType), true).create();
570586
}
571-
}
587+
}

0 commit comments

Comments
 (0)