39
39
40
40
41
41
class CloudFrontUtilitiesTest {
42
- private static final String resourceUrl = "https://d1npcfkc2mojrf.cloudfront.net/s3ObjectKey" ;
42
+ private static final String RESOURCE_URL = "https://d1npcfkc2mojrf.cloudfront.net/s3ObjectKey" ;
43
+ private static final String RESOURCE_URL_WITH_PORT = "https://d1npcfkc2mojrf.cloudfront.net:65535/s3ObjectKey" ;
43
44
private static KeyPairGenerator kpg ;
44
45
private static KeyPair keyPair ;
45
46
private static File keyFile ;
@@ -77,7 +78,7 @@ void getSignedURLWithCannedPolicy_producesValidUrl() {
77
78
Instant expirationDate = LocalDate .of (2024 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
78
79
SignedUrl signedUrl =
79
80
cloudFrontUtilities .getSignedUrlWithCannedPolicy (r -> r
80
- .resourceUrl (resourceUrl )
81
+ .resourceUrl (RESOURCE_URL )
81
82
.privateKey (keyPair .getPrivate ())
82
83
.keyPairId ("keyPairId" )
83
84
.expirationDate (expirationDate ));
@@ -115,7 +116,7 @@ void getSignedURLWithCustomPolicy_producesValidUrl() throws Exception {
115
116
String ipRange = "1.2.3.4" ;
116
117
SignedUrl signedUrl = cloudFrontUtilities .getSignedUrlWithCustomPolicy (r -> {
117
118
try {
118
- r .resourceUrl (resourceUrl )
119
+ r .resourceUrl (RESOURCE_URL )
119
120
.privateKey (keyFilePath )
120
121
.keyPairId ("keyPairId" )
121
122
.expirationDate (expirationDate )
@@ -164,7 +165,7 @@ void getSignedURLWithCustomPolicy_withIpRangeOmitted_producesValidUrl() throws E
164
165
Instant activeDate = LocalDate .of (2022 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
165
166
Instant expirationDate = LocalDate .of (2024 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
166
167
CustomSignerRequest request = CustomSignerRequest .builder ()
167
- .resourceUrl (resourceUrl )
168
+ .resourceUrl (RESOURCE_URL )
168
169
.privateKey (keyFilePath )
169
170
.keyPairId ("keyPairId" )
170
171
.expirationDate (expirationDate )
@@ -186,7 +187,7 @@ void getSignedURLWithCustomPolicy_withActiveDateOmitted_producesValidUrl() throw
186
187
Instant expirationDate = LocalDate .of (2024 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
187
188
String ipRange = "1.2.3.4" ;
188
189
CustomSignerRequest request = CustomSignerRequest .builder ()
189
- .resourceUrl (resourceUrl )
190
+ .resourceUrl (RESOURCE_URL )
190
191
.privateKey (keyFilePath )
191
192
.keyPairId ("keyPairId" )
192
193
.expirationDate (expirationDate )
@@ -207,7 +208,7 @@ void getSignedURLWithCustomPolicy_withActiveDateOmitted_producesValidUrl() throw
207
208
void getSignedURLWithCustomPolicy_withMissingExpirationDate_shouldThrowException () {
208
209
SdkClientException exception = assertThrows (SdkClientException .class , () ->
209
210
cloudFrontUtilities .getSignedUrlWithCustomPolicy (r -> r
210
- .resourceUrl (resourceUrl )
211
+ .resourceUrl (RESOURCE_URL )
211
212
.privateKey (keyPair .getPrivate ())
212
213
.keyPairId ("keyPairId" ))
213
214
);
@@ -260,17 +261,41 @@ void getSignedURLWithCustomPolicy_withEncodedUrl_doesNotDecodeUrl() {
260
261
assertThat (expected ).isEqualTo (url );
261
262
}
262
263
264
+ @ Test
265
+ void getSignedURLWithCannedPolicy_withPortNumber_returnsPortNumber () {
266
+ Instant expirationDate = LocalDate .of (2024 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
267
+ SignedUrl signedUrl =
268
+ cloudFrontUtilities .getSignedUrlWithCannedPolicy (r -> r
269
+ .resourceUrl (RESOURCE_URL_WITH_PORT )
270
+ .privateKey (keyPair .getPrivate ())
271
+ .keyPairId ("keyPairId" )
272
+ .expirationDate (expirationDate ));
273
+ assertThat (signedUrl .url ()).contains ("65535" );
274
+ }
275
+
276
+ @ Test
277
+ void getSignedURLWithCustomPolicy_withPortNumber_returnsPortNumber () {
278
+ Instant expirationDate = LocalDate .of (2024 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
279
+ SignedUrl signedUrl =
280
+ cloudFrontUtilities .getSignedUrlWithCustomPolicy (r -> r
281
+ .resourceUrl (RESOURCE_URL_WITH_PORT )
282
+ .privateKey (keyPair .getPrivate ())
283
+ .keyPairId ("keyPairId" )
284
+ .expirationDate (expirationDate ));
285
+ assertThat (signedUrl .url ()).contains ("65535" );
286
+ }
287
+
263
288
@ Test
264
289
void getCookiesForCannedPolicy_producesValidCookies () throws Exception {
265
290
Instant expirationDate = LocalDate .of (2024 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
266
291
CannedSignerRequest request = CannedSignerRequest .builder ()
267
- .resourceUrl (resourceUrl )
292
+ .resourceUrl (RESOURCE_URL )
268
293
.privateKey (keyFilePath )
269
294
.keyPairId ("keyPairId" )
270
295
.expirationDate (expirationDate )
271
296
.build ();
272
297
CookiesForCannedPolicy cookiesForCannedPolicy = cloudFrontUtilities .getCookiesForCannedPolicy (request );
273
- assertThat (cookiesForCannedPolicy .resourceUrl ()).isEqualTo (resourceUrl );
298
+ assertThat (cookiesForCannedPolicy .resourceUrl ()).isEqualTo (RESOURCE_URL );
274
299
assertThat (cookiesForCannedPolicy .keyPairIdHeaderValue ()).isEqualTo ("CloudFront-Key-Pair-Id=keyPairId" );
275
300
}
276
301
@@ -280,29 +305,29 @@ void getCookiesForCustomPolicy_producesValidCookies() throws Exception {
280
305
Instant expirationDate = LocalDate .of (2024 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
281
306
String ipRange = "1.2.3.4" ;
282
307
CustomSignerRequest request = CustomSignerRequest .builder ()
283
- .resourceUrl (resourceUrl )
308
+ .resourceUrl (RESOURCE_URL )
284
309
.privateKey (keyFilePath )
285
310
.keyPairId ("keyPairId" )
286
311
.expirationDate (expirationDate )
287
312
.activeDate (activeDate )
288
313
.ipRange (ipRange )
289
314
.build ();
290
315
CookiesForCustomPolicy cookiesForCustomPolicy = cloudFrontUtilities .getCookiesForCustomPolicy (request );
291
- assertThat (cookiesForCustomPolicy .resourceUrl ()).isEqualTo (resourceUrl );
316
+ assertThat (cookiesForCustomPolicy .resourceUrl ()).isEqualTo (RESOURCE_URL );
292
317
assertThat (cookiesForCustomPolicy .keyPairIdHeaderValue ()).isEqualTo ("CloudFront-Key-Pair-Id=keyPairId" );
293
318
}
294
319
295
320
@ Test
296
321
void getCookiesForCustomPolicy_withActiveDateAndIpRangeOmitted_producesValidCookies () {
297
322
Instant expirationDate = LocalDate .of (2024 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
298
323
CustomSignerRequest request = CustomSignerRequest .builder ()
299
- .resourceUrl (resourceUrl )
324
+ .resourceUrl (RESOURCE_URL )
300
325
.privateKey (keyPair .getPrivate ())
301
326
.keyPairId ("keyPairId" )
302
327
.expirationDate (expirationDate )
303
328
.build ();
304
329
CookiesForCustomPolicy cookiesForCustomPolicy = cloudFrontUtilities .getCookiesForCustomPolicy (request );
305
- assertThat (cookiesForCustomPolicy .resourceUrl ()).isEqualTo (resourceUrl );
330
+ assertThat (cookiesForCustomPolicy .resourceUrl ()).isEqualTo (RESOURCE_URL );
306
331
assertThat (cookiesForCustomPolicy .keyPairIdHeaderValue ()).isEqualTo ("CloudFront-Key-Pair-Id=keyPairId" );
307
332
}
308
333
0 commit comments