|
66 | 66 | import com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleAction;
|
67 | 67 | import com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleCondition;
|
68 | 68 | import com.google.cloud.storage.CopyWriter;
|
| 69 | +import com.google.cloud.storage.Cors; |
69 | 70 | import com.google.cloud.storage.HmacKey;
|
70 | 71 | import com.google.cloud.storage.HttpMethod;
|
71 | 72 | import com.google.cloud.storage.PostPolicyV4;
|
@@ -3474,4 +3475,50 @@ public void testAutoContentTypeCreateFrom() throws IOException {
|
3474 | 3475 | public void testAutoContentTypeWriter() throws IOException {
|
3475 | 3476 | testAutoContentType("writer");
|
3476 | 3477 | }
|
| 3478 | + |
| 3479 | + @Test |
| 3480 | + public void testRemoveBucketCORS() throws ExecutionException, InterruptedException { |
| 3481 | + String bucketName = RemoteStorageHelper.generateBucketName(); |
| 3482 | + List<Cors.Origin> origins = ImmutableList.of(Cors.Origin.of("http://cloud.google.com")); |
| 3483 | + List<HttpMethod> httpMethods = ImmutableList.of(HttpMethod.GET); |
| 3484 | + List<String> responseHeaders = ImmutableList.of("Content-Type"); |
| 3485 | + try { |
| 3486 | + Cors cors = |
| 3487 | + Cors.newBuilder() |
| 3488 | + .setOrigins(origins) |
| 3489 | + .setMethods(httpMethods) |
| 3490 | + .setResponseHeaders(responseHeaders) |
| 3491 | + .setMaxAgeSeconds(100) |
| 3492 | + .build(); |
| 3493 | + storage.create(BucketInfo.newBuilder(bucketName).setCors(ImmutableList.of(cors)).build()); |
| 3494 | + |
| 3495 | + // case-1 : Cors are set and field selector is selected then returns not-null. |
| 3496 | + Bucket remoteBucket = |
| 3497 | + storage.get(bucketName, Storage.BucketGetOption.fields(BucketField.CORS)); |
| 3498 | + assertThat(remoteBucket.getCors()).isNotNull(); |
| 3499 | + assertThat(remoteBucket.getCors().get(0).getMaxAgeSeconds()).isEqualTo(100); |
| 3500 | + assertThat(remoteBucket.getCors().get(0).getMethods()).isEqualTo(httpMethods); |
| 3501 | + assertThat(remoteBucket.getCors().get(0).getOrigins()).isEqualTo(origins); |
| 3502 | + assertThat(remoteBucket.getCors().get(0).getResponseHeaders()).isEqualTo(responseHeaders); |
| 3503 | + |
| 3504 | + // case-2 : Cors are set but field selector isn't selected then returns not-null. |
| 3505 | + remoteBucket = storage.get(bucketName); |
| 3506 | + assertThat(remoteBucket.getCors()).isNotNull(); |
| 3507 | + |
| 3508 | + // Remove CORS configuration from the bucket. |
| 3509 | + Bucket updatedBucket = remoteBucket.toBuilder().setCors(null).build().update(); |
| 3510 | + assertThat(updatedBucket.getCors()).isNull(); |
| 3511 | + |
| 3512 | + // case-3 : Cors are not set and field selector is selected then returns null. |
| 3513 | + updatedBucket = storage.get(bucketName, Storage.BucketGetOption.fields(BucketField.CORS)); |
| 3514 | + assertThat(updatedBucket.getCors()).isNull(); |
| 3515 | + |
| 3516 | + // case-4 : Cors are not set and field selector isn't selected then returns null. |
| 3517 | + updatedBucket = storage.get(bucketName); |
| 3518 | + assertThat(updatedBucket.getCors()).isNull(); |
| 3519 | + |
| 3520 | + } finally { |
| 3521 | + RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS); |
| 3522 | + } |
| 3523 | + } |
3477 | 3524 | }
|
0 commit comments