Skip to content

Commit

Permalink
SLCORE-443 Treat a single "default" section as monolithic
Browse files Browse the repository at this point in the history
  • Loading branch information
jblievremont authored Jan 27, 2023
1 parent 7928f84 commit b0d6312
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

public class ActiveRuleDetails {

public static final String DEFAULT_SECTION = "default";

public static ActiveRuleDetails from(SonarLintRuleDefinition ruleDefinition) {
return new ActiveRuleDetails(
ruleDefinition.getKey(),
Expand Down Expand Up @@ -129,7 +131,11 @@ public String getHtmlDescription() {
}

public boolean hasMonolithicDescription() {
return descriptionSectionsByKey.isEmpty();
return descriptionSectionsByKey.isEmpty() || hasOnlyDefaultSection();
}

private boolean hasOnlyDefaultSection() {
return descriptionSectionsByKey.size() == 1 && descriptionSectionsByKey.containsKey(DEFAULT_SECTION);
}

public Map<String, List<DescriptionSection>> getDescriptionSectionsByKey() {
Expand Down
35 changes: 35 additions & 0 deletions core/src/test/java/mediumtest/ActiveRulesMediumTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,41 @@ void it_should_merge_rule_from_storage_and_server_when_parent_project_is_bound()
assertThat(details.getParams()).isEmpty();
}

@Test
void it_return_single_section_from_server_when_project_is_bound() throws ExecutionException, InterruptedException {
var name = "name";
var desc = "desc";
StorageFixture.newStorage("connectionId")
.withProject("projectKey",
projectStorage -> projectStorage.withRuleSet(Language.JS.getLanguageKey(),
ruleSet -> ruleSet.withActiveRule("jssecurity:S5696", "BLOCKER")))
.create(storageDir);
backend = newBackend()
.withSonarQubeConnection("connectionId", mockWebServerExtension.endpointParams().getBaseUrl())
.withBoundConfigScope("scopeId", "connectionId", "projectKey")
.withStorageRoot(storageDir.resolve("storage"))
.build();
mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=jssecurity:S5696", Rules.ShowResponse.newBuilder()
.setRule(Rules.Rule.newBuilder().setName(name).setSeverity("BLOCKER").setType(Common.RuleType.VULNERABILITY).setLang("js")
.setHtmlDesc(desc)
.setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder()
.addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder()
.setKey("default")
.setContent(desc)
.build())
.build())
.build())
.build());

var activeRuleDetailsResponse = backend.getActiveRulesService().getActiveRuleDetails(new GetActiveRuleDetailsParams("scopeId", "jssecurity:S5696")).get();

var details = activeRuleDetailsResponse.details();
assertThat(details)
.extracting("key", "name", "type", "language", "severity", "description.left.htmlContent")
.containsExactly("jssecurity:S5696", name, RuleType.VULNERABILITY, Language.JS, IssueSeverity.BLOCKER, desc);
assertThat(details.getParams()).isEmpty();
}

@Test
void it_should_fail_to_merge_rule_from_storage_and_server_when_connection_is_unknown() {
StorageFixture.newStorage("connectionId")
Expand Down

0 comments on commit b0d6312

Please sign in to comment.