Skip to content

Commit

Permalink
SLVS-1666 Update Sonar.Text to 2.19.0.4883 (#5866)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Dec 3, 2024
1 parent b1f413e commit 92b1fae
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/EmbeddedSonarAnalyzer.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<EmbeddedSonarAnalyzerVersion>10.3.0.106239</EmbeddedSonarAnalyzerVersion>
<EmbeddedSonarCFamilyAnalyzerVersion>6.60.0.76379</EmbeddedSonarCFamilyAnalyzerVersion>
<EmbeddedSonarJSAnalyzerVersion>10.18.0.28572</EmbeddedSonarJSAnalyzerVersion>
<EmbeddedSonarSecretsJarVersion>2.16.0.4008</EmbeddedSonarSecretsJarVersion>
<EmbeddedSonarSecretsJarVersion>2.19.0.4883</EmbeddedSonarSecretsJarVersion>
<!-- SLOOP: Binaries for SonarLint Out Of Process -->
<EmbeddedSloopVersion>10.10.0.79572</EmbeddedSloopVersion>
</PropertyGroup>
Expand Down
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

#___________________________________________________________________

30 changes: 15 additions & 15 deletions src/SLCore.IntegrationTests/RuleConfigurationAnalysisTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void ClassInitialize(TestContext context)
{
sharedFileAnalysisTestsRunner = new FileAnalysisTestsRunner(nameof(RuleConfigurationAnalysisTests));
}

[ClassCleanup]
public static void ClassCleanup()
{
Expand All @@ -48,13 +48,13 @@ public async Task StandaloneRuleConfig_JavaScriptAnalysisShouldIgnoreOneIssueOfI
var ruleToDisable = FileAnalysisTestsRunner.JavaScriptIssues.ExpectedIssues[0];
var ruleConfig = CreateInactiveRuleConfig(ruleToDisable.ruleKey);
sharedFileAnalysisTestsRunner.SetRuleConfiguration(ruleConfig);

var issuesByFileUri = await sharedFileAnalysisTestsRunner.RunFileAnalysis(FileAnalysisTestsRunner.JavaScriptIssues, TestContext.TestName);

issuesByFileUri.Should().HaveCount(1);
issuesByFileUri[new FileUri(FileAnalysisTestsRunner.JavaScriptIssues.GetFullPath())].Should().HaveCount(FileAnalysisTestsRunner.JavaScriptIssues.ExpectedIssues.Count - 1);
}

[TestMethod]
public async Task StandaloneRuleConfig_SecretsAnalysisShouldIgnoreTwoIssuesOfInactiveRule()
{
Expand All @@ -67,7 +67,7 @@ public async Task StandaloneRuleConfig_SecretsAnalysisShouldIgnoreTwoIssuesOfIna
issuesByFileUri.Should().HaveCount(1);
issuesByFileUri[new FileUri(FileAnalysisTestsRunner.SecretsIssues.GetFullPath())].Should().HaveCount(FileAnalysisTestsRunner.SecretsIssues.ExpectedIssues.Count - multipleIssuesRule.issuesCount);
}

[TestMethod]
public async Task StandaloneRuleConfig_JsLetRuleIsDisableInSettingsFile_JavaScriptAnalysisShouldIgnoreIssueOnInitialization()
{
Expand All @@ -80,7 +80,7 @@ public async Task StandaloneRuleConfig_JsLetRuleIsDisableInSettingsFile_JavaScri
issuesByFileUri.Should().HaveCount(1);
issuesByFileUri[new FileUri(FileAnalysisTestsRunner.JavaScriptIssues.GetFullPath())].Should().HaveCount(FileAnalysisTestsRunner.JavaScriptIssues.ExpectedIssues.Count - 1);
}

[TestMethod]
public async Task StandaloneRuleConfig_CloudSecretsRuleIsDisabledInSettingsFile_SecretsAnalysisShouldIgnoreIssueOnInitialization()
{
Expand All @@ -89,31 +89,31 @@ public async Task StandaloneRuleConfig_CloudSecretsRuleIsDisabledInSettingsFile_
using var customTestRunner = new FileAnalysisTestsRunner(TestContext.TestName, secretsRuleConfig);

var issuesByFileUri = await customTestRunner.RunFileAnalysis(FileAnalysisTestsRunner.SecretsIssues, TestContext.TestName);

issuesByFileUri.Should().HaveCount(1);
issuesByFileUri[new FileUri(FileAnalysisTestsRunner.SecretsIssues.GetFullPath())].Should().HaveCount(FileAnalysisTestsRunner.SecretsIssues.ExpectedIssues.Count - multipleIssuesRule.issuesCount);
}

[TestMethod]
public async Task StandaloneRuleConfig_CtorParamsUnderThreshold_JavaScriptActiveRuleShouldHaveNoIssue()
{
var ctorParamsRuleConfig = CreateActiveCtorParamRuleConfig(threshold: FileAnalysisTestsRunner.OneIssueRuleWithParam.ActualCtorParams + 1);
var ctorParamsRuleConfig = CreateActiveCtorParamRuleConfig(threshold: OneIssueRuleWithParamFile.ActualCtorParams + 1);
sharedFileAnalysisTestsRunner.SetRuleConfiguration(ctorParamsRuleConfig);

var issuesByFileUri = await sharedFileAnalysisTestsRunner.RunFileAnalysis(FileAnalysisTestsRunner.OneIssueRuleWithParam, TestContext.TestName);

issuesByFileUri.Should().HaveCount(1);
issuesByFileUri[new FileUri(FileAnalysisTestsRunner.OneIssueRuleWithParam.GetFullPath())].Should().HaveCount(0);
}

[TestMethod]
public async Task StandaloneRuleConfig_CtorParamsAboveThreshold_JavaScriptActiveRuleShouldHaveOneIssue()
{
var ctorParamsRuleConfig = CreateActiveCtorParamRuleConfig(threshold: FileAnalysisTestsRunner.OneIssueRuleWithParam.ActualCtorParams - 1);
var ctorParamsRuleConfig = CreateActiveCtorParamRuleConfig(threshold: OneIssueRuleWithParamFile.ActualCtorParams - 1);
sharedFileAnalysisTestsRunner.SetRuleConfiguration(ctorParamsRuleConfig);

var issuesByFileUri = await sharedFileAnalysisTestsRunner.RunFileAnalysis(FileAnalysisTestsRunner.OneIssueRuleWithParam, TestContext.TestName);

issuesByFileUri.Should().HaveCount(1);
issuesByFileUri[new FileUri(FileAnalysisTestsRunner.OneIssueRuleWithParam.GetFullPath())].Should().HaveCount(1);
}
Expand All @@ -122,7 +122,7 @@ private static Dictionary<string, StandaloneRuleConfigDto> CreateActiveCtorParam
{
return new()
{
{ FileAnalysisTestsRunner.OneIssueRuleWithParam.CtorParamRuleId, new StandaloneRuleConfigDto(isActive: true, new() { { FileAnalysisTestsRunner.OneIssueRuleWithParam.CtorParamName, threshold.ToString() } }) }
{ OneIssueRuleWithParamFile.CtorParamRuleId, new StandaloneRuleConfigDto(isActive: true, new() { { OneIssueRuleWithParamFile.CtorParamName, threshold.ToString() } }) }
};
}

Expand Down
28 changes: 10 additions & 18 deletions src/SLCore.IntegrationTests/SimpleAnalysisTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

using SonarLint.VisualStudio.SLCore.Common.Models;
using SonarLint.VisualStudio.SLCore.Listener.Analysis.Models;

namespace SonarLint.VisualStudio.SLCore.IntegrationTests;

Expand All @@ -34,27 +35,27 @@ public static void ClassInitialize(TestContext context)
{
sharedFileAnalysisTestsRunner = new FileAnalysisTestsRunner(nameof(SimpleAnalysisTests));
}

[ClassCleanup]
public static void ClassCleanup()
{
sharedFileAnalysisTestsRunner.Dispose();
}

[TestMethod]
public Task DefaultRuleConfig_ContentFromDisk_JavaScriptAnalysisProducesExpectedIssues()
public Task DefaultRuleConfig_ContentFromDisk_JavaScriptAnalysisProducesExpectedIssues()
=> DefaultRuleConfig_AnalysisProducesExpectedIssuesInFile(FileAnalysisTestsRunner.JavaScriptIssues,false);

[TestMethod]
public Task DefaultRuleConfig_ContentFromRpc_JavaScriptAnalysisProducesExpectedIssues()
public Task DefaultRuleConfig_ContentFromRpc_JavaScriptAnalysisProducesExpectedIssues()
=> DefaultRuleConfig_AnalysisProducesExpectedIssuesInFile(FileAnalysisTestsRunner.JavaScriptIssues,true);

[TestMethod]
public Task DefaultRuleConfig_ContentFromDisk_SecretsAnalysisProducesExpectedIssues()
public Task DefaultRuleConfig_ContentFromDisk_SecretsAnalysisProducesExpectedIssues()
=> DefaultRuleConfig_AnalysisProducesExpectedIssuesInFile(FileAnalysisTestsRunner.SecretsIssues, false);

[TestMethod]
public Task DefaultRuleConfig_ContentFromRpc_SecretsAnalysisProducesExpectedIssues()
public Task DefaultRuleConfig_ContentFromRpc_SecretsAnalysisProducesExpectedIssues()
=> DefaultRuleConfig_AnalysisProducesExpectedIssuesInFile(FileAnalysisTestsRunner.SecretsIssues, true);

[TestMethod]
Expand Down Expand Up @@ -87,16 +88,7 @@ private async Task DefaultRuleConfig_AnalysisProducesExpectedIssuesInFile(ITesti

issuesByFileUri.Should().HaveCount(1);
var receivedIssues = issuesByFileUri[new FileUri(testingFile.GetFullPath())];
receivedIssues.Should().HaveCount(testingFile.ExpectedIssues.Count);

foreach (var expectedIssue in testingFile.ExpectedIssues)
{
var receivedIssue = receivedIssues.SingleOrDefault(x => x.ruleKey == expectedIssue.ruleKey && x.textRange.Equals(expectedIssue.textRange));
receivedIssue.Should().NotBeNull();
receivedIssue.severityMode.Right.Should().NotBeNull();
receivedIssue.severityMode.Right.cleanCodeAttribute.Should().Be(expectedIssue.cleanCodeAttribute);
receivedIssue.flows.Count.Should().Be(expectedIssue.expectedFlows);
}
var receivedTestIssues = receivedIssues.Select(x => new TestIssue(x.ruleKey, x.textRange, x.severityMode.Right?.cleanCodeAttribute, x.flows.Count));
receivedTestIssues.Should().BeEquivalentTo(testingFile.ExpectedIssues);
}

}

0 comments on commit 92b1fae

Please sign in to comment.