Skip to content

Commit f8cad99

Browse files
authored
chore(test): expand StorageInstance vetoing to apply to bucket acl operations (#1819)
* chore(test): simplify StorageInstance vetoing implementation Rather than using a runtime proxy to do invocation method argument matching we are now defining a concrete class to override the methods it needs to provide enforcement for. This is simpler in that it uses standard java language implementation approach which is helped by compiler and IDEs. It is at the expense of needing to define the new ~500 line AbstractStorageDecorator class. * test: veto attempts to mutate bucket default acls * test: veto attempts to mutate bucket acls * test: veto lockRetentionPolicy
1 parent 96beca2 commit f8cad99

File tree

3 files changed

+606
-138
lines changed

3 files changed

+606
-138
lines changed

google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITAccessTest.java

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.google.cloud.storage.Acl.Role;
3636
import com.google.cloud.storage.Acl.User;
3737
import com.google.cloud.storage.Blob;
38-
import com.google.cloud.storage.BlobId;
3938
import com.google.cloud.storage.BlobInfo;
4039
import com.google.cloud.storage.Bucket;
4140
import com.google.cloud.storage.BucketInfo;
@@ -45,7 +44,6 @@
4544
import com.google.cloud.storage.Storage.BlobTargetOption;
4645
import com.google.cloud.storage.Storage.BucketField;
4746
import com.google.cloud.storage.Storage.BucketGetOption;
48-
import com.google.cloud.storage.Storage.BucketSourceOption;
4947
import com.google.cloud.storage.Storage.BucketTargetOption;
5048
import com.google.cloud.storage.StorageException;
5149
import com.google.cloud.storage.StorageRoles;
@@ -63,7 +61,6 @@
6361
import java.time.Duration;
6462
import java.util.ArrayList;
6563
import java.util.Collections;
66-
import java.util.HashSet;
6764
import java.util.Iterator;
6865
import java.util.List;
6966
import java.util.Map;
@@ -97,37 +94,6 @@ public class ITAccessTest {
9794

9895
@Inject public Generator generator;
9996

100-
@Test
101-
@CrossRun.Ignore(transports = Transport.GRPC)
102-
public void bucketAcl_requesterPays_true() {
103-
String projectId = storage.getOptions().getProjectId();
104-
testBucketAclRequesterPays(requesterPaysBucket, BucketSourceOption.userProject(projectId));
105-
}
106-
107-
@Test
108-
@CrossRun.Ignore(transports = Transport.GRPC)
109-
public void bucketAcl_requesterPays_false() {
110-
testBucketAclRequesterPays(bucket);
111-
}
112-
113-
private void testBucketAclRequesterPays(
114-
BucketInfo bucket, Storage.BucketSourceOption... bucketOptions) {
115-
// TODO: break into individual tests
116-
assertNull(storage.getAcl(bucket.getName(), User.ofAllAuthenticatedUsers(), bucketOptions));
117-
assertFalse(storage.deleteAcl(bucket.getName(), User.ofAllAuthenticatedUsers(), bucketOptions));
118-
Acl acl = Acl.of(User.ofAllAuthenticatedUsers(), Role.READER);
119-
assertNotNull(storage.createAcl(bucket.getName(), acl, bucketOptions));
120-
Acl updatedAcl =
121-
storage.updateAcl(
122-
bucket.getName(), acl.toBuilder().setRole(Role.WRITER).build(), bucketOptions);
123-
assertEquals(Role.WRITER, updatedAcl.getRole());
124-
Set<Acl> acls = new HashSet<>();
125-
acls.addAll(storage.listAcls(bucket.getName(), bucketOptions));
126-
assertTrue(acls.contains(updatedAcl));
127-
assertTrue(storage.deleteAcl(bucket.getName(), User.ofAllAuthenticatedUsers(), bucketOptions));
128-
assertNull(storage.getAcl(bucket.getName(), User.ofAllAuthenticatedUsers(), bucketOptions));
129-
}
130-
13197
@Test
13298
public void bucket_defaultAcl_get() {
13399
String bucketName = bucket.getName();
@@ -1061,68 +1027,6 @@ public void testEnableAndDisableBucketPolicyOnlyOnExistingBucket() throws Except
10611027
}
10621028
}
10631029

1064-
@Test
1065-
@CrossRun.Ignore(transports = Transport.GRPC)
1066-
public void testBlobAcl() {
1067-
// TODO: break this test up into each of the respective scenarios
1068-
// 1. get ACL for specific entity
1069-
// 2. Create an ACL for specific entity
1070-
// 3. Update ACL to change role of a specific entity
1071-
// 4. List ACLs for an object
1072-
// 5. Delete an ACL for a specific entity
1073-
// 6. Attempt to get an acl for an object that doesn't exist
1074-
// 7. Attempt to delete an acl for an object that doesn't exist
1075-
// 8. Attempt to create an acl for an object that doesn't exist
1076-
// 9. Attempt to update an acl for an object that doesn't exist
1077-
// 10. Attempt to list acls for an object that doesn't exist
1078-
BlobId blobId = BlobId.of(bucket.getName(), "test-blob-acl");
1079-
BlobInfo blob = BlobInfo.newBuilder(blobId).build();
1080-
storage.create(blob);
1081-
assertNull(storage.getAcl(blobId, User.ofAllAuthenticatedUsers()));
1082-
Acl acl = Acl.of(User.ofAllAuthenticatedUsers(), Role.READER);
1083-
assertNotNull(storage.createAcl(blobId, acl));
1084-
Acl updatedAcl = storage.updateAcl(blobId, acl.toBuilder().setRole(Role.OWNER).build());
1085-
assertEquals(Role.OWNER, updatedAcl.getRole());
1086-
Set<Acl> acls = new HashSet<>(storage.listAcls(blobId));
1087-
assertTrue(acls.contains(updatedAcl));
1088-
assertTrue(storage.deleteAcl(blobId, User.ofAllAuthenticatedUsers()));
1089-
assertNull(storage.getAcl(blobId, User.ofAllAuthenticatedUsers()));
1090-
// test non-existing blob
1091-
BlobId otherBlobId = BlobId.of(bucket.getName(), "test-blob-acl", -1L);
1092-
try {
1093-
assertNull(storage.getAcl(otherBlobId, User.ofAllAuthenticatedUsers()));
1094-
fail("Expected an 'Invalid argument' exception");
1095-
} catch (StorageException e) {
1096-
assertThat(e.getMessage()).contains("Invalid argument");
1097-
}
1098-
1099-
try {
1100-
assertFalse(storage.deleteAcl(otherBlobId, User.ofAllAuthenticatedUsers()));
1101-
fail("Expected an 'Invalid argument' exception");
1102-
} catch (StorageException e) {
1103-
assertThat(e.getMessage()).contains("Invalid argument");
1104-
}
1105-
1106-
try {
1107-
storage.createAcl(otherBlobId, acl);
1108-
fail("Expected StorageException");
1109-
} catch (StorageException ex) {
1110-
// expected
1111-
}
1112-
try {
1113-
storage.updateAcl(otherBlobId, acl);
1114-
fail("Expected StorageException");
1115-
} catch (StorageException ex) {
1116-
// expected
1117-
}
1118-
try {
1119-
storage.listAcls(otherBlobId);
1120-
fail("Expected StorageException");
1121-
} catch (StorageException ex) {
1122-
// expected
1123-
}
1124-
}
1125-
11261030
static ImmutableList<Acl> dropEtags(List<Acl> defaultAcls) {
11271031
return defaultAcls.stream()
11281032
.map(ITAccessTest::dropEtag)

0 commit comments

Comments
 (0)