Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.16] Fix S3 validation errors not caught by action listener #1266

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,14 @@
}

public void downloadAndIndexIOCs(SATIFSourceConfig saTifSourceConfig, ActionListener<STIX2IOCFetchResponse> listener) {
S3ConnectorConfig s3ConnectorConfig = constructS3ConnectorConfig(saTifSourceConfig);
S3ConnectorConfig s3ConnectorConfig;
try {
s3ConnectorConfig = constructS3ConnectorConfig(saTifSourceConfig);

Check warning on line 146 in src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFetchService.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L146 was not covered by tests
} catch (SecurityAnalyticsException e) {
listener.onFailure(e);
return;
}

Check warning on line 150 in src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFetchService.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L150 was not covered by tests

Connector<STIX2> s3Connector = constructS3Connector(s3ConnectorConfig);
STIX2IOCFeedStore feedStore = new STIX2IOCFeedStore(client, clusterService, saTifSourceConfig, listener);
STIX2IOCConsumer consumer = new STIX2IOCConsumer(batchSize, feedStore, UpdateType.REPLACE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,57 @@ public void testWhenBucketObjectDoesNotExist() {
}
}

public void testWhenRoleArnIsEmpty() throws IOException {
// Try to create a source config with empty roleArn
source = new S3Source("bucketName", "objectKey", "region", "");

// Create test feed
String feedName = "download_test_feed_name";
String feedFormat = "STIX2";
SourceConfigType sourceConfigType = SourceConfigType.S3_CUSTOM;
IntervalSchedule schedule = new IntervalSchedule(Instant.now(), 1, ChronoUnit.MINUTES);
List<String> iocTypes = List.of(IOCType.IPV4_TYPE);

SATIFSourceConfigDto saTifSourceConfigDto = new SATIFSourceConfigDto(
null,
null,
feedName,
feedFormat,
sourceConfigType,
null,
null,
Instant.now(),
source,
null,
Instant.now(),
schedule,
null,
null,
Instant.now(),
null,
true,
iocTypes,
true
);

Exception exception = assertThrows(ResponseException.class, () ->
makeRequest(client(), "POST", SecurityAnalyticsPlugin.THREAT_INTEL_SOURCE_URI, Collections.emptyMap(), toHttpEntity(saTifSourceConfigDto))
);

String expectedError = "Role arn is empty or malformed";
assertTrue("Exception contains unexpected message: " + exception.getMessage(), exception.getMessage().contains(expectedError));

// ensure that source config is not created
String request = "{\n" +
" \"query\" : {\n" +
" \"match_all\":{\n" +
" }\n" +
" }\n" +
"}";
List<SearchHit> hits = executeSearch(JOB_INDEX_NAME, request);
Assert.assertEquals(0, hits.size());
}

/**
* Calls the get source config api and checks if the last updated time is different from the time that was passed in
* @param createdId
Expand Down
Loading