Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,7 @@ public String open(Job loadJob) {

@InternalApi("internal to java-bigquery")
public String openSkipExceptionTranslation(Job loadJob) throws IOException {
validateRPC();
String builder = options.getResolvedApiaryHost("bigquery");
if (!builder.endsWith("/")) {
builder += "/";
Expand Down Expand Up @@ -2011,6 +2012,7 @@ public Job write(
public Job writeSkipExceptionTranslation(
String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length, boolean last)
throws IOException {
validateRPC();
if (length == 0) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.google.api.services.bigquery.model.TableDataInsertAllRequest;
import com.google.api.services.bigquery.model.TableReference;
import com.google.cloud.NoCredentials;
import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.DataFormatOptions;
import com.google.cloud.bigquery.DataFormatOptions.TimestampFormatOptions;
Expand Down Expand Up @@ -1814,4 +1815,88 @@ public void testExecuteWithSpan_IgnoresHttpResponseException() throws Exception
verifyNoSpans();
}
}

@Nested
class UniverseDomainValidationTests {

private HttpBigQueryRpc rpcWithMismatchedUniverseDomain;

/** Initializes an {@link HttpBigQueryRpc} with a mismatched universe domain configuration. */
@BeforeEach
public void setUp() {
setUpServer();
BigQueryOptions options =
BigQueryOptions.newBuilder()
.setProjectId(PROJECT_ID)
.setUniverseDomain("custom-universe.com")
.setCredentials(NoCredentials.getInstance())
.setTransportOptions(
BigQueryOptions.getDefaultHttpTransportOptions().toBuilder()
.setHttpTransportFactory(() -> mockTransport)
.build())
.build();
rpcWithMismatchedUniverseDomain = new HttpBigQueryRpc(options);
}

@Test
public void testOpenFailsOnMismatchedUniverseDomain() {
BigQueryException exception =
assertThrows(
BigQueryException.class, () -> rpcWithMismatchedUniverseDomain.open(new Job()));

assertEquals(401, exception.getCode());
assertNull(lastRequestUrl);
}

@Test
public void testOpenSkipExceptionTranslationFailsOnMismatchedUniverseDomain() {
BigQueryException exception =
assertThrows(
BigQueryException.class,
() -> rpcWithMismatchedUniverseDomain.openSkipExceptionTranslation(new Job()));

assertEquals(401, exception.getCode());
assertNull(lastRequestUrl);
}

@Test
public void testWriteFailsOnMismatchedUniverseDomain() {
BigQueryException exception =
assertThrows(
BigQueryException.class,
() ->
rpcWithMismatchedUniverseDomain.write(
"https://bigquery.googleapis.com/upload/bigquery/v2/projects/"
+ PROJECT_ID
+ "/jobs?uploadType=resumable",
new byte[] {1, 2, 3},
0,
0,
3,
true));

assertEquals(401, exception.getCode());
assertNull(lastRequestUrl);
}

@Test
public void testWriteSkipExceptionTranslationFailsOnMismatchedUniverseDomain() {
BigQueryException exception =
assertThrows(
BigQueryException.class,
() ->
rpcWithMismatchedUniverseDomain.writeSkipExceptionTranslation(
"https://bigquery.googleapis.com/upload/bigquery/v2/projects/"
+ PROJECT_ID
+ "/jobs?uploadType=resumable",
new byte[] {1, 2, 3},
0,
0,
3,
true));

assertEquals(401, exception.getCode());
assertNull(lastRequestUrl);
}
}
}
Loading