Skip to content

Commit

Permalink
remove ioc finding tests with sleep
Browse files Browse the repository at this point in the history
Signed-off-by: Surya Sashank Nistala <[email protected]>
  • Loading branch information
eirsep authored and jowg-amazon committed Jul 2, 2024
1 parent bb58db1 commit 93b48a7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 159 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
import org.opensearch.securityanalytics.SecurityAnalyticsRestTestCase;
import org.opensearch.securityanalytics.model.threatintel.IocFinding;
import org.opensearch.securityanalytics.model.threatintel.IocWithFeeds;
import org.opensearch.test.OpenSearchTestCase;

import java.io.IOException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.opensearch.securityanalytics.settings.SecurityAnalyticsSettings.*;

public class IocFindingServiceRestApiIT extends SecurityAnalyticsRestTestCase {

Expand Down Expand Up @@ -56,67 +51,67 @@ public void testGetIocFindingsWithIocIdFilter() throws IOException {
Map<String, Object> responseAsMap = responseAsMap(response);
Assert.assertEquals(1, ((List<Map<String, Object>>) responseAsMap.get("ioc_findings")).size());
}

public void testGetIocFindingsRolloverByMaxDocs() throws IOException, InterruptedException {
updateClusterSetting(IOC_FINDING_HISTORY_ROLLOVER_PERIOD.getKey(), "1s");
updateClusterSetting(IOC_FINDING_HISTORY_MAX_DOCS.getKey(), "1");
makeRequest(client(), "GET", SecurityAnalyticsPlugin.THREAT_INTEL_BASE_URI + "/findings/_search?startIndex=1&size=5",
Map.of(), null);
List<IocFinding> iocFindings = generateIocMatches(5);
for (IocFinding iocFinding: iocFindings) {
makeRequest(client(), "POST", IocFindingService.IOC_FINDING_ALIAS_NAME + "/_doc?refresh", Map.of(),
toHttpEntity(iocFinding));
}

AtomicBoolean found = new AtomicBoolean(false);
OpenSearchTestCase.waitUntil(() -> {
try {
found.set(getIocFindingIndices().size() == 2);
return found.get();
} catch (IOException e) {
return false;
}
}, 30000, TimeUnit.SECONDS);
Assert.assertTrue(found.get());
}

public void testGetIocFindingsRolloverByMaxAge() throws IOException, InterruptedException {
updateClusterSetting(IOC_FINDING_HISTORY_ROLLOVER_PERIOD.getKey(), "1s");
updateClusterSetting(IOC_FINDING_HISTORY_MAX_DOCS.getKey(), "1000");
updateClusterSetting(IOC_FINDING_HISTORY_INDEX_MAX_AGE.getKey(), "1s");
makeRequest(client(), "GET", SecurityAnalyticsPlugin.THREAT_INTEL_BASE_URI + "/findings/_search?startIndex=1&size=5",
Map.of(), null);
List<IocFinding> iocFindings = generateIocMatches(5);
for (IocFinding iocFinding: iocFindings) {
makeRequest(client(), "POST", IocFindingService.IOC_FINDING_ALIAS_NAME + "/_doc?refresh", Map.of(),
toHttpEntity(iocFinding));
}

AtomicBoolean found = new AtomicBoolean(false);
OpenSearchTestCase.waitUntil(() -> {
try {
found.set(getIocFindingIndices().size() == 2);
return found.get();
} catch (IOException e) {
return false;
}
}, 30000, TimeUnit.SECONDS);
Assert.assertTrue(found.get());

updateClusterSetting(IOC_FINDING_HISTORY_INDEX_MAX_AGE.getKey(), "1000s");
updateClusterSetting(IOC_FINDING_HISTORY_RETENTION_PERIOD.getKey(), "1s");

AtomicBoolean retFound = new AtomicBoolean(false);
OpenSearchTestCase.waitUntil(() -> {
try {
retFound.set(getIocFindingIndices().size() == 1);
return retFound.get();
} catch (IOException e) {
return false;
}
}, 30000, TimeUnit.SECONDS);
Assert.assertTrue(retFound.get());
}
//
// public void testGetIocFindingsRolloverByMaxDocs() throws IOException, InterruptedException {
// updateClusterSetting(IOC_FINDING_HISTORY_ROLLOVER_PERIOD.getKey(), "1s");
// updateClusterSetting(IOC_FINDING_HISTORY_MAX_DOCS.getKey(), "1");
// makeRequest(client(), "GET", SecurityAnalyticsPlugin.THREAT_INTEL_BASE_URI + "/findings/_search?startIndex=1&size=5",
// Map.of(), null);
// List<IocFinding> iocFindings = generateIocMatches(5);
// for (IocFinding iocFinding: iocFindings) {
// makeRequest(client(), "POST", IocFindingService.IOC_FINDING_ALIAS_NAME + "/_doc?refresh", Map.of(),
// toHttpEntity(iocFinding));
// }
//
// AtomicBoolean found = new AtomicBoolean(false);
// OpenSearchTestCase.waitUntil(() -> {
// try {
// found.set(getIocFindingIndices().size() == 2);
// return found.get();
// } catch (IOException e) {
// return false;
// }
// }, 30000, TimeUnit.SECONDS);
// Assert.assertTrue(found.get());
// }
//
// public void testGetIocFindingsRolloverByMaxAge() throws IOException, InterruptedException {
// updateClusterSetting(IOC_FINDING_HISTORY_ROLLOVER_PERIOD.getKey(), "1s");
// updateClusterSetting(IOC_FINDING_HISTORY_MAX_DOCS.getKey(), "1000");
// updateClusterSetting(IOC_FINDING_HISTORY_INDEX_MAX_AGE.getKey(), "1s");
// makeRequest(client(), "GET", SecurityAnalyticsPlugin.THREAT_INTEL_BASE_URI + "/findings/_search?startIndex=1&size=5",
// Map.of(), null);
// List<IocFinding> iocFindings = generateIocMatches(5);
// for (IocFinding iocFinding: iocFindings) {
// makeRequest(client(), "POST", IocFindingService.IOC_FINDING_ALIAS_NAME + "/_doc?refresh", Map.of(),
// toHttpEntity(iocFinding));
// }
//
// AtomicBoolean found = new AtomicBoolean(false);
// OpenSearchTestCase.waitUntil(() -> {
// try {
// found.set(getIocFindingIndices().size() == 2);
// return found.get();
// } catch (IOException e) {
// return false;
// }
// }, 30000, TimeUnit.SECONDS);
// Assert.assertTrue(found.get());
//
// updateClusterSetting(IOC_FINDING_HISTORY_INDEX_MAX_AGE.getKey(), "1000s");
// updateClusterSetting(IOC_FINDING_HISTORY_RETENTION_PERIOD.getKey(), "1s");
//
// AtomicBoolean retFound = new AtomicBoolean(false);
// OpenSearchTestCase.waitUntil(() -> {
// try {
// retFound.set(getIocFindingIndices().size() == 1);
// return retFound.get();
// } catch (IOException e) {
// return false;
// }
// }, 30000, TimeUnit.SECONDS);
// Assert.assertTrue(retFound.get());
// }

private List<IocFinding> generateIocMatches(int i) {
List<IocFinding> iocFindings = new ArrayList<>();
Expand Down

0 comments on commit 93b48a7

Please sign in to comment.