if (adHocDescription != null && shouldReturnField(fieldsToReturn, FIELD_HTML_DESCRIPTION)) {
ruleResponse.setHtmlDesc(macroInterpreter.interpret(adHocDescription));
}
+
+ if (shouldReturnField(fieldsToReturn, FIELD_DESCRIPTION_SECTIONS) && adHocDescription != null) {
+ ruleResponse.clearDescriptionSections();
+ ruleResponse.addDescriptionSectionsBuilder()
+ .setKey(RuleDescriptionSectionDto.DEFAULT_KEY)
+ .setContent(macroInterpreter.interpret(adHocDescription));
+ }
}
private static void setAdHocSeverity(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
@Test
public void show_adhoc_rule() {
- RuleDto externalRule = db.rules().insert(r -> r
- .setIsExternal(true)
- .setIsAdHoc(true)
- .setAdHocName("adhoc name")
- .setAdHocDescription("<div>desc</div>")
- .setAdHocSeverity(Severity.BLOCKER)
- .setAdHocType(RuleType.VULNERABILITY)
- .setNoteData(null)
- .setNoteUserUuid(null));
+ RuleDto externalRule = db.rules().insert(r -> {
+ r.setIsExternal(true)
+ .setIsAdHoc(true)
+ .setAdHocName("adhoc name")
+ .setAdHocDescription("<div>desc</div>")
+ .setAdHocSeverity(Severity.BLOCKER)
+ .setAdHocType(RuleType.VULNERABILITY)
+ .setNoteData(null)
+ .setNoteUserUuid(null);
+ //Ad-hoc description has no description sections defined
+ r.getRuleDescriptionSectionDtos().clear();
+ }
+ );
+
doReturn("<div>desc2</div>").when(macroInterpreter).interpret(externalRule.getAdHocDescription());
ShowResponse result = ws.newRequest()
assertThat(resultRule)
.extracting(Rule::getName, Rule::getHtmlDesc, Rule::getSeverity, Rule::getType)
.containsExactlyInAnyOrder("adhoc name", "<div>desc2</div>", Severity.BLOCKER, VULNERABILITY);
+
+ assertThat(resultRule.getDescriptionSectionsList()).hasSize(1);
+ assertThat(resultRule.getDescriptionSectionsList().get(0))
+ .extracting(r -> r.getKey(), r -> r.getContent())
+ .containsExactly(DEFAULT_KEY, "<div>desc2</div>");
}
@Test