Skip to content

Commit 3b195fe

Browse files
committed
chore: add some request validation to readSession
1 parent ae31163 commit 3b195fe

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/StorageDataClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.google.cloud.storage;
1818

19+
import static com.google.common.base.Preconditions.checkArgument;
20+
1921
import com.google.api.core.ApiFuture;
2022
import com.google.api.gax.grpc.GrpcCallContext;
2123
import com.google.cloud.storage.GrpcUtils.ZeroCopyBidiStreamingCallable;
@@ -44,12 +46,15 @@ private StorageDataClient(
4446
}
4547

4648
ApiFuture<ObjectReadSession> readSession(BidiReadObjectRequest req, GrpcCallContext ctx) {
47-
// todo limit reads being included
49+
checkArgument(
50+
req.getReadRangesList().isEmpty(),
51+
"ranged included in the initial request are not supported");
4852
return ObjectReadSessionImpl.create(req, ctx, read, executor, retryContextProvider);
4953
}
5054

5155
@Override
5256
public void close() throws IOException {
57+
//noinspection EmptyTryBlock
5358
try (IOAutoCloseable ignore = onClose) {
5459
// intentional
5560
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.storage;
18+
19+
import static org.junit.Assert.assertThrows;
20+
21+
import com.google.api.gax.grpc.GrpcCallContext;
22+
import com.google.storage.v2.BidiReadObjectRequest;
23+
import com.google.storage.v2.ReadRange;
24+
import java.io.IOException;
25+
import org.junit.Test;
26+
27+
public final class StorageDataClientTest {
28+
29+
@Test
30+
public void readSession_requestWithRangeRead_noAllowed() throws IOException {
31+
try (StorageDataClient dc =
32+
StorageDataClient.create(null, null, null, IOAutoCloseable.noOp())) {
33+
assertThrows(
34+
IllegalArgumentException.class,
35+
() -> {
36+
BidiReadObjectRequest req =
37+
BidiReadObjectRequest.newBuilder()
38+
.addReadRanges(ReadRange.newBuilder().setReadId(1))
39+
.build();
40+
dc.readSession(req, GrpcCallContext.createDefault());
41+
});
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)