Skip to content

Commit

Permalink
SLVS-1691 Remove unused SQ GetRules requests and properties
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Dec 27, 2024
1 parent c1012fa commit 0783bd0
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 362 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ public class CSharpVBBindingConfigProviderTests
private SonarQubeQualityProfile validQualityProfile;

private static readonly SonarQubeRule ActiveRuleWithUnsupportedSeverity = new SonarQubeRule("activeHotspot", "any1",
true, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.SecurityHotspot, null, null, null, null, null, null);
true, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.SecurityHotspot);

private static readonly SonarQubeRule InactiveRuleWithUnsupportedSeverity = new SonarQubeRule("inactiveHotspot", "any2",
false, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.SecurityHotspot, null, null, null, null, null, null);
false, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.SecurityHotspot);

private static readonly SonarQubeRule ActiveTaintAnalysisRule = new SonarQubeRule("activeTaint", "roslyn.sonaranalyzer.security.foo",
true, SonarQubeIssueSeverity.Blocker, null, null,null, SonarQubeIssueType.CodeSmell, null, null, null, null, null, null);
true, SonarQubeIssueSeverity.Blocker, null, null,null, SonarQubeIssueType.CodeSmell);

private static readonly SonarQubeRule InactiveTaintAnalysisRule = new SonarQubeRule("inactiveTaint", "roslyn.sonaranalyzer.security.bar",
false, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.CodeSmell, null, null, null, null, null, null);
false, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.CodeSmell);

[TestInitialize]
public void TestInitialize()
Expand All @@ -60,7 +60,7 @@ public void TestInitialize()

validRules = new List<SonarQubeRule>
{
new SonarQubeRule("key", "repoKey", true, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.Bug, null, null, null, null, null, null)
new SonarQubeRule("key", "repoKey", true, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.Bug)
};

anyProperties = Array.Empty<SonarQubeProperty>();
Expand Down Expand Up @@ -261,13 +261,13 @@ public void IsSupportedRule_TaintRules(string repositoryKey, bool expected)
[DataRow(SonarQubeIssueType.Vulnerability, true)]
public void IsSupportedRule_Severity(SonarQubeIssueType issueType, bool expected)
{
var rule = new SonarQubeRule("any", "any", true, SonarQubeIssueSeverity.Blocker, null, null, null, issueType, null, null, null, null, null, null);
var rule = new SonarQubeRule("any", "any", true, SonarQubeIssueSeverity.Blocker, null, null, null, issueType);

CSharpVBBindingConfigProvider.IsSupportedRule(rule).Should().Be(expected);
}

private static SonarQubeRule CreateRule(string ruleKey, string repoKey, bool isActive) =>
new SonarQubeRule(ruleKey, repoKey, isActive, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.CodeSmell, null, null, null, null, null, null);
new SonarQubeRule(ruleKey, repoKey, isActive, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.CodeSmell);

private class TestEnvironmentBuilder
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void GetVSSeverity_Invalid_Throws(SonarQubeIssueSeverity sqSeverity)
}

private static SonarQubeRule CreateRule(string ruleKey, string repoKey, bool isActive = true) =>
new SonarQubeRule(ruleKey, repoKey, isActive, SonarQubeIssueSeverity.Info, null, null, new Dictionary<string, string>(), SonarQubeIssueType.Unknown, null, null, null, null, null, null);
new SonarQubeRule(ruleKey, repoKey, isActive, SonarQubeIssueSeverity.Info, null, null, new Dictionary<string, string>(), SonarQubeIssueType.Unknown);

private string GetRuleString(string expectedKey, string expectedSeverity) =>
$"dotnet_diagnostic.{expectedKey}.severity = {expectedSeverity}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class RoslynPluginRuleKeyExtensionsTests
[DataRow("vbnet", "sonaranalyzer-vbnet")] // special case for SonarVBNet
public void TryGetPrefix(string ruleKey, string expectedPrefix)
{
var rule = new SonarQubeRule("any", ruleKey, false, SonarQubeIssueSeverity.Unknown, null, null, null, SonarQubeIssueType.Unknown, null, null, null, null, null, null);
var rule = new SonarQubeRule("any", ruleKey, false, SonarQubeIssueSeverity.Unknown, null, null, null, SonarQubeIssueType.Unknown);

rule.TryGetRoslynPluginPropertyPrefix().Should().Be(expectedPrefix);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private static SonarQubeRule CreateRuleWithValidParams(string ruleKey, string re
CreateRule(ruleKey, repoKey, ValidParams);

private static SonarQubeRule CreateRule(string ruleKey, string repoKey, IDictionary<string, string> parameters = null, string description = null, IReadOnlyList<SonarQubeDescriptionSection> descriptionSections = null, IReadOnlyList<string> educationPrinciples = null, string name = null, IReadOnlyList<string> tags = null, string htmlNote = null) =>
new SonarQubeRule(ruleKey, repoKey, isActive: false, SonarQubeIssueSeverity.Blocker, null, null, parameters, SonarQubeIssueType.Unknown, description, descriptionSections, educationPrinciples, name, tags, htmlNote);
new SonarQubeRule(ruleKey, repoKey, isActive: false, SonarQubeIssueSeverity.Blocker, null, null, parameters, SonarQubeIssueType.Unknown);

private Language ToLanguage(string sqLanguageKey) => Language.GetLanguageFromLanguageKey(sqLanguageKey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public void ConfigureSonarQube_Writes_Debug_Messages()
"Registered SonarQube.Client.Api.V8_6.GetHotspotRequest for 8.6",
"Registered SonarQube.Client.Api.V7_20.GetExclusionsRequest for 7.2",
"Registered SonarQube.Client.Api.V9_4.GetSonarLintEventStream for 9.4",
"Registered SonarQube.Client.Api.V9_5.GetRulesWithDescriptionSectionsRequest for 9.5",
"Registered SonarQube.Client.Api.V9_6.GetRulesWithEducationPrinciplesRequest for 9.6",
"Registered SonarQube.Client.Api.V9_7.SearchHotspotRequest for 9.7",
"Registered SonarQube.Client.Api.V10_2.SearchHotspotRequest for 10.2",
"Registered SonarQube.Client.Api.V10_2.GetRulesWithCCTRequest for 10.2",
Expand Down
16 changes: 8 additions & 8 deletions src/SonarQube.Client.Tests/SonarQubeService_ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task GetAllRulesAsync_FetchesActiveAndInactive()
await ConnectToSonarQube();

// One active rule
SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", @"
SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", @"
{
""total"": 1,
""p"": 1,
Expand Down Expand Up @@ -94,7 +94,7 @@ public async Task GetAllRulesAsync_FetchesActiveAndInactive()
");

// One inactive rule
SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", @"
SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", @"
{
""total"": 1,
""p"": 1,
Expand Down Expand Up @@ -135,10 +135,10 @@ public async Task GetAllRulesAsync_OnlyActiveRulesExist_AreFetched()

// One active rule, no inactive rules
var ruleJson = SingleValidRuleJson("repo1", "rule1");
SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500",
SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500",
ruleJson);

SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500",
SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500",
NoRulesJson);

var result = await service.GetAllRulesAsync("quality-profile-1", CancellationToken.None);
Expand All @@ -157,10 +157,10 @@ public async Task GetAllRulesAsync_OnlyInactiveRulesExist_AreFetched()

// One active rule, no inactive rules
var ruleJson = SingleValidRuleJson("repo1", "rule1");
SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500",
SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500",
NoRulesJson);

SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500",
SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500",
ruleJson);

var result = await service.GetAllRulesAsync("quality-profile-1", CancellationToken.None);
Expand All @@ -180,10 +180,10 @@ public async Task GetAllRulesAsync_GetInactiveFails_ExceptionIsPropogated()

// One active rule, no inactive rules
var ruleJson = SingleValidRuleJson("repo1", "rule1");
SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500",
SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500",
ruleJson);

SetupRequestWithOperation("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500",
SetupRequestWithOperation("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500",
() => { throw new InvalidOperationException("xxx"); });

// Act
Expand Down
47 changes: 5 additions & 42 deletions src/SonarQube.Client.Tests/SonarQubeService_GetRuleByKeyAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task GetRuleByKeyAsync_RuleIsFound_ReturnsRule()
await ConnectToSonarQube("10.2.0.0");

SetupRequest(
"api/rules/search?qprofile=qpKey&rule_key=csharpsquid%3AS2342&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote%2CdescriptionSections%2CeducationPrinciples%2CcleanCodeAttribute&p=1&ps=500",
"api/rules/search?qprofile=qpKey&rule_key=csharpsquid%3AS2342&f=repo%2CinternalKey%2Cparams%2Cactives%2CcleanCodeAttribute&p=1&ps=500",
@"
{
""total"": 1,
Expand All @@ -47,10 +47,6 @@ public async Task GetRuleByKeyAsync_RuleIsFound_ReturnsRule()
{
""key"": ""csharpsquid:S2342"",
""repo"": ""csharpsquid"",
""htmlDesc"": ""Html Description"",
""htmlNote"": ""HTML Note"",
""name"": ""RuleName"",
""tags"": [""tag1"",""tag2""],
""params"": [
{
""key"": ""format"",
Expand All @@ -67,32 +63,14 @@ public async Task GetRuleByKeyAsync_RuleIsFound_ReturnsRule()
],
""type"": ""CODE_SMELL"",
""cleanCodeAttributeCategory"": ""INTENTIONAL"",
""cleanCodeAttribute"": ""CLEAR"",
""cleanCodeAttribute"": ""CLEAR"",
""impacts"": [
{
""softwareQuality"": ""RELIABILITY"",
""severity"": ""MEDIUM""
}
],
""descriptionSections"" : [
{
""key"": ""key1"",
""content"": ""content1""
},
{
""key"": ""key2"",
""content"": ""content2"",
""context"":{
""displayName"":""displayName"",
""key"":""key""
}
}
],
""educationPrinciples"": [
""education principle 1"",
""education principle 2""
]
},
]
}
],
""actives"": {
""csharpsquid:S2225"": [
Expand Down Expand Up @@ -153,34 +131,19 @@ public async Task GetRuleByKeyAsync_RuleIsFound_ReturnsRule()

result.Key.Should().Be("S2342");
result.RepositoryKey.Should().Be("csharpsquid");
result.Description.Should().Be("Html Description");
result.HtmlNote.Should().Be("HTML Note");
result.Severity.Should().Be(SonarQubeIssueSeverity.Minor);
result.Name.Should().Be("RuleName");
result.Tags.Should().BeEquivalentTo(new[] { "tag1", "tag2" });
result.CleanCodeAttribute.Should().Be(SonarQubeCleanCodeAttribute.Clear);
result.SoftwareQualitySeverities.Should().BeEquivalentTo(
new Dictionary<SonarQubeSoftwareQuality, SonarQubeSoftwareQualitySeverity>
{ { SonarQubeSoftwareQuality.Reliability, SonarQubeSoftwareQualitySeverity.Medium } });

result.DescriptionSections.Count.Should().Be(2);
result.DescriptionSections[0].Key.Should().Be("key1");
result.DescriptionSections[0].HtmlContent.Should().Be("content1");
result.DescriptionSections[0].Context.Should().BeNull();

result.DescriptionSections[1].Key.Should().Be("key2");
result.DescriptionSections[1].HtmlContent.Should().Be("content2");
result.DescriptionSections[1].Context.Should().NotBeNull();
result.DescriptionSections[1].Context.Key.Should().Be("key");
result.DescriptionSections[1].Context.DisplayName.Should().Be("displayName");
}

[TestMethod]
public async Task GetRuleByKeyAsync_RuleIsNotFound_ReturnsNull()
{
await ConnectToSonarQube();

SetupRequest("api/rules/search?qprofile=qpKey&rule_key=csharpsquid%3AS2342XX&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", @"{
SetupRequest("api/rules/search?qprofile=qpKey&rule_key=csharpsquid%3AS2342XX&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", @"{
""total"": 0,
""p"": 1,
""ps"": 100,
Expand Down
Loading

0 comments on commit 0783bd0

Please sign in to comment.