Skip to content

Commit 38fa5bc

Browse files
SC-28409 Make sonar-security compatible with SLCORE
1 parent 3154bd8 commit 38fa5bc

File tree

8 files changed

+139
-0
lines changed

8 files changed

+139
-0
lines changed

backend/analysis-engine/src/main/java/org/sonarsource/sonarlint/core/analysis/container/analysis/AnalysisContainer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.sonarsource.sonarlint.core.analysis.container.analysis.sensor.SonarLintSensorStorage;
4343
import org.sonarsource.sonarlint.core.analysis.container.global.AnalysisExtensionInstaller;
4444
import org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorContext;
45+
import org.sonarsource.sonarlint.core.analysis.sonarapi.noop.NoOpAnalysisWarnings;
4546
import org.sonarsource.sonarlint.core.analysis.sonarapi.noop.NoOpFileLinesContextFactory;
4647
import org.sonarsource.sonarlint.core.commons.log.SonarLintLogger;
4748
import org.sonarsource.sonarlint.core.commons.progress.ProgressIndicator;
@@ -65,6 +66,7 @@ protected void doBeforeStart() {
6566

6667
private void addCoreComponents() {
6768
add(
69+
new NoOpAnalysisWarnings(),
6870
cancelMonitor,
6971
SonarLintInputProject.class,
7072
NoOpFileLinesContextFactory.class,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* SonarLint Core - Analysis Engine
3+
* Copyright (C) 2016-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonarsource.sonarlint.core.analysis.sonarapi.noop;
21+
22+
import org.sonar.api.notifications.AnalysisWarnings;
23+
24+
public class NoOpAnalysisWarnings implements AnalysisWarnings {
25+
26+
@Override
27+
public void addUnique(String s) {
28+
// no-op
29+
}
30+
}

backend/plugin-commons/src/main/java/org/sonarsource/sonarlint/core/plugin/commons/PluginsLoader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ private static Set<String> additionalAllowedPlugins(Configuration configuration)
8181
allowedPluginsIds.add("omnisharp");
8282
allowedPluginsIds.add("iacenterprise");
8383
allowedPluginsIds.add("goenterprise");
84+
allowedPluginsIds.add("security");
85+
allowedPluginsIds.add("securityjavafrontend");
8486
allowedPluginsIds.addAll(maybeDbdAllowedPlugins(configuration.enableDataflowBugDetection));
8587
return Collections.unmodifiableSet(allowedPluginsIds);
8688
}

backend/server-connection/src/main/java/org/sonarsource/sonarlint/core/serverconnection/PluginsSynchronizer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class PluginsSynchronizer {
4141
public static final Version ENTERPRISE_GO_MIN_SQ_VERSION = Version.create("2025.2");
4242
public static final String CSHARP_ENTERPRISE_PLUGIN_ID = "csharpenterprise";
4343
private static final String GO_ENTERPRISE_PLUGIN_ID = "goenterprise";
44+
private static final String SECURITY_PLUGIN_ID = "security";
45+
private static final String SECURITY_JAVA_FRONTEND_PLUGIN_ID = "securityjavafrontend";
4446
private static final SonarLintLogger LOG = SonarLintLogger.get();
4547

4648
private final Set<String> sonarSourceDisabledPluginKeys;
@@ -58,6 +60,10 @@ public PluginsSynchronizer(Set<SonarLanguage> enabledLanguages, ConnectionStorag
5860
// SLCORE-1179 Force synchronize "C# Enterprise" after repackaging (SQS 10.8+)
5961
this.notSonarLintSupportedPluginsToSynchronize.add(CSHARP_ENTERPRISE_PLUGIN_ID);
6062
}
63+
if (enabledLanguages.contains(SonarLanguage.JAVA)) {
64+
this.notSonarLintSupportedPluginsToSynchronize.add(SECURITY_PLUGIN_ID);
65+
this.notSonarLintSupportedPluginsToSynchronize.add(SECURITY_JAVA_FRONTEND_PLUGIN_ID);
66+
}
6167
this.storage = storage;
6268
this.embeddedPluginKeys = embeddedPluginKeys;
6369
}

medium-tests/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@
219219
<version>1.36.1.13250</version>
220220
<type>jar</type>
221221
</artifactItem>
222+
<artifactItem>
223+
<groupId>com.sonarsource.security</groupId>
224+
<artifactId>sonar-security-plugin</artifactId>
225+
<version>11.5.0.38524</version>
226+
<type>jar</type>
227+
</artifactItem>
228+
<artifactItem>
229+
<groupId>com.sonarsource.security</groupId>
230+
<artifactId>sonar-security-java-frontend-plugin</artifactId>
231+
<version>11.5.0.38524</version>
232+
<type>jar</type>
233+
</artifactItem>
222234
</artifactItems>
223235
<outputDirectory>${project.build.directory}/plugins</outputDirectory>
224236
<overWriteReleases>false</overWriteReleases>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* SonarLint Core - Medium Tests
3+
* Copyright (C) 2016-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package mediumtest;
21+
22+
import java.io.File;
23+
import java.util.List;
24+
import java.util.Map;
25+
import org.sonarsource.sonarlint.core.rpc.protocol.backend.file.DidOpenFileParams;
26+
import org.sonarsource.sonarlint.core.rpc.protocol.common.ClientFileDto;
27+
import org.sonarsource.sonarlint.core.test.utils.junit5.SonarLintTest;
28+
import org.sonarsource.sonarlint.core.test.utils.junit5.SonarLintTestHarness;
29+
import utils.TestPlugin;
30+
31+
import static org.assertj.core.api.Assertions.assertThat;
32+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
33+
import static org.mockito.ArgumentMatchers.any;
34+
import static org.mockito.ArgumentMatchers.eq;
35+
import static org.mockito.Mockito.timeout;
36+
import static org.mockito.Mockito.verify;
37+
38+
public class SecurityMediumTest {
39+
private static final String CONFIG_SCOPE_ID = "CONFIG_SCOPE_ID";
40+
private static final boolean COMMERCIAL_ENABLED = System.getProperty("commercial") != null;
41+
42+
@SonarLintTest
43+
void it_should_find_taint_issues(SonarLintTestHarness harness) {
44+
assumeTrue(COMMERCIAL_ENABLED);
45+
var projectWithTaint = new File("/home/damien.urruty/Documents/Benchmark").getAbsoluteFile().toPath();
46+
var srcFilePath = projectWithTaint.resolve("src/main/java/org/owasp/benchmark/testcode/BenchmarkTest00008.java");
47+
var fileUri = srcFilePath.toUri();
48+
var fakeClient = harness.newFakeClient()
49+
.withInitialFs(CONFIG_SCOPE_ID, projectWithTaint, List.of(new ClientFileDto(fileUri, projectWithTaint.relativize(srcFilePath), CONFIG_SCOPE_ID, false,
50+
null, srcFilePath, null, null, true)))
51+
.build();
52+
var backend = harness.newBackend()
53+
.withUnboundConfigScope(CONFIG_SCOPE_ID, "My Project 1")
54+
.withStandaloneRuleConfig("javasecurity:S3649", true, Map.of())
55+
.withStandaloneEmbeddedPlugin(TestPlugin.JAVA)
56+
.withStandaloneEmbeddedPlugin(TestPlugin.SECURITY)
57+
.withStandaloneEmbeddedPluginAndEnabledLanguage(TestPlugin.SECURITY_JAVA_FRONTEND)
58+
.start(fakeClient);
59+
fakeClient.setInferredAnalysisProperties(CONFIG_SCOPE_ID, Map.of("sonar.java.libraries",
60+
"/home/damien.urruty/.m2/repository/javax/javaee-api/7.0/javaee-api-7.0.jar"));
61+
62+
backend.getFileService().didOpenFile(new DidOpenFileParams(CONFIG_SCOPE_ID, fileUri));
63+
64+
verify(fakeClient, timeout(4000).times(1)).raiseIssues(eq(CONFIG_SCOPE_ID), any(), eq(false), any());
65+
var raisedIssuesForScopeId = fakeClient.getRaisedIssuesForScopeId(CONFIG_SCOPE_ID);
66+
assertThat(raisedIssuesForScopeId).isEqualTo(Map.of(fileUri, List.of()));
67+
}
68+
}

medium-tests/src/test/java/utils/PluginLocator.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public class PluginLocator {
3131
public static final String SONAR_JAVA_SE_PLUGIN_JAR = "sonar-java-symbolic-execution-plugin-" + SONAR_JAVA_SE_PLUGIN_VERSION + ".jar";
3232
public static final String SONAR_JAVA_SE_PLUGIN_JAR_HASH = "unused";
3333

34+
public static final String SONAR_SECURITY_PLUGIN_VERSION = "11.6.0-SNAPSHOT";
35+
public static final String SONAR_SECURITY_PLUGIN_JAR = "sonar-security-plugin-" + SONAR_SECURITY_PLUGIN_VERSION + ".jar";
36+
public static final String SONAR_SECURITY_PLUGIN_JAR_HASH = "osef";
37+
38+
public static final String SONAR_SECURITY_JAVA_FRONTEND_PLUGIN_VERSION = "11.6.0-SNAPSHOT";
39+
public static final String SONAR_SECURITY_JAVA_FRONTEND_PLUGIN_JAR = "sonar-security-java-frontend-plugin-" + SONAR_SECURITY_JAVA_FRONTEND_PLUGIN_VERSION + ".jar";
40+
public static final String SONAR_SECURITY_JAVA_FRONTEND_PLUGIN_JAR_HASH = "osef";
41+
3442
public static final String SONAR_DBD_PLUGIN_VERSION = "1.36.1.13250";
3543
public static final String SONAR_DBD_PLUGIN_JAR = "sonar-dbd-plugin-" + SONAR_DBD_PLUGIN_VERSION + ".jar";
3644
public static final String SONAR_DBD_PLUGIN_JAR_HASH = "unused";
@@ -64,6 +72,14 @@ public static Path getJavaPluginPath() {
6472
return getValidPluginPath(SONAR_JAVA_PLUGIN_JAR);
6573
}
6674

75+
public static Path getSecurityPluginPath() {
76+
return getValidPluginPath(SONAR_SECURITY_PLUGIN_JAR);
77+
}
78+
79+
public static Path getSecurityJavaFrontendPluginPath() {
80+
return getValidPluginPath(SONAR_SECURITY_JAVA_FRONTEND_PLUGIN_JAR);
81+
}
82+
6783
public static Path getJavaSePluginPath() {
6884
return getPluginPath(SONAR_JAVA_SE_PLUGIN_JAR);
6985
}

medium-tests/src/test/java/utils/TestPlugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public class TestPlugin {
2929
public static final Plugin JAVA = new Plugin(Language.JAVA, PluginLocator.getJavaPluginPath(), PluginLocator.SONAR_JAVA_PLUGIN_VERSION, PluginLocator.SONAR_JAVA_PLUGIN_JAR_HASH);
3030
public static final Plugin JAVA_SE = new Plugin("javasymbolicexecution", Language.JAVA, PluginLocator.getJavaSePluginPath(), PluginLocator.SONAR_JAVA_SE_PLUGIN_VERSION, PluginLocator.SONAR_JAVA_SE_PLUGIN_JAR_HASH);
3131

32+
public static final Plugin SECURITY = new Plugin(Language.JAVA, PluginLocator.getSecurityPluginPath(), PluginLocator.SONAR_SECURITY_PLUGIN_VERSION, PluginLocator.SONAR_SECURITY_PLUGIN_JAR_HASH);
33+
public static final Plugin SECURITY_JAVA_FRONTEND = new Plugin(Language.JAVA, PluginLocator.getSecurityJavaFrontendPluginPath(), PluginLocator.SONAR_SECURITY_JAVA_FRONTEND_PLUGIN_VERSION, PluginLocator.SONAR_SECURITY_JAVA_FRONTEND_PLUGIN_JAR_HASH);
34+
3235
public static final Plugin DBD = new Plugin("dbd", Language.JAVA, PluginLocator.getDbdPluginPath(), PluginLocator.SONAR_DBD_PLUGIN_VERSION, PluginLocator.SONAR_DBD_PLUGIN_JAR_HASH);
3336
public static final Plugin DBD_JAVA = new Plugin("dbdjavafrontend", Language.JAVA, PluginLocator.getDbdJavaPluginPath(), PluginLocator.SONAR_DBD_JAVA_PLUGIN_VERSION, PluginLocator.SONAR_DBD_JAVA_PLUGIN_JAR_HASH);
3437

0 commit comments

Comments
 (0)