|
31 | 31 | import org.junit.jupiter.params.provider.MethodSource;
|
32 | 32 | import org.mockito.ArgumentCaptor;
|
33 | 33 | import software.amazon.awssdk.awscore.retry.AwsRetryStrategy;
|
| 34 | +import software.amazon.awssdk.core.exception.SdkClientException; |
34 | 35 | import software.amazon.awssdk.metrics.MetricCollection;
|
35 | 36 | import software.amazon.awssdk.metrics.MetricPublisher;
|
36 | 37 | import software.amazon.awssdk.core.metrics.CoreMetric;
|
@@ -208,6 +209,23 @@ private static Stream<Arguments> additionalTestCases() {
|
208 | 209 | );
|
209 | 210 | }
|
210 | 211 |
|
| 212 | + private static Stream<Arguments> invalidUrlTestCases() { |
| 213 | + return Stream.of( |
| 214 | + Arguments.of( |
| 215 | + "URL with spaces in path", |
| 216 | + "https://test-bucket.s3.us-east-1.amazonaws.com/test key with spaces" |
| 217 | + ), |
| 218 | + Arguments.of( |
| 219 | + "URL with invalid characters", |
| 220 | + "https://test-bucket.s3.us-east-1.amazonaws.com/test<>key" |
| 221 | + ), |
| 222 | + Arguments.of( |
| 223 | + "Malformed URL", |
| 224 | + "not-a-valid-url" |
| 225 | + ) |
| 226 | + ); |
| 227 | + } |
| 228 | + |
211 | 229 | @ParameterizedTest(name = "{0}")
|
212 | 230 | @MethodSource("additionalTestCases")
|
213 | 231 | void given_PresignedUrlManager_when_ExecutingDifferentScenarios_then_ShouldBehaveCorrectly(String testName,
|
@@ -256,6 +274,21 @@ void given_PresignedUrlManager_when_ExecutingDifferentScenarios_then_ShouldBehav
|
256 | 274 | }
|
257 | 275 | }
|
258 | 276 |
|
| 277 | + @ParameterizedTest(name = "{0}") |
| 278 | + @MethodSource("invalidUrlTestCases") |
| 279 | + void given_PresignedUrlManager_when_GetObjectWithInvalidUrl_then_ShouldThrowException(String testName, String invalidUrlString) { |
| 280 | + assertThatThrownBy(() -> { |
| 281 | + URL invalidUrl = new URL(invalidUrlString); |
| 282 | + PresignedUrlGetObjectRequest invalidRequest = PresignedUrlGetObjectRequest.builder() |
| 283 | + .presignedUrl(invalidUrl) |
| 284 | + .build(); |
| 285 | + presignedUrlManager.getObject(invalidRequest, ResponseTransformer.toInputStream()); |
| 286 | + }).satisfiesAnyOf( |
| 287 | + ex -> assertThat(ex).isInstanceOf(java.net.MalformedURLException.class), |
| 288 | + ex -> assertThat(ex).isInstanceOf(SdkClientException.class) |
| 289 | + ); |
| 290 | + } |
| 291 | + |
259 | 292 | private SdkClientConfiguration getDefaultSdkConfigs() {
|
260 | 293 | return SdkClientConfiguration.builder()
|
261 | 294 | .option(SdkClientOption.SYNC_HTTP_CLIENT, mockHttpClient)
|
|
0 commit comments