diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/rules/RuleDetailsAdapter.java b/backend/core/src/main/java/org/sonarsource/sonarlint/core/rules/RuleDetailsAdapter.java index b207a3e17a..7cd587ffd5 100644 --- a/backend/core/src/main/java/org/sonarsource/sonarlint/core/rules/RuleDetailsAdapter.java +++ b/backend/core/src/main/java/org/sonarsource/sonarlint/core/rules/RuleDetailsAdapter.java @@ -109,8 +109,8 @@ private static RuleMonolithicDescriptionDto transformMonolithicDescription(RuleD htmlSnippets.addAll(ruleDetails.getDescriptionSectionsByKey().get("default").stream().map(RuleDetails.DescriptionSection::getHtmlContent).collect(Collectors.toList())); } else { htmlSnippets.add(ruleDetails.getHtmlDescription()); - htmlSnippets.add(ruleDetails.getExtendedDescription()); } + htmlSnippets.add(ruleDetails.getExtendedDescription()); htmlSnippets.add(getCleanCodePrinciplesContent(ruleDetails.getCleanCodePrincipleKeys())); return new RuleMonolithicDescriptionDto(concat(htmlSnippets)); } diff --git a/backend/server-api/src/test/java/org/sonarsource/sonarlint/core/serverapi/rules/RulesApiTests.java b/backend/server-api/src/test/java/org/sonarsource/sonarlint/core/serverapi/rules/RulesApiTests.java index 155dba7a7d..c5e39a5d93 100644 --- a/backend/server-api/src/test/java/org/sonarsource/sonarlint/core/serverapi/rules/RulesApiTests.java +++ b/backend/server-api/src/test/java/org/sonarsource/sonarlint/core/serverapi/rules/RulesApiTests.java @@ -65,8 +65,13 @@ void should_get_rule() { .setSeverity("MINOR") .setType(Common.RuleType.VULNERABILITY) .setLang(SonarLanguage.PYTHON.getSonarLanguageKey()) - .setHtmlDesc("htmlDesc") .setHtmlNote("htmlNote") + .setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder() + .addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder() + .setKey("default") + .setContent("desc") + .build()) + .build()) .setCleanCodeAttribute(Common.CleanCodeAttribute.COMPLETE) .setImpacts(Rules.Rule.Impacts.newBuilder().addImpacts(Common.Impact.newBuilder().setSeverity(Common.ImpactSeverity.HIGH).setSoftwareQuality(Common.SoftwareQuality.MAINTAINABILITY).build()).build()) .build()) @@ -76,8 +81,9 @@ void should_get_rule() { var rule = rulesApi.getRule("java:S1234", new SonarLintCancelMonitor()).get(); - assertThat(rule).extracting("name", "severity", "type", "language", "htmlDesc", "htmlNote", "cleanCodeAttribute", "impacts") - .contains("name", IssueSeverity.MINOR, RuleType.VULNERABILITY, SonarLanguage.PYTHON, "htmlDesc", "htmlNote", CleanCodeAttribute.COMPLETE, Map.of(SoftwareQuality.MAINTAINABILITY, ImpactSeverity.HIGH)); + assertThat(rule).extracting("name", "severity", "type", "language", "htmlNote", "cleanCodeAttribute", "impacts") + .contains("name", IssueSeverity.MINOR, RuleType.VULNERABILITY, SonarLanguage.PYTHON, "htmlNote", CleanCodeAttribute.COMPLETE, Map.of(SoftwareQuality.MAINTAINABILITY, ImpactSeverity.HIGH)); + assertThat(rule.getDescriptionSections().get(0).getHtmlContent()).isEqualTo("desc"); } @Test @@ -89,7 +95,6 @@ void should_get_rule_with_description_sections() { .setSeverity("MINOR") .setType(Common.RuleType.VULNERABILITY) .setLang(SonarLanguage.PYTHON.getSonarLanguageKey()) - .setHtmlDesc("htmlDesc") .setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder() .addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder().setKey("sectionKey").setContent("htmlContent").build()) .addDescriptionSections( @@ -106,8 +111,8 @@ void should_get_rule_with_description_sections() { var rule = rulesApi.getRule("java:S1234", new SonarLintCancelMonitor()).get(); - assertThat(rule).extracting("name", "severity", "type", "language", "htmlDesc", "htmlNote", "cleanCodeAttribute", "impacts") - .contains("name", IssueSeverity.MINOR, RuleType.VULNERABILITY, SonarLanguage.PYTHON, "htmlDesc", "htmlNote", CleanCodeAttribute.CONVENTIONAL, Map.of(SoftwareQuality.RELIABILITY, ImpactSeverity.LOW)); + assertThat(rule).extracting("name", "severity", "type", "language","htmlNote", "cleanCodeAttribute", "impacts") + .contains("name", IssueSeverity.MINOR, RuleType.VULNERABILITY, SonarLanguage.PYTHON, "htmlNote", CleanCodeAttribute.CONVENTIONAL, Map.of(SoftwareQuality.RELIABILITY, ImpactSeverity.LOW)); var sections = rule.getDescriptionSections(); assertThat(sections).hasSize(2); @@ -131,8 +136,13 @@ void should_get_rule_from_organization() { .setSeverity("MAJOR") .setType(Common.RuleType.VULNERABILITY) .setLang(SonarLanguage.PYTHON.getSonarLanguageKey()) - .setHtmlDesc("htmlDesc") .setHtmlNote("htmlNote") + .setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder() + .addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder() + .setKey("default") + .setContent("desc") + .build()) + .build()) .build()) .build()); @@ -140,8 +150,9 @@ void should_get_rule_from_organization() { var rule = rulesApi.getRule("java:S1234", new SonarLintCancelMonitor()).get(); - assertThat(rule).extracting("name", "severity", "type", "language", "htmlDesc", "htmlNote") - .contains("name", IssueSeverity.MAJOR, RuleType.VULNERABILITY, SonarLanguage.PYTHON, "htmlDesc", "htmlNote"); + assertThat(rule).extracting("name", "severity", "type", "language", "htmlNote") + .contains("name", IssueSeverity.MAJOR, RuleType.VULNERABILITY, SonarLanguage.PYTHON, "htmlNote"); + assertThat(rule.getDescriptionSections().get(0).getHtmlContent()).isEqualTo("desc"); } @Test diff --git a/medium-tests/src/test/java/mediumtest/EffectiveRulesMediumTests.java b/medium-tests/src/test/java/mediumtest/EffectiveRulesMediumTests.java index 0c268a4115..a21eb99db3 100644 --- a/medium-tests/src/test/java/mediumtest/EffectiveRulesMediumTests.java +++ b/medium-tests/src/test/java/mediumtest/EffectiveRulesMediumTests.java @@ -164,7 +164,7 @@ void it_should_merge_rule_from_storage_and_server_when_project_is_bound() { .withConnectedEmbeddedPluginAndEnabledLanguage(TestPlugin.PYTHON) .build(); mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=python:S139", Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc("desc").setHtmlNote("extendedDesc").build()) + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc").build()) .build()); var details = getEffectiveRuleDetails("scopeId", "python:S139"); @@ -188,7 +188,7 @@ void it_should_merge_rule_from_storage_and_server_when_parent_project_is_bound() .withConnectedEmbeddedPluginAndEnabledLanguage(TestPlugin.PYTHON) .build(); mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=python:S139", Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc("desc").setHtmlNote("extendedDesc").build()) + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc").build()) .build()); var details = getEffectiveRuleDetails("childScopeId", "python:S139"); @@ -213,7 +213,6 @@ void it_return_single_section_from_server_when_project_is_bound() { .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") @@ -278,7 +277,14 @@ void it_should_merge_template_rule_from_storage_and_server_when_project_is_bound .withConnectedEmbeddedPluginAndEnabledLanguage(TestPlugin.PYTHON) .build(); mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=python:custom", Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc("desc").setHtmlNote("extendedDesc").build()) + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc") + .setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder() + .addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder() + .setKey("default") + .setContent("desc") + .build()) + .build()) + .build()) .build()); var details = getEffectiveRuleDetails("scopeId", "python:custom"); @@ -300,7 +306,14 @@ void it_should_merge_rule_from_storage_and_server_rule_when_rule_is_unknown_in_l .withEnabledLanguageInStandaloneMode(PYTHON) .build(); mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=python:S139", Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc("desc").setHtmlNote("extendedDesc").build()) + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc") + .setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder() + .addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder() + .setKey("default") + .setContent("desc") + .build()) + .build()) + .build()) .build()); var details = getEffectiveRuleDetails("scopeId", "python:S139"); @@ -410,7 +423,7 @@ void it_should_add_a_more_info_tab_if_no_resource_section_exists_and_extended_de .withEnabledLanguageInStandaloneMode(PYTHON) .build(); mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=python:S139", Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc("desc").setHtmlNote("extendedDesc") + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc") .setEducationPrinciples(Rules.Rule.EducationPrinciples.newBuilder().addEducationPrinciples("never_trust_user_input").build()) .setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder() .addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder() @@ -486,7 +499,7 @@ private void prepareForRuleDescriptionSectionsAndContext() { .withEnabledLanguageInStandaloneMode(PYTHON) .build(); mockWebServerExtension.addProtobufResponse("/api/rules/show.protobuf?key=python:S139", Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc("desc").setHtmlNote("extendedDesc") + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc") .setEducationPrinciples(Rules.Rule.EducationPrinciples.newBuilder().addEducationPrinciples("never_trust_user_input").build()) .setDescriptionSections(Rules.Rule.DescriptionSections.newBuilder() .addDescriptionSections(Rules.Rule.DescriptionSection.newBuilder() diff --git a/medium-tests/src/test/java/mediumtest/http/AuthenticationMediumTests.java b/medium-tests/src/test/java/mediumtest/http/AuthenticationMediumTests.java index a5fe22aa64..830bbc2c9f 100644 --- a/medium-tests/src/test/java/mediumtest/http/AuthenticationMediumTests.java +++ b/medium-tests/src/test/java/mediumtest/http/AuthenticationMediumTests.java @@ -28,10 +28,10 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import org.sonarsource.sonarlint.core.commons.api.SonarLanguage; import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcServer; import org.sonarsource.sonarlint.core.rpc.protocol.backend.rules.EffectiveRuleDetailsDto; import org.sonarsource.sonarlint.core.rpc.protocol.backend.rules.GetEffectiveRuleDetailsParams; -import org.sonarsource.sonarlint.core.commons.api.SonarLanguage; import org.sonarsource.sonarlint.core.serverapi.proto.sonarqube.ws.Common; import org.sonarsource.sonarlint.core.serverapi.proto.sonarqube.ws.Rules; @@ -79,8 +79,7 @@ void it_should_authenticate_preemptively_on_sonarqube_with_login_password() { "\"UP\"}"))); sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139") .willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc( - "desc").setHtmlNote("extendedDesc from server").build()) + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build()) .build())))); var details = getEffectiveRuleDetails("scopeId", "python:S139"); @@ -105,8 +104,7 @@ void it_should_authenticate_preemptively_on_sonarqube_9_9_with_token_and_basic_s .build(fakeClient); sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139") .willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc( - "desc").setHtmlNote("extendedDesc from server").build()) + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build()) .build())))); sonarqubeMock.stubFor(get("/api/system/status") .willReturn(aResponse().withStatus(200).withBody("{\"id\": \"20160308094653\",\"version\": \"9.9\",\"status\": " + @@ -134,8 +132,7 @@ void it_should_authenticate_preemptively_on_sonarqube_10_0_with_token_and_bearer .build(fakeClient); sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139") .willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc( - "desc").setHtmlNote("extendedDesc from server").build()) + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build()) .build())))); sonarqubeMock.stubFor(get("/api/system/status") .willReturn(aResponse().withStatus(200).withBody("{\"id\": \"20160308094653\",\"version\": \"10.0\",\"status\": " + diff --git a/medium-tests/src/test/java/mediumtest/http/ProxyMediumTests.java b/medium-tests/src/test/java/mediumtest/http/ProxyMediumTests.java index 91e186ddf4..8114c6f4bb 100644 --- a/medium-tests/src/test/java/mediumtest/http/ProxyMediumTests.java +++ b/medium-tests/src/test/java/mediumtest/http/ProxyMediumTests.java @@ -123,8 +123,7 @@ void it_should_honor_http_proxy_settings() { .build(fakeClient); sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139") .willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc( - "desc").setHtmlNote("extendedDesc from server").build()) + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build()) .build())))); var details = getEffectiveRuleDetails("scopeId", "python:S139"); @@ -150,8 +149,7 @@ void it_should_honor_http_direct_proxy_settings() { .build(fakeClient); sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139") .willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc( - "desc").setHtmlNote("extendedDesc from server").build()) + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build()) .build())))); var details = getEffectiveRuleDetails("scopeId", "python:S139"); @@ -182,8 +180,7 @@ void it_should_honor_http_proxy_authentication() { .build(fakeClient); sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139") .willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc( - "desc").setHtmlNote("extendedDesc from server").build()) + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build()) .build())))); var details = getEffectiveRuleDetails("scopeId", "python:S139"); @@ -213,8 +210,7 @@ void it_should_honor_http_proxy_authentication_with_null_password() { .build(fakeClient); sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139") .willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc( - "desc").setHtmlNote("extendedDesc from server").build()) + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build()) .build())))); var details = getEffectiveRuleDetails("scopeId", "python:S139"); @@ -244,8 +240,7 @@ void it_should_fail_if_proxy_port_is_smaller_than_valid_range() { .build(fakeClient); sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139") .willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc( - "desc").setHtmlNote("extendedDesc from server").build()) + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build()) .build())))); var details = getEffectiveRuleDetails("scopeId", "python:S139"); @@ -280,8 +275,7 @@ void it_should_fail_if_proxy_port_is_higher_than_valid_range() { .build(fakeClient); sonarqubeMock.stubFor(get("/api/rules/show.protobuf?key=python:S139") .willReturn(aResponse().withStatus(200).withResponseBody(protobufBody(Rules.ShowResponse.newBuilder() - .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlDesc( - "desc").setHtmlNote("extendedDesc from server").build()) + .setRule(Rules.Rule.newBuilder().setName("newName").setSeverity("INFO").setType(Common.RuleType.BUG).setLang("py").setHtmlNote("extendedDesc from server").build()) .build())))); var details = getEffectiveRuleDetails("scopeId", "python:S139");