|
25 | 25 | import java.util.List;
|
26 | 26 | import java.util.stream.Collectors;
|
27 | 27 | import org.junit.Test;
|
| 28 | +import org.sonar.api.SonarEdition; |
| 29 | +import org.sonar.api.SonarQubeSide; |
| 30 | +import org.sonar.api.SonarRuntime; |
| 31 | +import org.sonar.api.internal.SonarRuntimeImpl; |
28 | 32 | import org.sonar.api.rules.RuleType;
|
29 | 33 | import org.sonar.api.server.rule.RulesDefinition;
|
| 34 | +import org.sonar.api.utils.Version; |
30 | 35 | import org.sonar.python.checks.CheckList;
|
31 | 36 |
|
32 | 37 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -58,6 +63,19 @@ public void createRulesTest() throws IOException {
|
58 | 63 | }
|
59 | 64 | }
|
60 | 65 |
|
| 66 | + @Test |
| 67 | + public void owaspSecurityStandard() { |
| 68 | + RulesDefinition.Repository repository_9_3 = buildRepository(9, 3); |
| 69 | + RulesDefinition.Rule s4721_9_3 = repository_9_3.rule("S4721"); |
| 70 | + assertThat(s4721_9_3).isNotNull(); |
| 71 | + assertThat(s4721_9_3.securityStandards()).contains("owaspTop10-2021:a3"); |
| 72 | + |
| 73 | + RulesDefinition.Repository repository_9_2 = buildRepository(9, 2); |
| 74 | + RulesDefinition.Rule s4721_9_2 = repository_9_2.rule("S4721"); |
| 75 | + assertThat(s4721_9_2).isNotNull(); |
| 76 | + assertThat(s4721_9_2.securityStandards()).doesNotContain("owaspTop10-2021:a3"); |
| 77 | + } |
| 78 | + |
61 | 79 | private List<String> nonAbstractCheckFiles() throws IOException {
|
62 | 80 | return Files.walk(new File("../python-checks/src/main/java/org/sonar/python/checks").toPath())
|
63 | 81 | .filter(Files::isRegularFile)
|
@@ -98,7 +116,12 @@ public void hotspotRules() {
|
98 | 116 | }
|
99 | 117 |
|
100 | 118 | private static RulesDefinition.Repository buildRepository() {
|
101 |
| - PythonRuleRepository ruleRepository = new PythonRuleRepository(); |
| 119 | + return buildRepository(9, 3); |
| 120 | + } |
| 121 | + |
| 122 | + private static RulesDefinition.Repository buildRepository(int majorVersion, int minorVersion) { |
| 123 | + SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(majorVersion, minorVersion), SonarQubeSide.SERVER, SonarEdition.DEVELOPER); |
| 124 | + PythonRuleRepository ruleRepository = new PythonRuleRepository(sonarRuntime); |
102 | 125 | RulesDefinition.Context context = new RulesDefinition.Context();
|
103 | 126 | ruleRepository.define(context);
|
104 | 127 | return context.repository(CheckList.REPOSITORY_KEY);
|
|
0 commit comments