Skip to content

Commit 76ff29e

Browse files
test(bigquery-jdbc): verify universeDomain, proxy, and SSLTrustStore propagation in BigQueryConnectionTest
1 parent 6c50d41 commit 76ff29e

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

‎java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryConnectionTest.java‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import com.google.cloud.bigquery.jdbc.telemetry.v1.TelemetryManager;
7171
import com.google.cloud.bigquery.jdbc.telemetry.v1.TelemetryPayload;
7272
import com.google.cloud.bigquery.jdbc.telemetry.v1.TelemetryTestUtils;
73+
import com.google.cloud.bigquery.jdbc.utils.TestUtilities;
7374
import com.google.cloud.bigquery.jdbc.utils.URIBuilder;
7475
import com.google.cloud.bigquery.storage.v1.BigQueryReadClient;
7576
import com.google.cloud.bigquery.storage.v1.BigQueryReadSettings;
@@ -2088,32 +2089,84 @@ public void testConcurrentGetWarningsAndReset_neverThrowsIndexOutOfBounds() thro
20882089
@Test
20892090
public void testCreateTelemetryTransportConfig_propagatesConnectionTransportSettings()
20902091
throws Exception {
2092+
String trustStorePath = TestUtilities.getTestResourcePath("test_truststore_withpass.jks");
20912093
String url =
20922094
getUriOAuthToken()
20932095
.append("ProjectId", "test-project")
2096+
.append("universeDomain", "apis-tpczero.goog")
20942097
.append("EndpointOverrides", "OAUTH2=https://oauth.custom.test/token")
20952098
.append("ProxyHost", "127.0.0.1")
20962099
.append("ProxyPort", "8080")
20972100
.append("ProxyUid", "puser")
20982101
.append("ProxyPwd", "ppass")
2102+
.append("SSLTrustStore", trustStorePath)
2103+
.append("SSLTrustStorePwd", "testpassword")
2104+
.append("SSLTrustStoreType", "JKS")
20992105
.toString();
21002106

21012107
try (BigQueryConnection conn = new BigQueryConnection(url)) {
21022108
TelemetryTransportConfig config = conn.createTelemetryTransportConfig();
21032109
assertEquals("test-project", config.projectId);
21042110
assertNotNull(config.fallbackCredentials);
2111+
assertEquals("apis-tpczero.goog", config.universeDomain);
21052112
assertEquals("https://oauth.custom.test/token", config.overrideProperties.get("OAUTH2"));
2113+
assertEquals("apis-tpczero.goog", config.overrideProperties.get("universeDomain"));
21062114
assertEquals(
21072115
BigQueryJdbcOAuthUtility.AuthType.PRE_GENERATED_TOKEN.name(),
21082116
config.authProperties.get(BigQueryJdbcUrlUtility.OAUTH_TYPE_PROPERTY_NAME));
21092117
assertEquals("127.0.0.1", config.proxyProperties.get("ProxyHost"));
21102118
assertEquals("8080", config.proxyProperties.get("ProxyPort"));
21112119
assertEquals("puser", config.proxyProperties.get("ProxyUid"));
21122120
assertEquals("ppass", config.proxyProperties.get("ProxyPwd"));
2121+
assertEquals(trustStorePath, config.sslTrustStorePath);
2122+
assertEquals("testpassword", config.sslTrustStorePassword);
2123+
assertEquals("JKS", config.sslTrustStoreType);
21132124
assertNotNull(config.httpTransportFactory);
21142125
}
21152126
}
21162127

2128+
private static DataSource serviceAccountDataSource(
2129+
String email, String projectId, String universeDomain) throws Exception {
2130+
String saJson = buildServiceAccountJson(email, projectId, universeDomain).toString();
2131+
DataSource ds = DataSource.fromUrl(BASE_URL);
2132+
ds.setOAuthType(0);
2133+
ds.setOAuthServiceAcctEmail(email);
2134+
ds.setOAuthPvtKey(saJson);
2135+
ds.setProjectId(projectId);
2136+
return ds;
2137+
}
2138+
2139+
@Test
2140+
public void testConnect_authenticatedProxyWithTraceExporterThrowsCheckedSqlException()
2141+
throws Exception {
2142+
DataSource ds =
2143+
serviceAccountDataSource("sa@test-proj.iam.gserviceaccount.com", "test-proj", null);
2144+
ds.setProxyHost("127.0.0.1");
2145+
ds.setProxyPort("8080");
2146+
ds.setProxyUid("proxy-user");
2147+
ds.setProxyPwd("proxy-pass");
2148+
ds.setEnableGcpTraceExporter(true);
2149+
2150+
BigQueryJdbcException ex =
2151+
assertThrows(BigQueryJdbcException.class, () -> new BigQueryConnection(BASE_URL, ds));
2152+
assertTrue(ex.getMessage().contains("authenticated HTTP proxies"));
2153+
assertTrue(ex.getMessage().contains("useGlobalOpenTelemetry=true"));
2154+
}
2155+
2156+
@Test
2157+
public void testConnect_universeDomainMismatchWithTraceExporterThrowsCheckedSqlException()
2158+
throws Exception {
2159+
DataSource ds =
2160+
serviceAccountDataSource(
2161+
"sa@tpc-proj.iam.gserviceaccount.com", "tpc-proj", "apis-tpczero.goog");
2162+
ds.setEnableGcpTraceExporter(true);
2163+
2164+
BigQueryJdbcException ex =
2165+
assertThrows(BigQueryJdbcException.class, () -> new BigQueryConnection(BASE_URL, ds));
2166+
assertTrue(ex.getMessage().contains("googleapis.com"));
2167+
assertTrue(ex.getMessage().contains("apis-tpczero.goog"));
2168+
}
2169+
21172170
@Test
21182171
public void testConnect_unsupportedAuthTypeWithTraceExporterThrowsCheckedSqlException()
21192172
throws Exception {

0 commit comments

Comments
 (0)