Skip to content
Merged
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 @@ -16,6 +16,7 @@

package com.google.cloud.bigquery.jdbc;

import com.google.cloud.bigquery.jdbc.utils.TestUtilities;
import com.google.cloud.bigquery.jdbc.utils.URIBuilder;

public class BigQueryJdbcBaseTest {
Expand Down Expand Up @@ -43,7 +44,7 @@ public class BigQueryJdbcBaseTest {
"-----END PRIVATE KEY-----";

protected static URIBuilder getBaseUri() {
return new URIBuilder("jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;");
return new URIBuilder(TestUtilities.getBaseConnectionUrl());
}

protected static URIBuilder getBaseUri(int authType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void testValidServiceAccountAuthentication() throws SQLException, IOExcep
Files.write(tempFile.toPath(), authJson.toString().getBytes());

String connection_uri =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
getBaseConnectionUrl()
+ "ProjectId="
+ authJson.get("project_id").getAsString()
+ ";OAuthType=0;"
Expand All @@ -104,11 +104,7 @@ public void testValidServiceAccountAuthentication() throws SQLException, IOExcep

@Test
public void testServiceAccountAuthenticationMissingOAuthPvtKeyPath() throws SQLException {
String connection_uri =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
+ "ProjectId="
+ PROJECT_ID
+ ";OAuthType=0;";
String connection_uri = getBaseConnectionUrl() + "ProjectId=" + PROJECT_ID + ";OAuthType=0;";

try {
DriverManager.getConnection(connection_uri);
Expand All @@ -127,7 +123,7 @@ public void testValidServiceAccountAuthenticationOAuthPvtKeyAsPath()
Files.write(tempFile.toPath(), authJson.toString().getBytes());

String connection_uri =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
getBaseConnectionUrl()
+ "ProjectId="
+ authJson.get("project_id").getAsString()
+ ";OAuthType=0;"
Expand All @@ -144,7 +140,7 @@ public void testValidServiceAccountAuthenticationViaEmailAndPkcs8Key()
final JsonObject authJson = getAuthJson();

String connection_uri =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
getBaseConnectionUrl()
+ "ProjectId="
+ authJson.get("project_id").getAsString()
+ ";OAuthType=0;"
Expand All @@ -162,7 +158,7 @@ public void testValidServiceAccountAuthenticationOAuthPvtKeyAsJson()
final JsonObject authJson = getAuthJson();

String connection_uri =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
getBaseConnectionUrl()
+ "ProjectId="
+ authJson.get("project_id").getAsString()
+ ";OAuthType=0;"
Expand Down Expand Up @@ -192,9 +188,12 @@ public void testValidServiceAccountAuthenticationP12() throws SQLException, IOEx
@Disabled
public void testValidGoogleUserAccountAuthentication() throws SQLException {
String connection_uri =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID="
getBaseConnectionUrl()
+ "PROJECTID="
+ PROJECT_ID
+ ";OAuthType=1;OAuthClientId=client_id;OAuthClientSecret=client_secret;";
+ ";OAuthType=1;"
+ "OAuthClientId=client_id;"
+ "OAuthClientSecret=client_secret;";

Connection connection = DriverManager.getConnection(connection_uri);
assertNotNull(connection);
Expand All @@ -213,12 +212,15 @@ public void testValidGoogleUserAccountAuthentication() throws SQLException {
@Disabled
public void testValidExternalAccountAuthentication() throws SQLException {
String connection_uri =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID="
getBaseConnectionUrl()
+ "PROJECTID="
+ PROJECT_ID
+ ";OAUTHTYPE=4;"
+ "BYOID_AudienceUri=//iam.googleapis.com/projects/<project>/locations/<location>/workloadIdentityPools/<pool>/providers/<provider>;"
+ "BYOID_SubjectTokenType=<type>;BYOID_CredentialSource={\"file\":\"/path/to/file\"};"
+ "BYOID_SA_Impersonation_Uri=<sa>;BYOID_TokenUri=<uri>;";
+ "BYOID_SubjectTokenType=<type>;"
+ "BYOID_CredentialSource={\"file\":\"/path/to/file\"};"
+ "BYOID_SA_Impersonation_Uri=<sa>;"
+ "BYOID_TokenUri=<uri>;";

Connection connection = DriverManager.getConnection(connection_uri);
assertNotNull(connection);
Expand All @@ -237,7 +239,8 @@ public void testValidExternalAccountAuthentication() throws SQLException {
@Disabled
public void testValidExternalAccountAuthenticationFromFile() throws SQLException {
String connection_uri =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID="
getBaseConnectionUrl()
+ "PROJECTID="
+ PROJECT_ID
+ ";OAUTHTYPE=4;"
+ "OAuthPvtKeyPath=/path/to/file;";
Expand All @@ -259,9 +262,11 @@ public void testValidExternalAccountAuthenticationFromFile() throws SQLException
@Disabled
public void testValidExternalAccountAuthenticationRawJson() throws SQLException {
String connection_uri =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID="
getBaseConnectionUrl()
+ "PROJECTID="
+ PROJECT_ID
+ ";OAUTHTYPE=4;OAuthPvtKey={\n"
+ ";OAUTHTYPE=4;"
+ "OAuthPvtKey={\n"
+ " \"universe_domain\": \"googleapis.com\",\n"
+ " \"type\": \"external_account\",\n"
+ " \"audience\":"
Expand Down Expand Up @@ -303,7 +308,8 @@ public void testValidPreGeneratedAccessTokenAuthentication(String scope, boolean
String accessToken = credentials.getAccessToken().getTokenValue();

String connectionUri =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId="
getBaseConnectionUrl()
+ "ProjectId="
+ authJson.get("project_id").getAsString()
+ ";OAuthType=2"
+ ";OAuthAccessToken="
Expand All @@ -319,10 +325,13 @@ public void testValidPreGeneratedAccessTokenAuthentication(String scope, boolean
@Disabled
public void testValidRefreshTokenAuthentication() throws SQLException {
String connection_uri =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID="
getBaseConnectionUrl()
+ "PROJECTID="
+ PROJECT_ID
+ ";OAUTHTYPE=2;OAuthRefreshToken=refresh_token;"
+ ";OAuthClientId=client;OAuthClientSecret=secret;";
+ ";OAUTHTYPE=2;"
+ "OAuthRefreshToken=refresh_token;"
+ ";OAuthClientId=client;"
+ "OAuthClientSecret=secret;";

Connection connection = DriverManager.getConnection(connection_uri);
assertNotNull(connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.QueryJobConfiguration;
import com.google.cloud.bigquery.jdbc.BigQueryJdbcBaseTest;
import com.google.cloud.bigquery.jdbc.utils.TestUtilities;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -177,10 +178,13 @@ private static void registerShutdownHook(final String dataset) {
}

public static final String DEFAULT_CATALOG = ServiceOptions.getDefaultProjectId();
public static String connectionUrl =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId="
+ DEFAULT_CATALOG
+ ";OAuthType=3;Timeout=3600;";

public static String getBaseConnectionUrl() {
return TestUtilities.getBaseConnectionUrl();
}

public static final String connectionUrl =
getBaseConnectionUrl() + "ProjectId=" + DEFAULT_CATALOG + ";OAuthType=3;Timeout=3600;";

public static final String createDatasetQuery =
"CREATE SCHEMA IF NOT EXISTS `%s.%s` OPTIONS(default_table_expiration_days = 5)";
Expand Down
Loading
Loading