Skip to content
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

SLVS-1672 Feature/hardening q4 4 #5871

Merged
merged 6 commits into from
Dec 3, 2024
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
4 changes: 2 additions & 2 deletions THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ mailto:info AT sonarsource DOT com
This program is distributed with SonarQube analyzers that are subject to
specific license terms.

The sonar-csharp-enterprise-plugin and sonar-vbnet-enterprise-plugin are
SonarQube analyzers published under the following proprietary license:
The sonar-cfamily, sonar-csharp-enterprise-plugin and sonar-vbnet-enterprise-plugin
are SonarQube analyzers published under the following proprietary license:
SonarSource SA grants you a non-transferable, non-sublicensable,
limited license to use the aforementioned plugins solely as part of this
program. Any use, reproduction, distribution, or modification of the
Expand Down
8 changes: 4 additions & 4 deletions src/EmbeddedSonarAnalyzer.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<PropertyGroup>
<!-- Note: Guide on how to update the analyzers is on the xtranet! -->
<EmbeddedSonarAnalyzerVersion>10.3.0.106239</EmbeddedSonarAnalyzerVersion>
<EmbeddedSonarCFamilyAnalyzerVersion>6.60.0.76379</EmbeddedSonarCFamilyAnalyzerVersion>
<EmbeddedSonarJSAnalyzerVersion>10.16.0.27621</EmbeddedSonarJSAnalyzerVersion>
<EmbeddedSonarSecretsJarVersion>2.16.0.4008</EmbeddedSonarSecretsJarVersion>
<EmbeddedSonarCFamilyAnalyzerVersion>6.61.0.77816</EmbeddedSonarCFamilyAnalyzerVersion>
<EmbeddedSonarJSAnalyzerVersion>10.18.0.28572</EmbeddedSonarJSAnalyzerVersion>
<EmbeddedSonarSecretsJarVersion>2.19.0.4883</EmbeddedSonarSecretsJarVersion>
<!-- SLOOP: Binaries for SonarLint Out Of Process -->
<EmbeddedSloopVersion>10.10.0.79572</EmbeddedSloopVersion>
<EmbeddedSloopVersion>10.11.0.79687</EmbeddedSloopVersion>
</PropertyGroup>
</Project>
15 changes: 9 additions & 6 deletions src/Integration.UnitTests/LocalServices/FileTrackerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void MefCtor_CheckExports()
MefTestHelpers.CreateExport<IClientFileDtoFactory>(),
MefTestHelpers.CreateExport<ILogger>());
}

[TestMethod]
public void AddFiles_ServiceProviderFailed_LogsError()
{
Expand All @@ -56,7 +56,7 @@ public void AddFiles_ServiceProviderFailed_LogsError()
var testLogger = new TestLogger();

var testSubject = new FileTracker(serviceProvider, activeConfigScopeTracker, threadHandling, clientFileDtoFactory, testLogger);

testSubject.AddFiles(new SourceFile("C:\\Users\\test\\TestProject\\AFile.cs"));

testLogger.AssertOutputStrings($"[FileTracker] {SLCoreStrings.ServiceProviderNotInitialized}");
Expand All @@ -72,7 +72,8 @@ public void AddFiles_ShouldForwardFilesToSlCore()
testSubject.AddFiles(new SourceFile("C:\\Users\\test\\TestProject\\AFile.cs"));

result.removedFiles.Should().BeEmpty();
result.addedOrChangedFiles.Should().ContainSingle();
result.addedFiles.Should().BeEmpty();
result.changedFiles.Should().ContainSingle();
}

[TestMethod]
Expand All @@ -86,7 +87,8 @@ public void RemoveFiles_ShouldForwardFilesToSlCore()

result.removedFiles.Should().ContainSingle();
result.removedFiles[0].Should().BeEquivalentTo(new FileUri("C:\\Users\\test\\TestProject\\AFile.cs"));
result.addedOrChangedFiles.Should().BeEmpty();
result.addedFiles.Should().BeEmpty();
result.changedFiles.Should().BeEmpty();
}

[TestMethod]
Expand All @@ -101,7 +103,8 @@ public void RenameFiles_ShouldForwardFilesToSlCore()

result.removedFiles.Should().ContainSingle();
result.removedFiles[0].Should().BeEquivalentTo(new FileUri("C:\\Users\\test\\TestProject\\AFile.cs"));
result.addedOrChangedFiles.Should().ContainSingle();
result.addedFiles.Should().BeEmpty();
result.changedFiles.Should().ContainSingle();
}

private static FileTracker CreateTestSubject(out IFileRpcSLCoreService slCoreService)
Expand All @@ -124,7 +127,7 @@ private static FileTracker CreateTestSubject(out IFileRpcSLCoreService slCoreSer
.Returns(async info => await info.Arg<Func<Task<int>>>()());

var logger = Substitute.For<ILogger>();

return new FileTracker(serviceProvider, activeConfigScopeTracker, threadHandling, clientFileDtoFactory, logger);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public class CFamilyEmbeddedSonarWayRulesTests
// e.g. https://next.sonarqube.com/sonarqube/api/plugins/installed and https://sonarcloud.io/api/plugins/installed
// Note - you need to be logged in.

// Rule data for C-Family plugin v6.57.0.73017
// Rule data for C-Family plugin v6.61.0.77816

private const int Active_C_Rules = 209;
private const int Active_C_Rules = 211;
private const int Inactive_C_Rules = 130;

private const int Active_CPP_Rules = 445;
private const int Active_CPP_Rules = 453;
private const int Inactive_CPP_Rules = 219;

private readonly CFamilySonarWayRulesConfigProvider rulesMetadataCache = new CFamilySonarWayRulesConfigProvider(CFamilyShared.CFamilyFilesDirectory);
Expand Down
12 changes: 7 additions & 5 deletions src/Integration/LocalServices/FileTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ public void RenameFiles(string[] beforeRenameFiles, SourceFile[] afterRenameFile
.Forget();
}

private void NotifySlCoreFilesChanged(string[] removedFiles, SourceFile[] addedFiles)
private void NotifySlCoreFilesChanged(string[] removedFiles, SourceFile[] addedOrChangedFiles)
{
if (serviceProvider.TryGetTransientService(out IFileRpcSLCoreService fileRpcSlCoreService) && activeConfigScopeTracker.Current is {} configScope)
if (serviceProvider.TryGetTransientService(out IFileRpcSLCoreService fileRpcSlCoreService) && activeConfigScopeTracker.Current is {} configScope)
{
var clientFiles = addedFiles.Select(sourceFile => clientFileDtoFactory.Create(configScope.Id, configScope.RootPath, sourceFile)).ToList();
var clientFiles = addedOrChangedFiles.Select(sourceFile => clientFileDtoFactory.Create(configScope.Id, configScope.RootPath, sourceFile)).ToList();
var removedFileUris = removedFiles.Select(f => new FileUri(f)).ToList();

fileRpcSlCoreService.DidUpdateFileSystem(new DidUpdateFileSystemParams(
removedFileUris, clientFiles));
/* we're only sending changed files here as it is complicated to implement the proper tracking of added files
AND `changed` files that were actually added are recognized as added by SLCore
https://github.com/SonarSource/sonarlint-core/pull/1163/files#diff-070e6ef952d4a71245d92ea8f281c5a56050e8992179cde3955d4b1530dff664R152 */
fileRpcSlCoreService.DidUpdateFileSystem(new DidUpdateFileSystemParams(removedFileUris, [], clientFiles));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public void Convert_CalculatesChecksumForCodeSnippet()
var issue = testSubject.Convert(new IssueDetailDto("key",
"ruleKey",
"ide\\path",
"branch",
"pr",
"msg",
"today",
codeSnippet,
Expand All @@ -83,8 +81,6 @@ public void Convert_PathTranslated()
var issue = testSubject.Convert(new IssueDetailDto("key",
"ruleKey",
"ide\\path",
"branch",
"pr",
"msg",
"today",
"codeSnippet",
Expand Down Expand Up @@ -112,8 +108,6 @@ public void Convert_PrimaryRangeAndMessagePreserved()
var issue = testSubject.Convert(new IssueDetailDto("key",
"ruleKey",
"ide\\path",
"branch",
"pr",
message,
"today",
"codeSnippet",
Expand All @@ -138,8 +132,6 @@ public void Convert_RuleKeyPreserved()
var issue = testSubject.Convert(new IssueDetailDto("key",
ruleKey,
"ide\\path",
"branch",
"pr",
"msg",
"today",
"codeSnippet",
Expand All @@ -161,8 +153,6 @@ public void Convert_FlowsPreservedWithPathTranslation()
var issue = testSubject.Convert(new IssueDetailDto("key",
"rule",
"ide\\path",
"branch",
"pr",
"msg",
"today",
"codeSnippet",
Expand Down
10 changes: 5 additions & 5 deletions src/IssueViz.UnitTests/OpenInIDE/OpenIssueInIdeHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ public void MefCtor_CheckIsSingleton()
{
MefTestHelpers.CheckIsSingletonMefComponent<OpenIssueInIdeHandler>();
}

[DataTestMethod]
[DataRow(true)]
[DataRow(false)]
public void Show_CallsBaseHandler(bool isTaint)
{
const string configScope = "configscope";
var issue = new IssueDetailDto(default, default, default, default, default, default,
var issue = new IssueDetailDto(default, default, default, default,
default, default, isTaint, default, default);
var testSubject = CreateTestSubject(out var handler, out var converter);

testSubject.Show(issue, configScope);

handler.Received().ShowIssue(issue, configScope, converter, isTaint ? IssueListIds.TaintId : IssueListIds.ErrorListId, null);
}

Expand All @@ -66,5 +66,5 @@ private OpenIssueInIdeHandler CreateTestSubject(out IOpenInIdeHandlerImplementat
issueOpenInIdeConverter = Substitute.For<IIssueDetailDtoToAnalysisIssueConverter>();
return new OpenIssueInIdeHandler(openInIdeHandlerImplementation,
issueOpenInIdeConverter);
}
}
}
53 changes: 27 additions & 26 deletions src/SLCore.IntegrationTests/FileAnalysisTestsRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,77 +177,78 @@ public void Dispose()
internal interface ITestingFile
{
string RelativePath { get; }
List<ExpectedTestIssue> ExpectedIssues { get; }
List<TestIssue> ExpectedIssues { get; }
}

internal record ExpectedTestIssue(string ruleKey, TextRangeDto textRange, CleanCodeAttribute cleanCodeAttribute, int expectedFlows);
internal record TestIssue(string ruleKey, TextRangeDto textRange, CleanCodeAttribute? cleanCodeAttribute, int expectedFlows);

internal class JavaScriptIssuesFile : ITestingFile
{
public string RelativePath => @"Resources\JavaScriptIssues.js";

public List<ExpectedTestIssue> ExpectedIssues =>
public List<TestIssue> ExpectedIssues =>
[
new ExpectedTestIssue("javascript:S1135", new TextRangeDto(1, 3, 1, 7), CleanCodeAttribute.COMPLETE, 0),
new ExpectedTestIssue("javascript:S3504", new TextRangeDto(2, 0, 2, 5), CleanCodeAttribute.CLEAR, 0)
new("javascript:S1135", new TextRangeDto(1, 3, 1, 7), CleanCodeAttribute.COMPLETE, 0),
new("javascript:S3504", new TextRangeDto(2, 0, 2, 5), CleanCodeAttribute.CLEAR, 0)
];
}

internal class OneIssueRuleWithParamFile : ITestingFile
{
public string RelativePath => @"Resources\RuleParam.js";
public readonly string CtorParamRuleId = "javascript:S107";
public readonly int ActualCtorParams = 4;
public readonly string CtorParamName = "maximumFunctionParameters";
public List<ExpectedTestIssue> ExpectedIssues { get; set; }

public const string CtorParamRuleId = "javascript:S107";
public const int ActualCtorParams = 4;
public const string CtorParamName = "maximumFunctionParameters";
public List<TestIssue> ExpectedIssues { get; set; }
}

internal class TypeScriptIssuesFile : ITestingFile
{
public string RelativePath => @"Resources\TypeScriptIssues.ts";

public List<ExpectedTestIssue> ExpectedIssues =>
public List<TestIssue> ExpectedIssues =>
[
new ExpectedTestIssue("typescript:S2737", new TextRangeDto(3, 2, 3, 7), CleanCodeAttribute.CLEAR, 0),
new ExpectedTestIssue("typescript:S1186", new TextRangeDto(7, 16, 7, 19), CleanCodeAttribute.COMPLETE, 0),
new ExpectedTestIssue("typescript:S3776", new TextRangeDto(30, 9, 30, 18), CleanCodeAttribute.FOCUSED, 21)
new("typescript:S2737", new TextRangeDto(3, 2, 3, 7), CleanCodeAttribute.CLEAR, 0),
new("typescript:S1186", new TextRangeDto(7, 16, 7, 19), CleanCodeAttribute.COMPLETE, 0),
new("typescript:S3776", new TextRangeDto(30, 9, 30, 18), CleanCodeAttribute.FOCUSED, 21)
];
}

internal class CssIssuesFile : ITestingFile
{
public string RelativePath => @"Resources\CssIssues.css";

public List<ExpectedTestIssue> ExpectedIssues =>
public List<TestIssue> ExpectedIssues =>
[
new ExpectedTestIssue("css:S4666", new TextRangeDto(20, 0, 20, 77), CleanCodeAttribute.LOGICAL, 0),
new ExpectedTestIssue("css:S4655", new TextRangeDto(12, 0, 12, 38), CleanCodeAttribute.LOGICAL, 0),
new("css:S4666", new TextRangeDto(20, 0, 20, 77), CleanCodeAttribute.LOGICAL, 0),
new("css:S4655", new TextRangeDto(12, 0, 12, 38), CleanCodeAttribute.LOGICAL, 0),
];
}

internal class VueIssuesFile : ITestingFile
{
public string RelativePath => @"Resources\VueIssues.vue";

public List<ExpectedTestIssue> ExpectedIssues =>
public List<TestIssue> ExpectedIssues =>
[
new ExpectedTestIssue("css:S4661", new TextRangeDto(12, 0, 12, 43), CleanCodeAttribute.LOGICAL, 0),
new ExpectedTestIssue("css:S4658", new TextRangeDto(12, 0, 12, 43), CleanCodeAttribute.CLEAR, 0),
new("css:S4661", new TextRangeDto(12, 0, 12, 43), CleanCodeAttribute.LOGICAL, 0),
new("css:S4658", new TextRangeDto(12, 0, 12, 43), CleanCodeAttribute.CLEAR, 0),
];
}

internal class SecretsIssuesFile : ITestingFile
{
private const string CloudSecretsRuleKey = "secrets:S6336";
private const string AmazonSecretsRuleKey = "secrets:S6290";
private const string AzureSecretsRuleKey = "secrets:S6684";
public string RelativePath => @"Resources\Secrets.yml";
public (string ruleKey, int issuesCount) RuleWithMultipleIssues => (CloudSecretsRuleKey, 2);
public (string ruleKey, int issuesCount) RuleWithMultipleIssues => (AmazonSecretsRuleKey, 2);

public List<ExpectedTestIssue> ExpectedIssues =>
public List<TestIssue> ExpectedIssues =>
[
new ExpectedTestIssue(CloudSecretsRuleKey, new TextRangeDto(9, 24, 9, 40), CleanCodeAttribute.TRUSTWORTHY, 0),
new ExpectedTestIssue(CloudSecretsRuleKey, new TextRangeDto(14, 24, 14, 40), CleanCodeAttribute.TRUSTWORTHY, 0),
new ExpectedTestIssue("secrets:S6337", new TextRangeDto(20, 12, 20, 56), CleanCodeAttribute.TRUSTWORTHY, 0),
new(AmazonSecretsRuleKey, new TextRangeDto(9, 38, 9, 78), CleanCodeAttribute.TRUSTWORTHY, 0),
new(AmazonSecretsRuleKey, new TextRangeDto(14, 38, 14, 78), CleanCodeAttribute.TRUSTWORTHY, 0),
new(AzureSecretsRuleKey, new TextRangeDto(20, 33, 20, 65), CleanCodeAttribute.TRUSTWORTHY, 0),
];
}

Expand Down
16 changes: 11 additions & 5 deletions src/SLCore.IntegrationTests/Resources/Secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@


#________________
# S6336 - Alibaba Cloud AccessKeys should not be disclosed
# S6290 - Amazon Web Services credentials should not be disclosed

#"String aliyunAcecret="LTAI5tBcc9SecYAo";
# props.set("aws-secret-access-key", "kHeUAwnSUizTWpSbyGAz4f+As5LshPIjvtpswqGb")

#___________________________________________________________________
# S6336 - Alibaba Cloud AccessKeys should not be disclosed
# S6290 - Amazon Web Services credentials should not be disclosed

#"String aliyunAcecret="LTAI5tBcc9SecYAo";
# props.set("aws-secret-access-key", "kHeUAwnSUizTWpSbyGAz4f+As5LshPIjvtpswqGb")

#___________________________________________________________________

# S6684 Azure Subscription Keys should not be disclosed

# props.set("subscription_key", "efbb1a98f026d061464af685cd16dcd3")

#___________________________________________________________________

# S6337 - IBM API keys should not be disclosed

#"apikey": "fDKU7e_u_EnQgWgDVO4b_ubGqVTa5IYwWEey7lMfEB_1"
#"apikey": "fDKU7e_u_EnQgWgDVO4b_ubGqVTa5IYwWEey7lMfEB_1" NOT SUPPORTED WITH BASIC ANALYZER

#___________________________________________________________________

Loading
Loading