Skip to content

Commit 1f517b3

Browse files
committed
PLUGINAPI-142 Modify the Plugin API to support OWASP Mobile Top 10 2024 issues
1 parent 44df6a8 commit 1f517b3

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Deprecate `org.sonar.api.issue.DefaultTransitions`
55
* Deprecate `org.sonar.api.web.UserRole`
66
* Remove deprecated extension points ~~`org.sonar.api.profiles.ProfileExporter`~~ and ~~`org.sonar.api.profiles.ProfileImporter`~~.
7+
* Introduce new security standards for OWASP Mobile 2024
78

89
## 11.3
910
* Introduce `org.sonar.api.batch.sensor.SensorContext.addAnalysisData`.

plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,34 @@ public String prefix() {
276276
}
277277
}
278278

279+
enum OwaspMobileTop10Version {
280+
Y2024("2024", "owaspMobileTop10-2024");
281+
282+
private final String label;
283+
private final String prefix;
284+
285+
OwaspMobileTop10Version(String label, String prefix) {
286+
this.label = label;
287+
this.prefix = prefix;
288+
}
289+
290+
public String label() {
291+
return label;
292+
}
293+
294+
public String prefix() {
295+
return prefix;
296+
}
297+
}
298+
279299
enum OwaspTop10 {
280300
A1, A2, A3, A4, A5, A6, A7, A8, A9, A10
281301
}
282302

303+
enum OwaspMobileTop10 {
304+
M1, M2, M3, M4, M5, M6, M7, M8, M9, M10
305+
}
306+
283307
enum PciDssVersion {
284308
V3_2("3.2", "pciDss-3.2"), V4_0("4.0", "pciDss-4.0");
285309

@@ -461,6 +485,7 @@ abstract class NewRule {
461485
/**
462486
* The Clean Code Attribute of the rule.
463487
* Providing it is optional for now, but will become mandatory in the future.
488+
*
464489
* @since 10.1
465490
*/
466491
public abstract NewRule setCleanCodeAttribute(CleanCodeAttribute attribute);
@@ -470,7 +495,8 @@ abstract class NewRule {
470495
* For backward compatibility, one of the old method {@link #setHtmlDescription(String)} or {@link #setHtmlDescription(URL)} still
471496
* need to be called on top of that one.
472497
* Each section must have a different section key when they are non-contextual.
473-
* As soon as one section is contextual for a section key, all sections with that key must be contextual. The pair "section key, context key" pair must still be unique.
498+
* As soon as one section is contextual for a section key, all sections with that key must be contextual. The pair "section key,
499+
* context key" pair must still be unique.
474500
* If several sections provide contexts, the provided context keys must be the same between sections.
475501
*
476502
* @since 9.6
@@ -484,7 +510,8 @@ abstract class NewRule {
484510
public abstract NewRule setHtmlDescription(@Nullable String s);
485511

486512
/**
487-
* Load description from a file available in classpath. Example : <code>setHtmlDescription(getClass().getResource("/myrepo/Rule1234.html")</code>
513+
* Load description from a file available in classpath. Example : <code>setHtmlDescription(getClass().getResource("/myrepo/Rule1234
514+
* .html")</code>
488515
*/
489516
public abstract NewRule setHtmlDescription(@Nullable URL classpathUrl);
490517

@@ -498,7 +525,8 @@ abstract class NewRule {
498525
public abstract NewRule setMarkdownDescription(@Nullable String s);
499526

500527
/**
501-
* Load description from a file available in classpath. Example : {@code setMarkdownDescription(getClass().getResource("/myrepo/Rule1234.md")}
528+
* Load description from a file available in classpath. Example : {@code setMarkdownDescription(getClass().getResource
529+
* ("/myrepo/Rule1234.md")}
502530
*
503531
* @deprecated since 9.6. Use {@link #addDescriptionSection(RuleDescriptionSection)} instead
504532
*/
@@ -565,6 +593,11 @@ abstract class NewRule {
565593
*/
566594
public abstract NewRule addOwaspTop10(OwaspTop10Version version, OwaspTop10... standards);
567595

596+
/**
597+
* @since 11.4
598+
*/
599+
public abstract NewRule addOwaspMobileTop10(OwaspMobileTop10Version owaspMobileTop10Version, OwaspMobileTop10... standards);
600+
568601
/**
569602
* @since 9.5
570603
*/

plugin-api/src/main/java/org/sonar/api/server/rule/internal/DefaultNewRule.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import org.sonar.api.server.rule.RuleDescriptionSection;
4949
import org.sonar.api.server.rule.RuleTagFormat;
5050
import org.sonar.api.server.rule.RulesDefinition;
51+
import org.sonar.api.server.rule.RulesDefinition.OwaspMobileTop10;
52+
import org.sonar.api.server.rule.RulesDefinition.OwaspMobileTop10Version;
5153
import org.sonar.api.server.rule.RulesDefinition.OwaspTop10;
5254
import org.sonar.api.server.rule.RulesDefinition.OwaspTop10Version;
5355
import org.sonar.api.server.rule.RulesDefinition.PciDssVersion;
@@ -335,6 +337,17 @@ public DefaultNewRule addOwaspTop10(OwaspTop10Version owaspTop10Version, OwaspTo
335337
return this;
336338
}
337339

340+
@Override
341+
public DefaultNewRule addOwaspMobileTop10(OwaspMobileTop10Version owaspMobileTop10Version, OwaspMobileTop10... standards) {
342+
requireNonNull(owaspMobileTop10Version, "Owasp mobile version must not be null");
343+
344+
for (OwaspMobileTop10 owaspMobileTop10 : standards) {
345+
String standard = owaspMobileTop10Version.prefix() + ":" + owaspMobileTop10.name().toLowerCase(Locale.ENGLISH);
346+
securityStandards.add(standard);
347+
}
348+
return this;
349+
}
350+
338351
@Override
339352
public DefaultNewRule addOwaspAsvs(OwaspAsvsVersion owaspAsvsVersion, String... requirements) {
340353
requireNonNull(owaspAsvsVersion, "OWASP ASVS version must not be null");

plugin-api/src/test/java/org/sonar/api/server/rule/internal/DefaultNewRuleTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import org.sonar.api.server.rule.RuleDescriptionSectionBuilder;
3636
import org.sonar.api.server.rule.RulesDefinition;
3737
import org.sonar.api.server.rule.RulesDefinition.OwaspAsvsVersion;
38+
import org.sonar.api.server.rule.RulesDefinition.OwaspMobileTop10;
39+
import org.sonar.api.server.rule.RulesDefinition.OwaspMobileTop10Version;
3840
import org.sonar.api.server.rule.RulesDefinition.OwaspTop10;
3941
import org.sonar.api.server.rule.RulesDefinition.OwaspTop10Version;
4042
import org.sonar.api.server.rule.RulesDefinition.PciDssVersion;
@@ -143,6 +145,10 @@ private void assertSecurityStandards() {
143145
assertThat(rule.securityStandards())
144146
.contains("owaspTop10:a1", "owaspTop10:a2", "owaspTop10:a4", "owaspTop10-2021:a3", "owaspTop10-2021:a5");
145147

148+
rule.addOwaspMobileTop10(OwaspMobileTop10Version.Y2024, OwaspMobileTop10.M2, OwaspMobileTop10.M3);
149+
rule.addOwaspMobileTop10(OwaspMobileTop10Version.Y2024, OwaspMobileTop10.M5);
150+
assertThat(rule.securityStandards()).contains("owaspMobileTop10-2024:m2", "owaspMobileTop10-2024:m3", "owaspMobileTop10-2024:m5");
151+
146152
rule.addPciDss(PciDssVersion.V3_2, "6.5.1");
147153
rule.addPciDss(PciDssVersion.V3_2, "6.5");
148154
rule.addPciDss(PciDssVersion.V4_0, "6.5.2", "6.5.10");
@@ -228,6 +234,13 @@ public void fail_if_null_owasp_version() {
228234
.hasMessage("Owasp version must not be null");
229235
}
230236

237+
@Test
238+
public void fail_if_null_owasp_mobile_version() {
239+
assertThatThrownBy(() -> rule.addOwaspMobileTop10(null, OwaspMobileTop10.M5))
240+
.isInstanceOf(NullPointerException.class)
241+
.hasMessage("Owasp mobile version must not be null");
242+
}
243+
231244
@Test
232245
public void fail_if_null_pci_dss_version() {
233246
assertThatThrownBy(() -> rule.addPciDss(null, "6.5.1"))

0 commit comments

Comments
 (0)