|
70 | 70 | import com.google.cloud.bigquery.jdbc.telemetry.v1.TelemetryManager; |
71 | 71 | import com.google.cloud.bigquery.jdbc.telemetry.v1.TelemetryPayload; |
72 | 72 | import com.google.cloud.bigquery.jdbc.telemetry.v1.TelemetryTestUtils; |
| 73 | +import com.google.cloud.bigquery.jdbc.utils.TestUtilities; |
73 | 74 | import com.google.cloud.bigquery.jdbc.utils.URIBuilder; |
74 | 75 | import com.google.cloud.bigquery.storage.v1.BigQueryReadClient; |
75 | 76 | import com.google.cloud.bigquery.storage.v1.BigQueryReadSettings; |
@@ -2088,32 +2089,84 @@ public void testConcurrentGetWarningsAndReset_neverThrowsIndexOutOfBounds() thro |
2088 | 2089 | @Test |
2089 | 2090 | public void testCreateTelemetryTransportConfig_propagatesConnectionTransportSettings() |
2090 | 2091 | throws Exception { |
| 2092 | + String trustStorePath = TestUtilities.getTestResourcePath("test_truststore_withpass.jks"); |
2091 | 2093 | String url = |
2092 | 2094 | getUriOAuthToken() |
2093 | 2095 | .append("ProjectId", "test-project") |
| 2096 | + .append("universeDomain", "apis-tpczero.goog") |
2094 | 2097 | .append("EndpointOverrides", "OAUTH2=https://oauth.custom.test/token") |
2095 | 2098 | .append("ProxyHost", "127.0.0.1") |
2096 | 2099 | .append("ProxyPort", "8080") |
2097 | 2100 | .append("ProxyUid", "puser") |
2098 | 2101 | .append("ProxyPwd", "ppass") |
| 2102 | + .append("SSLTrustStore", trustStorePath) |
| 2103 | + .append("SSLTrustStorePwd", "testpassword") |
| 2104 | + .append("SSLTrustStoreType", "JKS") |
2099 | 2105 | .toString(); |
2100 | 2106 |
|
2101 | 2107 | try (BigQueryConnection conn = new BigQueryConnection(url)) { |
2102 | 2108 | TelemetryTransportConfig config = conn.createTelemetryTransportConfig(); |
2103 | 2109 | assertEquals("test-project", config.projectId); |
2104 | 2110 | assertNotNull(config.fallbackCredentials); |
| 2111 | + assertEquals("apis-tpczero.goog", config.universeDomain); |
2105 | 2112 | assertEquals("https://oauth.custom.test/token", config.overrideProperties.get("OAUTH2")); |
| 2113 | + assertEquals("apis-tpczero.goog", config.overrideProperties.get("universeDomain")); |
2106 | 2114 | assertEquals( |
2107 | 2115 | BigQueryJdbcOAuthUtility.AuthType.PRE_GENERATED_TOKEN.name(), |
2108 | 2116 | config.authProperties.get(BigQueryJdbcUrlUtility.OAUTH_TYPE_PROPERTY_NAME)); |
2109 | 2117 | assertEquals("127.0.0.1", config.proxyProperties.get("ProxyHost")); |
2110 | 2118 | assertEquals("8080", config.proxyProperties.get("ProxyPort")); |
2111 | 2119 | assertEquals("puser", config.proxyProperties.get("ProxyUid")); |
2112 | 2120 | assertEquals("ppass", config.proxyProperties.get("ProxyPwd")); |
| 2121 | + assertEquals(trustStorePath, config.sslTrustStorePath); |
| 2122 | + assertEquals("testpassword", config.sslTrustStorePassword); |
| 2123 | + assertEquals("JKS", config.sslTrustStoreType); |
2113 | 2124 | assertNotNull(config.httpTransportFactory); |
2114 | 2125 | } |
2115 | 2126 | } |
2116 | 2127 |
|
| 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 | + |
2117 | 2170 | @Test |
2118 | 2171 | public void testConnect_unsupportedAuthTypeWithTraceExporterThrowsCheckedSqlException() |
2119 | 2172 | throws Exception { |
|
0 commit comments