Skip to content

Commit 2e0ed56

Browse files
authored
Fix S3 validation errors not caught by action listener (opensearch-project#1257)
* catch errors and fail action listener Signed-off-by: Joanne Wang <jowg@amazon.com> * add test to validate behavior Signed-off-by: Joanne Wang <jowg@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com>
1 parent 890493a commit 2e0ed56

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFetchService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,14 @@ public void onlyIndexIocs(SATIFSourceConfig saTifSourceConfig,
141141
}
142142

143143
public void downloadAndIndexIOCs(SATIFSourceConfig saTifSourceConfig, ActionListener<STIX2IOCFetchResponse> listener) {
144-
S3ConnectorConfig s3ConnectorConfig = constructS3ConnectorConfig(saTifSourceConfig);
144+
S3ConnectorConfig s3ConnectorConfig;
145+
try {
146+
s3ConnectorConfig = constructS3ConnectorConfig(saTifSourceConfig);
147+
} catch (SecurityAnalyticsException e) {
148+
listener.onFailure(e);
149+
return;
150+
}
151+
145152
Connector<STIX2> s3Connector = constructS3Connector(s3ConnectorConfig);
146153
STIX2IOCFeedStore feedStore = new STIX2IOCFeedStore(client, clusterService, saTifSourceConfig, listener);
147154
STIX2IOCConsumer consumer = new STIX2IOCConsumer(batchSize, feedStore, UpdateType.REPLACE);

src/test/java/org/opensearch/securityanalytics/resthandler/SATIFSourceConfigRestApiIT.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,57 @@ public void testWhenBucketObjectDoesNotExist() {
788788
}
789789
}
790790

791+
public void testWhenRoleArnIsEmpty() throws IOException {
792+
// Try to create a source config with empty roleArn
793+
source = new S3Source("bucketName", "objectKey", "region", "");
794+
795+
// Create test feed
796+
String feedName = "download_test_feed_name";
797+
String feedFormat = "STIX2";
798+
SourceConfigType sourceConfigType = SourceConfigType.S3_CUSTOM;
799+
IntervalSchedule schedule = new IntervalSchedule(Instant.now(), 1, ChronoUnit.MINUTES);
800+
List<String> iocTypes = List.of(IOCType.IPV4_TYPE);
801+
802+
SATIFSourceConfigDto saTifSourceConfigDto = new SATIFSourceConfigDto(
803+
null,
804+
null,
805+
feedName,
806+
feedFormat,
807+
sourceConfigType,
808+
null,
809+
null,
810+
Instant.now(),
811+
source,
812+
null,
813+
Instant.now(),
814+
schedule,
815+
null,
816+
null,
817+
Instant.now(),
818+
null,
819+
true,
820+
iocTypes,
821+
true
822+
);
823+
824+
Exception exception = assertThrows(ResponseException.class, () ->
825+
makeRequest(client(), "POST", SecurityAnalyticsPlugin.THREAT_INTEL_SOURCE_URI, Collections.emptyMap(), toHttpEntity(saTifSourceConfigDto))
826+
);
827+
828+
String expectedError = "Role arn is empty or malformed";
829+
assertTrue("Exception contains unexpected message: " + exception.getMessage(), exception.getMessage().contains(expectedError));
830+
831+
// ensure that source config is not created
832+
String request = "{\n" +
833+
" \"query\" : {\n" +
834+
" \"match_all\":{\n" +
835+
" }\n" +
836+
" }\n" +
837+
"}";
838+
List<SearchHit> hits = executeSearch(JOB_INDEX_NAME, request);
839+
Assert.assertEquals(0, hits.size());
840+
}
841+
791842
/**
792843
* Calls the get source config api and checks if the last updated time is different from the time that was passed in
793844
* @param createdId

0 commit comments

Comments
 (0)