]> source.dussan.org Git - sonarqube.git/commitdiff
Comply key validation of sonar-plugin-api
authorZipeng WU <zipeng.wu@sonarsource.com>
Tue, 23 Aug 2022 10:00:38 +0000 (12:00 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 23 Aug 2022 20:03:04 +0000 (20:03 +0000)
plugins/sonar-education-plugin/src/main/java/org/sonar/education/EducationRulesDefinition.java
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java
server/sonar-webserver-core/src/test/java/org/sonar/server/rule/AdvancedRuleDescriptionSectionsGeneratorTest.java
server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RuleDescriptionSectionsGeneratorsTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/AddTagsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java

index 5c8a6512ceb7c9d09e4d8d9675ec22f5514fa49c..8b3c03b28a402a3c2ddb34554f7c12f8d8be2cc9 100644 (file)
@@ -45,7 +45,7 @@ public class EducationRulesDefinition implements RulesDefinition {
     RESOURCES_SECTION_KEY, HOW_TO_FIX_SECTION_KEY};
   private static final String IGNORED_FAKE_SECTION = "fake_section_to_be_ignored";
 
-  public static final String[] CONTEXTS = {"spring", "hibernate", "apache-commons", "vaadin", "mybatis"};
+  public static final String[] CONTEXTS = {"spring", "hibernate", "apache_commons", "vaadin", "mybatis"};
 
   private static final String HTML_LOREM_IPSUM = "<a href=\"https://google.com\">Lorem</a> ipsum dolor sit amet, consectetur adipiscing " +
     "elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco " +
index 964aceba41109df789d14e715b1546eef275ca3e..399e70c9d704adf24d80085eedf0476362aa8eae 100644 (file)
@@ -48,7 +48,7 @@ import static org.sonar.api.server.rule.RulesDefinition.OwaspTop10Version.Y2021;
  */
 public class XooRulesDefinition implements RulesDefinition {
 
-  public static final String[] AVAILABLE_CONTEXTS = {"JavaScript", "JQuery", "Express.js", "React", "Axios"};
+  public static final String[] AVAILABLE_CONTEXTS = {"javascript", "jquery", "express_js", "react", "axios"};
 
   public static final String XOO_REPOSITORY = "xoo";
   public static final String XOO2_REPOSITORY = "xoo2";
@@ -95,7 +95,7 @@ public class XooRulesDefinition implements RulesDefinition {
 
     NewRule hasTag = repo.createRule(HasTagSensor.RULE_KEY).setName("Has Tag")
       .setActivatedByDefault(true)
-      .addDescriptionSection(howToFixSectionWithContext("singleContext"));
+      .addDescriptionSection(howToFixSectionWithContext("single_context"));
     addDescriptionSectionsWithoutContexts(hasTag, "Search for a given tag in Xoo files");
 
     hasTag
@@ -262,7 +262,7 @@ public class XooRulesDefinition implements RulesDefinition {
       .setName("Find security hotspots, how_to_fix with single context")
       .setType(RuleType.SECURITY_HOTSPOT)
       .setActivatedByDefault(false)
-      .addDescriptionSection(howToFixSectionWithContext("singleContext"));
+      .addDescriptionSection(howToFixSectionWithContext("single_context"));
     addDescriptionSectionsWithoutContexts(hotspotWithSingleContext, "Search for Security Hotspots with single context in Xoo files");
 
     repo.done();
index b2c4425606ac05e419442cf8d6fa1ade8b7dbed7..f007aff95dd4407e880d18f9a5bbd20712d4a543 100644 (file)
@@ -52,14 +52,14 @@ public class AdvancedRuleDescriptionSectionsGeneratorTest {
   private static final RuleDescriptionSection SECTION_1 = new RuleDescriptionSectionBuilder().sectionKey(HOW_TO_FIX_SECTION_KEY).htmlContent(HTML_CONTENT).build();
   private static final RuleDescriptionSection SECTION_2 = new RuleDescriptionSectionBuilder().sectionKey(ROOT_CAUSE_SECTION_KEY).htmlContent(HTML_CONTENT + "2").build();
 
-  private static final Context CONTEXT_1 = new Context("CTX_1", "ctx 1 display name");
+  private static final Context CONTEXT_1 = new Context("ctx_1", "ctx 1 display name");
   private static final RuleDescriptionSection SECTION_3_WITH_CTX_1 = new RuleDescriptionSectionBuilder()
     .sectionKey(RESOURCES_SECTION_KEY)
     .htmlContent(HTML_CONTENT)
     .context(CONTEXT_1)
     .build();
 
-  private static final Context CONTEXT_2 = new Context("CTX_2", "ctx 2 display name");
+  private static final Context CONTEXT_2 = new Context("ctx_2", "ctx 2 display name");
   private static final RuleDescriptionSection SECTION_3_WITH_CTX_2 = new RuleDescriptionSectionBuilder()
     .sectionKey(RESOURCES_SECTION_KEY)
     .htmlContent(HTML_CONTENT + "2")
index 58e48f4d2cc8565266c14c3f4bc0f33423f1f4cb..2204e065f670e9348bea9f71d7202ba4567fe84a 100644 (file)
@@ -745,10 +745,10 @@ public class RegisterRulesTest {
   public void update_several_rule_descriptions() {
     system.setNow(DATE1.getTime());
 
-    RuleDescriptionSection section1context1 = createRuleDescriptionSection(HOW_TO_FIX_SECTION_KEY, "section1 ctx1 content", "CTX_1");
-    RuleDescriptionSection section1context2 = createRuleDescriptionSection(HOW_TO_FIX_SECTION_KEY, "section1 ctx2 content", "CTX_2");
-    RuleDescriptionSection section2context1 = createRuleDescriptionSection(RESOURCES_SECTION_KEY, "section2 content", "CTX_1");
-    RuleDescriptionSection section2context2 = createRuleDescriptionSection(RESOURCES_SECTION_KEY,"section2 ctx2 content", "CTX_2");
+    RuleDescriptionSection section1context1 = createRuleDescriptionSection(HOW_TO_FIX_SECTION_KEY, "section1 ctx1 content", "ctx_1");
+    RuleDescriptionSection section1context2 = createRuleDescriptionSection(HOW_TO_FIX_SECTION_KEY, "section1 ctx2 content", "ctx_2");
+    RuleDescriptionSection section2context1 = createRuleDescriptionSection(RESOURCES_SECTION_KEY, "section2 content", "ctx_1");
+    RuleDescriptionSection section2context2 = createRuleDescriptionSection(RESOURCES_SECTION_KEY,"section2 ctx2 content", "ctx_2");
     RuleDescriptionSection section3noContext = createRuleDescriptionSection(ASSESS_THE_PROBLEM_SECTION_KEY, "section3 content", null);
     RuleDescriptionSection section4noContext = createRuleDescriptionSection(ROOT_CAUSE_SECTION_KEY, "section4 content", null);
     execute(context -> {
@@ -765,10 +765,10 @@ public class RegisterRulesTest {
       repo.done();
     });
 
-    RuleDescriptionSection section1context2updated = createRuleDescriptionSection(HOW_TO_FIX_SECTION_KEY, "section1 ctx2 updated content", "CTX_2");
+    RuleDescriptionSection section1context2updated = createRuleDescriptionSection(HOW_TO_FIX_SECTION_KEY, "section1 ctx2 updated content", "ctx_2");
     RuleDescriptionSection section2updatedWithoutContext = createRuleDescriptionSection(RESOURCES_SECTION_KEY, section2context1.getHtmlContent(), null);
-    RuleDescriptionSection section4updatedWithContext1 = createRuleDescriptionSection(ROOT_CAUSE_SECTION_KEY, section4noContext.getHtmlContent(), "CTX_1");
-    RuleDescriptionSection section4updatedWithContext2 = createRuleDescriptionSection(ROOT_CAUSE_SECTION_KEY, section4noContext.getHtmlContent(), "CTX_2");
+    RuleDescriptionSection section4updatedWithContext1 = createRuleDescriptionSection(ROOT_CAUSE_SECTION_KEY, section4noContext.getHtmlContent(), "ctx_1");
+    RuleDescriptionSection section4updatedWithContext2 = createRuleDescriptionSection(ROOT_CAUSE_SECTION_KEY, section4noContext.getHtmlContent(), "ctx_2");
     system.setNow(DATE2.getTime());
     execute(context -> {
       NewRepository repo = context.createRepository("fake", "java");
index 03ad1283b712b99ea63607bf34ff9b0e24d3b39f..bd595f39e871c5d7196c82b6fc99519d0473e174 100644 (file)
@@ -50,8 +50,8 @@ import static org.sonar.server.rule.RuleDescriptionGeneratorTestData.aRuleOfType
 @RunWith(Parameterized.class)
 public class RuleDescriptionSectionsGeneratorsTest {
 
-  private static final String KEY_1 = "KEY";
-  private static final String KEY_2 = "KEY_2";
+  private static final String KEY_1 = "key";
+  private static final String KEY_2 = "key_2";
   private static final String UUID_1 = "uuid1";
   private static final String UUID_2 = "uuid2";
 
index e716d9b2e8ae5ff41ae631ab4edceabfdf2f7f0f..6436433769eb174cbac3dfbf9ab33f435cf0db2b 100644 (file)
@@ -67,6 +67,6 @@ public class AddTagsActionTest {
       underTest.execute(properties, context);
     })
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Entry 'th ag' is invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'");
+      .hasMessage("Entry 'th ag' is invalid. For Rule tags the entry has to match the regexp ^[a-z0-9\\+#\\-\\.]+$");
   }
 }
index 6c35531d6e4be023554449f1df530f6458e19db9..cf5491e2c1c9d77e2c379adc259e700896290f9f 100644 (file)
@@ -67,6 +67,6 @@ public class RemoveTagsActionTest {
       action.execute(properties, context);
     })
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Entry 'th ag' is invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'");
+      .hasMessage("Entry 'th ag' is invalid. For Rule tags the entry has to match the regexp ^[a-z0-9\\+#\\-\\.]+$");
   }
 }
index 9dfd0f41558e9e2f9bbb9ec9297fcdb01877f23b..763c39eb857eda5f6aca1fedc0816b38f6055b9e 100644 (file)
@@ -175,7 +175,7 @@ public class SetTagsActionTest {
 
     assertThatThrownBy(() -> call(issueDto.getKey(), "pol op"))
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Entries 'pol op' are invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'");
+      .hasMessage("Entries 'pol op' are invalid. For Rule tags the entry has to match the regexp ^[a-z0-9\\+#\\-\\.]+$");
   }
 
   @Test