You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XooRulesDefinitionTest.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.xoo.rule;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23. import org.sonar.api.SonarEdition;
  24. import org.sonar.api.SonarQubeSide;
  25. import org.sonar.api.impl.server.RulesDefinitionContext;
  26. import org.sonar.api.internal.SonarRuntimeImpl;
  27. import org.sonar.api.server.debt.DebtRemediationFunction;
  28. import org.sonar.api.server.rule.RulesDefinition;
  29. import org.sonar.api.utils.Version;
  30. import static org.assertj.core.api.Assertions.assertThat;
  31. public class XooRulesDefinitionTest {
  32. private XooRulesDefinition def = new XooRulesDefinition(SonarRuntimeImpl.forSonarQube(Version.create(9, 3), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY));
  33. private RulesDefinition.Context context = new RulesDefinitionContext();
  34. @Before
  35. public void setUp() {
  36. def.define(context);
  37. }
  38. @Test
  39. public void define_xoo_rules() {
  40. RulesDefinition.Repository repo = getRepository();
  41. RulesDefinition.Rule rule = repo.rule(OneIssuePerLineSensor.RULE_KEY);
  42. assertThat(rule.name()).isNotEmpty();
  43. assertThat(rule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
  44. assertThat(rule.debtRemediationFunction().gapMultiplier()).isEqualTo("1min");
  45. assertThat(rule.debtRemediationFunction().baseEffort()).isNull();
  46. assertThat(rule.gapDescription()).isNotEmpty();
  47. }
  48. @Test
  49. public void define_xoo_hotspot_rule() {
  50. RulesDefinition.Repository repo = getRepository();
  51. RulesDefinition.Rule rule = repo.rule(HotspotSensor.RULE_KEY);
  52. assertThat(rule.name()).isNotEmpty();
  53. assertThat(rule.securityStandards())
  54. .isNotEmpty()
  55. .containsExactlyInAnyOrder("cwe:1", "cwe:89", "cwe:123", "cwe:863", "owaspTop10:a1", "owaspTop10:a3",
  56. "owaspTop10-2021:a3", "owaspTop10-2021:a2");
  57. }
  58. @Test
  59. public void define_xoo_vulnerability_rule() {
  60. RulesDefinition.Repository repo = getRepository();
  61. RulesDefinition.Rule rule = repo.rule(OneVulnerabilityIssuePerModuleSensor.RULE_KEY);
  62. assertThat(rule.name()).isNotEmpty();
  63. assertThat(rule.securityStandards())
  64. .isNotEmpty()
  65. .containsExactlyInAnyOrder("cwe:250", "cwe:546", "cwe:564", "cwe:943", "owaspTop10-2021:a6", "owaspTop10-2021:a9",
  66. "owaspTop10:a10", "owaspTop10:a9");
  67. }
  68. @Test
  69. public void define_xooExternal_rules() {
  70. RulesDefinition.Repository repo = context.repository("external_XooEngine");
  71. assertThat(repo).isNotNull();
  72. assertThat(repo.name()).isEqualTo("XooEngine");
  73. assertThat(repo.language()).isEqualTo("xoo");
  74. assertThat(repo.rules()).hasSize(1);
  75. }
  76. @Test
  77. public void define_xoo2_rules() {
  78. RulesDefinition.Repository repo = context.repository("xoo2");
  79. assertThat(repo).isNotNull();
  80. assertThat(repo.name()).isEqualTo("Xoo2");
  81. assertThat(repo.language()).isEqualTo("xoo2");
  82. assertThat(repo.rules()).hasSize(2);
  83. }
  84. private RulesDefinition.Repository getRepository() {
  85. RulesDefinition.Repository repo = context.repository("xoo");
  86. assertThat(repo).isNotNull();
  87. assertThat(repo.name()).isEqualTo("Xoo");
  88. assertThat(repo.language()).isEqualTo("xoo");
  89. assertThat(repo.rules()).hasSize(23);
  90. return repo;
  91. }
  92. }