Skip to content

Commit

Permalink
Fix unit tests for Sigma title changes in main
Browse files Browse the repository at this point in the history
Signed-off-by: Megha Goyal <[email protected]>
  • Loading branch information
goyamegh committed Apr 15, 2024
1 parent d935a24 commit 084539a
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.opensearch.securityanalytics.rules.exceptions.SigmaLogsourceError;
import org.opensearch.securityanalytics.rules.exceptions.SigmaModifierError;
import org.opensearch.securityanalytics.rules.exceptions.SigmaRegularExpressionError;
import org.opensearch.securityanalytics.rules.exceptions.SigmaTitleError;
import org.opensearch.securityanalytics.rules.exceptions.SigmaValueError;
import org.opensearch.securityanalytics.rules.modifiers.SigmaContainsModifier;
import org.opensearch.securityanalytics.rules.modifiers.SigmaEndswithModifier;
Expand Down Expand Up @@ -53,7 +52,7 @@ public void testSigmaRuleBadLevel() {
SigmaRule.fromDict(sigmaRule, false);
});

String expectedMessage = "null is no valid Sigma rule level";
String expectedMessage = "Sigma rule level cannot be null";
String actualMessage = exception.getErrors().get(0).getMessage();

assertTrue(actualMessage.contains(expectedMessage));
Expand All @@ -68,7 +67,7 @@ public void testSigmaRuleBadStatus() {
SigmaRule.fromDict(sigmaRule, false);
});

String expectedMessage = "null is no valid Sigma rule status";
String expectedMessage = "Sigma rule status cannot be null";
String actualMessage = exception.getErrors().get(0).getMessage();

assertTrue(actualMessage.contains(expectedMessage));
Expand Down Expand Up @@ -97,23 +96,23 @@ public void testSigmaRuleBadTitle() {
String invalidSigmaRuleTitle = "";
sigmaRule.put("title", invalidSigmaRuleTitle);

Exception exception = assertThrows(SigmaTitleError.class, () -> {
CompositeSigmaErrors exception = assertThrows(CompositeSigmaErrors.class, () -> {
SigmaRule.fromDict(sigmaRule, false);
});

String expectedMessage = "Sigma rule title can be max 256 characters";
String actualMessage = exception.getMessage();
String actualMessage = exception.getErrors().get(0).getMessage();
assertTrue(actualMessage.contains(expectedMessage));

// test string over 256 chars
invalidSigmaRuleTitle = "a".repeat(257);
sigmaRule.put("title", invalidSigmaRuleTitle);

exception = assertThrows(SigmaTitleError.class, () -> {
exception = assertThrows(CompositeSigmaErrors.class, () -> {
SigmaRule.fromDict(sigmaRule, false);
});

actualMessage = exception.getMessage();
actualMessage = exception.getErrors().get(0).getMessage();
assertTrue(actualMessage.contains(expectedMessage));
}

Expand Down

0 comments on commit 084539a

Please sign in to comment.