From cb42ef8865f3533c96480e256ceed1637bdb1f26 Mon Sep 17 00:00:00 2001 From: Subhobrata Dey Date: Wed, 11 Jan 2023 18:06:55 +0000 Subject: [PATCH 1/3] fix flaky tests for locale Signed-off-by: Subhobrata Dey --- src/test/java/org/opensearch/securityanalytics/TestHelpers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/opensearch/securityanalytics/TestHelpers.java b/src/test/java/org/opensearch/securityanalytics/TestHelpers.java index 939b118f5..34afda245 100644 --- a/src/test/java/org/opensearch/securityanalytics/TestHelpers.java +++ b/src/test/java/org/opensearch/securityanalytics/TestHelpers.java @@ -320,7 +320,7 @@ public static User randomUserEmpty() { } public static String randomDetectorType() { - return "TEST_WINDOWS"; + return "test_windows"; } public static DetectorInput randomDetectorInput() { From 58091db45b5022a6693740ab9f8cb824b7f878ff Mon Sep 17 00:00:00 2001 From: Subhobrata Dey Date: Wed, 11 Jan 2023 18:32:31 +0000 Subject: [PATCH 2/3] add nesting level to yaml constructor Signed-off-by: Subhobrata Dey --- .../securityanalytics/rules/objects/SigmaRule.java | 8 +++++++- .../SecurityAnalyticsPluginTransportIT.java | 4 ++-- .../securityanalytics/resthandler/DetectorRestApiIT.java | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/opensearch/securityanalytics/rules/objects/SigmaRule.java b/src/main/java/org/opensearch/securityanalytics/rules/objects/SigmaRule.java index 4b507a863..6236713d1 100644 --- a/src/main/java/org/opensearch/securityanalytics/rules/objects/SigmaRule.java +++ b/src/main/java/org/opensearch/securityanalytics/rules/objects/SigmaRule.java @@ -11,8 +11,11 @@ import org.opensearch.securityanalytics.rules.exceptions.SigmaLevelError; import org.opensearch.securityanalytics.rules.exceptions.SigmaLogsourceError; import org.opensearch.securityanalytics.rules.exceptions.SigmaStatusError; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.SafeConstructor; +import org.yaml.snakeyaml.representer.Representer; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -168,7 +171,10 @@ protected static SigmaRule fromDict(Map rule, boolean collectErr } public static SigmaRule fromYaml(String rule, boolean collectErrors) throws SigmaError { - Yaml yaml = new Yaml(new SafeConstructor()); + LoaderOptions loaderOptions = new LoaderOptions(); + loaderOptions.setNestingDepthLimit(10); + + Yaml yaml = new Yaml(new SafeConstructor(), new Representer(), new DumperOptions(), loaderOptions); Map ruleMap = yaml.load(rule); return fromDict(ruleMap, collectErrors); } diff --git a/src/test/java/org/opensearch/securityanalytics/SecurityAnalyticsPluginTransportIT.java b/src/test/java/org/opensearch/securityanalytics/SecurityAnalyticsPluginTransportIT.java index ab8b374f1..688df56a0 100644 --- a/src/test/java/org/opensearch/securityanalytics/SecurityAnalyticsPluginTransportIT.java +++ b/src/test/java/org/opensearch/securityanalytics/SecurityAnalyticsPluginTransportIT.java @@ -17,7 +17,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -public class SecurityAnalyticsPluginTransportIT extends OpenSearchIntegTestCase { +/*public class SecurityAnalyticsPluginTransportIT extends OpenSearchIntegTestCase { public void testPluginsAreInstalled() { NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(); @@ -30,4 +30,4 @@ public void testPluginsAreInstalled() { Assert.assertTrue(pluginInfos.stream().anyMatch(pluginInfo -> pluginInfo.getName() .equals("opensearch-security-analytics"))); } -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/src/test/java/org/opensearch/securityanalytics/resthandler/DetectorRestApiIT.java b/src/test/java/org/opensearch/securityanalytics/resthandler/DetectorRestApiIT.java index e20f69161..1711a6ca3 100644 --- a/src/test/java/org/opensearch/securityanalytics/resthandler/DetectorRestApiIT.java +++ b/src/test/java/org/opensearch/securityanalytics/resthandler/DetectorRestApiIT.java @@ -585,12 +585,12 @@ public void testDeletingADetector_single_ruleTopicIndex() throws IOException { Response deleteResponse = makeRequest(client(), "DELETE", SecurityAnalyticsPlugin.DETECTOR_BASE_URI + "/" + detectorId1, Collections.emptyMap(), null); Assert.assertEquals("Delete detector failed", RestStatus.OK, restStatus(deleteResponse)); // We deleted 1 detector, but 1 detector with same type exists, so we expect queryIndex to be present - Assert.assertTrue(doesIndexExist(String.format(Locale.getDefault(), ".opensearch-sap-%s-detectors-queries-000001", "test_windows"))); + Assert.assertTrue(doesIndexExist(String.format(Locale.ROOT, ".opensearch-sap-%s-detectors-queries-000001", "test_windows"))); deleteResponse = makeRequest(client(), "DELETE", SecurityAnalyticsPlugin.DETECTOR_BASE_URI + "/" + detectorId2, Collections.emptyMap(), null); Assert.assertEquals("Delete detector failed", RestStatus.OK, restStatus(deleteResponse)); // We deleted all detectors of type windows, so we expect that queryIndex is deleted - Assert.assertFalse(doesIndexExist(String.format(Locale.getDefault(), ".opensearch-sap-%s-detectors-queries-000001", "test_windows"))); + Assert.assertFalse(doesIndexExist(String.format(Locale.ROOT, ".opensearch-sap-%s-detectors-queries-000001", "test_windows"))); request = "{\n" + " \"query\" : {\n" + From e6cddd74d98e0f71de3f41a8ca8bbbf8d0edf5ca Mon Sep 17 00:00:00 2001 From: Subhobrata Dey Date: Wed, 11 Jan 2023 18:36:35 +0000 Subject: [PATCH 3/3] add nesting level to yaml constructor Signed-off-by: Subhobrata Dey --- .../securityanalytics/SecurityAnalyticsPluginTransportIT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/opensearch/securityanalytics/SecurityAnalyticsPluginTransportIT.java b/src/test/java/org/opensearch/securityanalytics/SecurityAnalyticsPluginTransportIT.java index 688df56a0..ab8b374f1 100644 --- a/src/test/java/org/opensearch/securityanalytics/SecurityAnalyticsPluginTransportIT.java +++ b/src/test/java/org/opensearch/securityanalytics/SecurityAnalyticsPluginTransportIT.java @@ -17,7 +17,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -/*public class SecurityAnalyticsPluginTransportIT extends OpenSearchIntegTestCase { +public class SecurityAnalyticsPluginTransportIT extends OpenSearchIntegTestCase { public void testPluginsAreInstalled() { NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(); @@ -30,4 +30,4 @@ public void testPluginsAreInstalled() { Assert.assertTrue(pluginInfos.stream().anyMatch(pluginInfo -> pluginInfo.getName() .equals("opensearch-security-analytics"))); } -}*/ \ No newline at end of file +} \ No newline at end of file