feat: Add news information management module with API and database support
- Introduced new API endpoints for querying and managing news information in the CMS. - Implemented data model for NewsInfo and NewsInfoQuery with validation. - Created NewsInfoMapper for database interactions and corresponding XML mappings. - Developed INewsInfoService interface and its implementation for business logic. - Added RichTextSanitizer utility for cleaning HTML content to prevent XSS attacks. - Created unit tests for RichTextSanitizer to ensure proper functionality. - Updated database schema with news_info table and necessary fields, including status and module. - Added migration scripts for setting up the news information module in the database. - Integrated jsoup library for HTML sanitization.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.ruoyi.cms.util;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class RichTextSanitizerTest {
|
||||
|
||||
@Test
|
||||
void shouldKeepCommonRichTextAndRemoveExecutableContent() {
|
||||
String source = "<h2>标题</h2><p onclick=\"alert(1)\"><strong>正文</strong></p>"
|
||||
+ "<script>alert('xss')</script>"
|
||||
+ "<a href=\"javascript:alert(2)\">危险链接</a>"
|
||||
+ "<img src=\"https://example.com/news.png\" onerror=\"alert(3)\">";
|
||||
|
||||
String cleaned = RichTextSanitizer.clean(source);
|
||||
|
||||
assertTrue(cleaned.contains("<h2>标题</h2>"));
|
||||
assertTrue(cleaned.contains("<strong>正文</strong>"));
|
||||
assertTrue(cleaned.contains("https://example.com/news.png"));
|
||||
assertFalse(cleaned.contains("script"));
|
||||
assertFalse(cleaned.contains("alert"));
|
||||
assertFalse(cleaned.contains("onclick"));
|
||||
assertFalse(cleaned.contains("onerror"));
|
||||
assertFalse(cleaned.contains("javascript:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldTreatEditorPlaceholderAsEmpty() {
|
||||
String cleaned = RichTextSanitizer.clean("<p><br></p>");
|
||||
|
||||
assertFalse(RichTextSanitizer.hasContent(cleaned));
|
||||
assertTrue(RichTextSanitizer.hasContent("<p>有效正文</p>"));
|
||||
assertTrue(RichTextSanitizer.hasContent("<img src=\"https://example.com/a.png\">"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user