@@ -214,6 +214,52 @@ void getSignedURLWithCustomPolicy_withMissingExpirationDate_shouldThrowException
214
214
assertThat (exception .getMessage ().contains ("Expiration date must be provided to sign CloudFront URLs" ));
215
215
}
216
216
217
+ @ Test
218
+ void getSignedURLWithCannedPolicy_withEncodedUrl_doesNotDecodeUrl () {
219
+ String encodedUrl = "https://distributionDomain/s3ObjectKey/%40blob?v=1n1dm%2F01n1dm0" ;
220
+ Instant expirationDate = LocalDate .of (2024 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
221
+ SignedUrl signedUrl =
222
+ cloudFrontUtilities .getSignedUrlWithCannedPolicy (r -> r
223
+ .resourceUrl (encodedUrl )
224
+ .privateKey (keyPair .getPrivate ())
225
+ .keyPairId ("keyPairId" )
226
+ .expirationDate (expirationDate ));
227
+ String url = signedUrl .url ();
228
+ String signature = url .substring (url .indexOf ("&Signature" ), url .indexOf ("&Key-Pair-Id" ));
229
+ String expected = "https://distributionDomain/s3ObjectKey/%40blob?v=1n1dm%2F01n1dm0&Expires=1704067200"
230
+ + signature
231
+ + "&Key-Pair-Id=keyPairId" ;
232
+ assertThat (expected ).isEqualTo (url );
233
+ }
234
+
235
+ @ Test
236
+ void getSignedURLWithCustomPolicy_withEncodedUrl_doesNotDecodeUrl () {
237
+ String encodedUrl = "https://distributionDomain/s3ObjectKey/%40blob?v=1n1dm%2F01n1dm0" ;
238
+ Instant activeDate = LocalDate .of (2022 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
239
+ Instant expirationDate = LocalDate .of (2024 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
240
+ String ipRange = "1.2.3.4" ;
241
+ SignedUrl signedUrl = cloudFrontUtilities .getSignedUrlWithCustomPolicy (r -> {
242
+ try {
243
+ r .resourceUrl (encodedUrl )
244
+ .privateKey (keyFilePath )
245
+ .keyPairId ("keyPairId" )
246
+ .expirationDate (expirationDate )
247
+ .activeDate (activeDate )
248
+ .ipRange (ipRange );
249
+ } catch (Exception e ) {
250
+ throw new RuntimeException (e );
251
+ }
252
+ });
253
+ String url = signedUrl .url ();
254
+ String policy = url .substring (url .indexOf ("Policy=" ) + 7 , url .indexOf ("&Signature" ));
255
+ String signature = url .substring (url .indexOf ("&Signature" ), url .indexOf ("&Key-Pair-Id" ));
256
+ String expected = "https://distributionDomain/s3ObjectKey/%40blob?v=1n1dm%2F01n1dm0&Policy="
257
+ + policy
258
+ + signature
259
+ + "&Key-Pair-Id=keyPairId" ;
260
+ assertThat (expected ).isEqualTo (url );
261
+ }
262
+
217
263
@ Test
218
264
void getCookiesForCannedPolicy_producesValidCookies () throws Exception {
219
265
Instant expirationDate = LocalDate .of (2024 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
0 commit comments