diff --git a/data-prepper-plugins/aws-plugin-api/build.gradle b/data-prepper-plugins/aws-plugin-api/build.gradle index be45155735..10c360f9da 100644 --- a/data-prepper-plugins/aws-plugin-api/build.gradle +++ b/data-prepper-plugins/aws-plugin-api/build.gradle @@ -13,7 +13,7 @@ jacocoTestCoverageVerification { violationRules { rule { limit { - minimum = 0.95 + minimum = 0.99 } } } diff --git a/data-prepper-plugins/aws-plugin-api/src/main/java/org/opensearch/dataprepper/aws/api/AwsRequestSigningApache4Interceptor.java b/data-prepper-plugins/aws-plugin-api/src/main/java/org/opensearch/dataprepper/aws/api/AwsRequestSigningApache4Interceptor.java index 36c5ff4492..0f5e3ab3f3 100644 --- a/data-prepper-plugins/aws-plugin-api/src/main/java/org/opensearch/dataprepper/aws/api/AwsRequestSigningApache4Interceptor.java +++ b/data-prepper-plugins/aws-plugin-api/src/main/java/org/opensearch/dataprepper/aws/api/AwsRequestSigningApache4Interceptor.java @@ -169,7 +169,7 @@ private URI buildUri(final HttpContext context, URIBuilder uriBuilder) throws IO } return uriBuilder.build(); - } catch (URISyntaxException e) { + } catch (final Exception e) { throw new IOException("Invalid URI", e); } } diff --git a/data-prepper-plugins/aws-plugin-api/src/test/java/org/opensearch/dataprepper/aws/api/AwsRequestSigningApache4InterceptorTest.java b/data-prepper-plugins/aws-plugin-api/src/test/java/org/opensearch/dataprepper/aws/api/AwsRequestSigningApache4InterceptorTest.java index e7ef5a4dde..0ed6d3f769 100644 --- a/data-prepper-plugins/aws-plugin-api/src/test/java/org/opensearch/dataprepper/aws/api/AwsRequestSigningApache4InterceptorTest.java +++ b/data-prepper-plugins/aws-plugin-api/src/test/java/org/opensearch/dataprepper/aws/api/AwsRequestSigningApache4InterceptorTest.java @@ -66,6 +66,51 @@ void invalidURI_throws_IOException() { assertThrows(IOException.class, () -> objectUnderTest.process(httpRequest, httpContext)); } + @Test + void IOException_is_thrown_when_buildURI_throws_exception() { + final RequestLine requestLine = mock(RequestLine.class); + when(requestLine.getMethod()).thenReturn("GET"); + when(requestLine.getUri()).thenReturn("http://localhost?param=test"); + when(httpRequest.getRequestLine()).thenReturn(requestLine); + + when(httpContext.getAttribute(HttpCoreContext.HTTP_TARGET_HOST)).thenThrow(RuntimeException.class); + + final AwsRequestSigningApache4Interceptor objectUnderTest = createObjectUnderTest(); + + assertThrows(IOException.class, () -> objectUnderTest.process(httpRequest, httpContext)); + } + + @Test + void empty_contentStreamProvider_throws_IllegalStateException() throws IOException { + final RequestLine requestLine = mock(RequestLine.class); + when(requestLine.getMethod()).thenReturn("GET"); + when(requestLine.getUri()).thenReturn("http://localhost?param=test"); + when(httpRequest.getRequestLine()).thenReturn(requestLine); + when(httpRequest.getAllHeaders()).thenReturn(new BasicHeader[]{ + new BasicHeader("test-name", "test-value"), + new BasicHeader("content-length", "0") + }); + + final HttpEntity httpEntity = mock(HttpEntity.class); + final InputStream inputStream = mock(InputStream.class); + when(httpEntity.getContent()).thenReturn(inputStream); + + when((httpRequest).getEntity()).thenReturn(httpEntity); + + final HttpHost httpHost = HttpHost.create("http://localhost?param=test"); + when(httpContext.getAttribute(HttpCoreContext.HTTP_TARGET_HOST)).thenReturn(httpHost); + + final SdkHttpFullRequest signedRequest = mock(SdkHttpFullRequest.class); + when(signedRequest.headers()).thenReturn(Map.of("test-name", List.of("test-value"))); + when(signedRequest.contentStreamProvider()).thenReturn(Optional.empty()); + when(signer.sign(any(SdkHttpFullRequest.class), any(ExecutionAttributes.class))) + .thenReturn(signedRequest); + + final AwsRequestSigningApache4Interceptor objectUnderTest = createObjectUnderTest(); + + assertThrows(IllegalStateException.class, () -> objectUnderTest.process(httpRequest, httpContext)); + } + @Test void testHappyPath() throws IOException { final RequestLine requestLine = mock(RequestLine.class);