diff --git a/src/test/java/org/opensearch/securityanalytics/model/SATIFSourceConfigDtoTests.java b/src/test/java/org/opensearch/securityanalytics/model/SATIFSourceConfigDtoTests.java index c9215af5a..e5b2ed7c5 100644 --- a/src/test/java/org/opensearch/securityanalytics/model/SATIFSourceConfigDtoTests.java +++ b/src/test/java/org/opensearch/securityanalytics/model/SATIFSourceConfigDtoTests.java @@ -10,11 +10,15 @@ import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule; +import org.opensearch.securityanalytics.threatIntel.common.SourceConfigType; import org.opensearch.securityanalytics.threatIntel.model.S3Source; import org.opensearch.securityanalytics.threatIntel.model.SATIFSourceConfigDto; import org.opensearch.test.OpenSearchTestCase; import java.io.IOException; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.List; import static org.opensearch.securityanalytics.TestHelpers.randomSATIFSourceConfigDto; @@ -36,6 +40,34 @@ public void testParseFunction() throws IOException { assertEqualsSaTifSourceConfigDtos(saTifSourceConfigDto, newSaTifSourceConfigDto); } + public void testParseFunctionWithNullValues() throws IOException { + // Source config with invalid name and format + SATIFSourceConfigDto saTifSourceConfigDto = new SATIFSourceConfigDto( + "randomId", + null, + null, + null, + SourceConfigType.S3_CUSTOM, + null, + null, + null, + new S3Source("bucket", "objectkey", "region", "rolearn"), + null, + null, + new org.opensearch.jobscheduler.spi.schedule.IntervalSchedule(Instant.now(), 1, ChronoUnit.DAYS), + null, + null, + null, + null, + true, + List.of("ip"), + true + ); + String json = toJsonString(saTifSourceConfigDto); + SATIFSourceConfigDto newSaTifSourceConfigDto = SATIFSourceConfigDto.parse(getParser(json), saTifSourceConfigDto.getId(), null); + assertEqualsSaTifSourceConfigDtos(saTifSourceConfigDto, newSaTifSourceConfigDto); + } + public XContentParser getParser(String xc) throws IOException { XContentParser parser = XContentType.JSON.xContent().createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, xc); parser.nextToken(); diff --git a/src/test/java/org/opensearch/securityanalytics/model/SATIFSourceConfigTests.java b/src/test/java/org/opensearch/securityanalytics/model/SATIFSourceConfigTests.java index 2687907d1..8fa8ec395 100644 --- a/src/test/java/org/opensearch/securityanalytics/model/SATIFSourceConfigTests.java +++ b/src/test/java/org/opensearch/securityanalytics/model/SATIFSourceConfigTests.java @@ -10,12 +10,17 @@ import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule; +import org.opensearch.securityanalytics.commons.model.IOCType; +import org.opensearch.securityanalytics.threatIntel.common.SourceConfigType; import org.opensearch.securityanalytics.threatIntel.model.DefaultIocStoreConfig; import org.opensearch.securityanalytics.threatIntel.model.S3Source; import org.opensearch.securityanalytics.threatIntel.model.SATIFSourceConfig; import org.opensearch.test.OpenSearchTestCase; import java.io.IOException; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.List; import static org.opensearch.securityanalytics.TestHelpers.randomSATIFSourceConfig; @@ -37,6 +42,35 @@ public void testParseFunction() throws IOException { assertEqualsSaTifSourceConfigs(saTifSourceConfig, newSaTifSourceConfig); } + public void testParseFunctionWithNullValues() throws IOException { + // Source config with invalid name and format + SATIFSourceConfig saTifSourceConfig = new SATIFSourceConfig( + null, + null, + null, + null, + SourceConfigType.S3_CUSTOM, + null, + null, + null, + new S3Source("bucket", "objectkey", "region", "rolearn"), + null, + null, + new org.opensearch.jobscheduler.spi.schedule.IntervalSchedule(Instant.now(), 1, ChronoUnit.DAYS), + null, + null, + null, + null, + true, + new DefaultIocStoreConfig(List.of(new DefaultIocStoreConfig.IocToIndexDetails(new IOCType(IOCType.DOMAIN_NAME_TYPE), "indexPattern", "writeIndex"))), + List.of("ip"), + true + ); + String json = toJsonString(saTifSourceConfig); + SATIFSourceConfig newSaTifSourceConfig = SATIFSourceConfig.parse(getParser(json), saTifSourceConfig.getId(), null); + assertEqualsSaTifSourceConfigs(saTifSourceConfig, newSaTifSourceConfig); + } + public XContentParser getParser(String xc) throws IOException { XContentParser parser = XContentType.JSON.xContent().createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, xc); parser.nextToken();