fix(haobang-security-rule)修改json错误处理方式
This commit is contained in:
+32
@@ -105,6 +105,38 @@ class LogNormalProcessorRuleSelectionTest {
|
||||
verify(fixture.nonNormalService, never()).saveMessage(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidJsonStopsAtFirstJsonRuleAndGoesDirectlyToDeferredNonNormal() {
|
||||
RuleSource invalidJson = jsonRule(10L, "json-first", "", equalMapping(), "");
|
||||
RuleSource regexWouldMatch = regexRule(20L, "regex-second", "value=(\\S+)");
|
||||
Fixture fixture = fixture(Arrays.asList(invalidJson, regexWouldMatch), config(true));
|
||||
|
||||
LogNormalProcessor.NormalizationResult result = fixture.prepareActive(
|
||||
"value=ok {\"broken\":\"unterminated");
|
||||
|
||||
assertEquals(LogNormalProcessor.ProcessingOutcome.FILTERED, result.getOutcome());
|
||||
assertTrue(result.getRows().isEmpty());
|
||||
assertEquals(1, result.getNonNormalMessages().size());
|
||||
assertEquals("JSON解析异常", result.getNonNormalMessages().get(0).getReason());
|
||||
assertTrue(result.getNonNormalMessages().get(0).getReasonDetail().contains("ruleId=10"));
|
||||
verify(fixture.nonNormalService, never()).saveMessage(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyInvalidJsonIsNonNormalTerminalInsteadOfException() {
|
||||
Fixture fixture = fixture(Arrays.asList(
|
||||
jsonRule(10L, "legacy-json", "", equalMapping(), "")), config(false));
|
||||
|
||||
LogNormalProcessor.NormalizationResult result = fixture.prepareActive(
|
||||
"{\"broken\":\"unterminated");
|
||||
|
||||
assertEquals(LogNormalProcessor.ProcessingOutcome.FILTERED, result.getOutcome());
|
||||
assertTrue(result.getRows().isEmpty());
|
||||
assertEquals(1, result.getNonNormalMessages().size());
|
||||
assertEquals("JSON解析异常", result.getNonNormalMessages().get(0).getReason());
|
||||
verify(fixture.nonNormalService, never()).saveMessage(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonNormalSaveFailureRemainsRetryable() {
|
||||
Fixture fixture = fixture(Arrays.asList(
|
||||
|
||||
Reference in New Issue
Block a user