16
16
package software .amazon .awssdk .services .cloudfront ;
17
17
18
18
import static org .assertj .core .api .Assertions .assertThat ;
19
- import static software .amazon .awssdk .services .cloudfront .utils .CloudFrontSignedCookie .getCookiesForCannedPolicy ;
20
- import static software .amazon .awssdk .services .cloudfront .utils .CloudFrontSignedCookie .getCookiesForCustomPolicy ;
21
- import static software .amazon .awssdk .services .cloudfront .utils .CloudFrontSignedUrl .getSignedUrlWithCannedPolicy ;
22
- import static software .amazon .awssdk .services .cloudfront .utils .CloudFrontSignedUrl .getSignedUrlWithCustomPolicy ;
23
- import static software .amazon .awssdk .services .cloudfront .utils .CloudFrontSignerUtils .generateResourceUrl ;
24
19
25
20
import java .io .File ;
26
21
import java .io .FileWriter ;
80
75
import software .amazon .awssdk .services .cloudfront .model .TrustedKeyGroups ;
81
76
import software .amazon .awssdk .services .cloudfront .model .UpdateDistributionResponse ;
82
77
import software .amazon .awssdk .services .cloudfront .model .ViewerProtocolPolicy ;
78
+ import software .amazon .awssdk .services .cloudfront .utils .CloudFrontSignedCookie ;
79
+ import software .amazon .awssdk .services .cloudfront .utils .CloudFrontSignedUrl ;
80
+ import software .amazon .awssdk .services .cloudfront .utils .CloudFrontSignerUtils ;
83
81
import software .amazon .awssdk .services .cloudfront .utils .CloudFrontSignedCookie .CookiesForCannedPolicy ;
84
82
import software .amazon .awssdk .services .cloudfront .utils .CloudFrontSignedCookie .CookiesForCustomPolicy ;
85
83
import software .amazon .awssdk .services .cloudfront .utils .CloudFrontSignerUtils .Protocol ;
@@ -127,7 +125,7 @@ public static void tearDown() throws InterruptedException {
127
125
128
126
@ Test
129
127
void unsignedUrl_shouldReturn403Response () throws Exception {
130
- String unsignedUrl = generateResourceUrl (Protocol .HTTPS , domainName , s3ObjectKey );
128
+ String unsignedUrl = CloudFrontSignerUtils . generateResourceUrl (Protocol .HTTPS , domainName , s3ObjectKey );
131
129
SdkHttpClient client = ApacheHttpClient .create ();
132
130
HttpExecuteResponse response =
133
131
client .prepareRequest (HttpExecuteRequest .builder ()
@@ -146,7 +144,8 @@ void unsignedUrl_shouldReturn403Response() throws Exception {
146
144
void getSignedUrlWithCannedPolicy_shouldWork () throws Exception {
147
145
InputStream originalBucketContent = s3Client .getObject (GetObjectRequest .builder ().bucket (bucketName ).key (s3ObjectKey ).build ());
148
146
ZonedDateTime expirationDate = ZonedDateTime .of (2050 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
149
- String signedUrl = getSignedUrlWithCannedPolicy (Protocol .HTTPS , domainName , s3ObjectKey , keyFile , publicKeyId , expirationDate );
147
+ String signedUrl = CloudFrontSignedUrl .getSignedUrlWithCannedPolicy (Protocol .HTTPS , domainName , s3ObjectKey , keyFile ,
148
+ publicKeyId , expirationDate );
150
149
String encodedPath = signedUrl .substring (signedUrl .indexOf ("s3ObjectKey" ));
151
150
SdkHttpClient client = ApacheHttpClient .create ();
152
151
HttpExecuteResponse response =
@@ -168,7 +167,8 @@ void getSignedUrlWithCannedPolicy_shouldWork() throws Exception {
168
167
@ Test
169
168
void getSignedUrlWithCannedPolicy_withExpiredDate_shouldReturn403Response () throws Exception {
170
169
ZonedDateTime expirationDate = ZonedDateTime .of (2020 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
171
- String signedUrl = getSignedUrlWithCannedPolicy (Protocol .HTTPS , domainName , s3ObjectKey , keyFile , publicKeyId , expirationDate );
170
+ String signedUrl = CloudFrontSignedUrl .getSignedUrlWithCannedPolicy (Protocol .HTTPS , domainName , s3ObjectKey , keyFile ,
171
+ publicKeyId , expirationDate );
172
172
String encodedPath = signedUrl .substring (signedUrl .indexOf ("s3ObjectKey" ));
173
173
SdkHttpClient client = ApacheHttpClient .create ();
174
174
HttpExecuteResponse response =
@@ -189,7 +189,8 @@ void getSignedUrlWithCustomPolicy_shouldWork() throws Exception {
189
189
InputStream originalBucketContent = s3Client .getObject (GetObjectRequest .builder ().bucket (bucketName ).key (s3ObjectKey ).build ());
190
190
ZonedDateTime activeDate = ZonedDateTime .of (2020 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
191
191
ZonedDateTime expirationDate = ZonedDateTime .of (2050 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
192
- String signedUrl = getSignedUrlWithCustomPolicy (Protocol .HTTPS , domainName , s3ObjectKey , keyFile , publicKeyId , activeDate , expirationDate , null );
192
+ String signedUrl = CloudFrontSignedUrl .getSignedUrlWithCustomPolicy (Protocol .HTTPS , domainName , s3ObjectKey , keyFile ,
193
+ publicKeyId , activeDate , expirationDate , null );
193
194
String encodedPath = signedUrl .substring (signedUrl .indexOf ("s3ObjectKey" ));
194
195
SdkHttpClient client = ApacheHttpClient .create ();
195
196
HttpExecuteResponse response =
@@ -212,7 +213,8 @@ void getSignedUrlWithCustomPolicy_shouldWork() throws Exception {
212
213
void getSignedUrlWithCustomPolicy_withFutureActiveDate_shouldReturn403Response () throws Exception {
213
214
ZonedDateTime activeDate = ZonedDateTime .of (2040 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
214
215
ZonedDateTime expirationDate = ZonedDateTime .of (2050 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
215
- String signedUrl = getSignedUrlWithCustomPolicy (Protocol .HTTPS , domainName , s3ObjectKey , keyFile , publicKeyId , activeDate , expirationDate , null );
216
+ String signedUrl = CloudFrontSignedUrl .getSignedUrlWithCustomPolicy (Protocol .HTTPS , domainName , s3ObjectKey , keyFile ,
217
+ publicKeyId , activeDate , expirationDate , null );
216
218
String encodedPath = signedUrl .substring (signedUrl .indexOf ("s3ObjectKey" ));
217
219
SdkHttpClient client = ApacheHttpClient .create ();
218
220
HttpExecuteResponse response =
@@ -232,8 +234,9 @@ void getSignedUrlWithCustomPolicy_withFutureActiveDate_shouldReturn403Response()
232
234
void getCookiesForCannedPolicy_shouldWork () throws Exception {
233
235
InputStream originalBucketContent = s3Client .getObject (GetObjectRequest .builder ().bucket (bucketName ).key (s3ObjectKey ).build ());
234
236
ZonedDateTime expirationDate = ZonedDateTime .of (2050 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
235
- CookiesForCannedPolicy cookies = getCookiesForCannedPolicy (Protocol .HTTPS , domainName , s3ObjectKey , keyFile , publicKeyId , expirationDate );
236
- String encodedPath = generateResourceUrl (Protocol .HTTPS , domainName , s3ObjectKey );
237
+ CookiesForCannedPolicy cookies = CloudFrontSignedCookie .getCookiesForCannedPolicy (Protocol .HTTPS , domainName ,
238
+ s3ObjectKey , keyFile , publicKeyId , expirationDate );
239
+ String encodedPath = CloudFrontSignerUtils .generateResourceUrl (Protocol .HTTPS , domainName , s3ObjectKey );
237
240
238
241
SdkHttpClient client = ApacheHttpClient .create ();
239
242
HttpExecuteResponse response =
@@ -259,8 +262,9 @@ void getCookiesForCannedPolicy_shouldWork() throws Exception {
259
262
@ Test
260
263
void getCookiesForCannedPolicy_withExpiredDate_shouldReturn403Response () throws Exception {
261
264
ZonedDateTime expirationDate = ZonedDateTime .of (2020 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
262
- CookiesForCannedPolicy cookies = getCookiesForCannedPolicy (Protocol .HTTPS , domainName , s3ObjectKey , keyFile , publicKeyId , expirationDate );
263
- String encodedPath = generateResourceUrl (Protocol .HTTPS , domainName , s3ObjectKey );
265
+ CookiesForCannedPolicy cookies = CloudFrontSignedCookie .getCookiesForCannedPolicy (Protocol .HTTPS , domainName , s3ObjectKey ,
266
+ keyFile , publicKeyId , expirationDate );
267
+ String encodedPath = CloudFrontSignerUtils .generateResourceUrl (Protocol .HTTPS , domainName , s3ObjectKey );
264
268
265
269
SdkHttpClient client = ApacheHttpClient .create ();
266
270
HttpExecuteResponse response =
@@ -285,8 +289,9 @@ void getCookiesForCustomPolicy_shouldWork() throws Exception {
285
289
InputStream originalBucketContent = s3Client .getObject (GetObjectRequest .builder ().bucket (bucketName ).key (s3ObjectKey ).build ());
286
290
ZonedDateTime activeDate = ZonedDateTime .of (2020 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
287
291
ZonedDateTime expirationDate = ZonedDateTime .of (2050 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
288
- CookiesForCustomPolicy cookies = getCookiesForCustomPolicy (Protocol .HTTPS , domainName , s3ObjectKey , keyFile , publicKeyId , activeDate , expirationDate , null );
289
- String encodedPath = generateResourceUrl (Protocol .HTTPS , domainName , s3ObjectKey );
292
+ CookiesForCustomPolicy cookies = CloudFrontSignedCookie .getCookiesForCustomPolicy (Protocol .HTTPS , domainName , s3ObjectKey ,
293
+ keyFile , publicKeyId , activeDate , expirationDate , null );
294
+ String encodedPath = CloudFrontSignerUtils .generateResourceUrl (Protocol .HTTPS , domainName , s3ObjectKey );
290
295
291
296
SdkHttpClient client = ApacheHttpClient .create ();
292
297
HttpExecuteResponse response =
@@ -313,8 +318,9 @@ void getCookiesForCustomPolicy_shouldWork() throws Exception {
313
318
void getCookiesForCustomPolicy_withFutureActiveDate_shouldReturn403Response () throws Exception {
314
319
ZonedDateTime activeDate = ZonedDateTime .of (2040 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
315
320
ZonedDateTime expirationDate = ZonedDateTime .of (2050 , 1 , 1 , 0 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
316
- CookiesForCustomPolicy cookies = getCookiesForCustomPolicy (Protocol .HTTPS , domainName , s3ObjectKey , keyFile , publicKeyId , activeDate , expirationDate , null );
317
- String encodedPath = generateResourceUrl (Protocol .HTTPS , domainName , s3ObjectKey );
321
+ CookiesForCustomPolicy cookies = CloudFrontSignedCookie .getCookiesForCustomPolicy (Protocol .HTTPS , domainName , s3ObjectKey ,
322
+ keyFile , publicKeyId , activeDate , expirationDate , null );
323
+ String encodedPath = CloudFrontSignerUtils .generateResourceUrl (Protocol .HTTPS , domainName , s3ObjectKey );
318
324
319
325
SdkHttpClient client = ApacheHttpClient .create ();
320
326
HttpExecuteResponse response =
0 commit comments