Skip to content

Commit a3db96b

Browse files
committed
add unit tests
1 parent 773f1d3 commit a3db96b

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

java-bigquery/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOAuthUtilityTest.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public void testParseOAuthProperties_UserAccount_RequestDriveScopeEnabled() {
356356
"redactedClientSecret",
357357
properties.get(BigQueryJdbcUrlUtility.OAUTH_CLIENT_SECRET_PROPERTY_NAME));
358358
assertEquals(
359-
"1", properties.get(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME));
359+
"true", properties.get(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME));
360360
}
361361

362362
@Test
@@ -369,7 +369,7 @@ public void testParseOAuthProperties_UserAccount_RequestDriveScopeDisabled() {
369369
BigQueryJdbcOAuthUtility.parseOAuthProperties(
370370
DataSource.fromUrl(url), this.getClass().getName());
371371
assertEquals(
372-
"0", properties.get(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME));
372+
"false", properties.get(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME));
373373
}
374374

375375
@Test
@@ -381,7 +381,7 @@ public void testParseOAuthProperties_UserAccount_RequestDriveScopeDefault() {
381381
BigQueryJdbcOAuthUtility.parseOAuthProperties(
382382
DataSource.fromUrl(url), this.getClass().getName());
383383
assertEquals(
384-
String.valueOf(BigQueryJdbcUrlUtility.DEFAULT_REQUEST_GOOGLE_DRIVE_SCOPE_VALUE),
384+
"false",
385385
properties.get(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME));
386386
}
387387

@@ -391,7 +391,7 @@ public void testGetUserAuthorizer_WithDriveScope() throws URISyntaxException {
391391
authProperties.put(BigQueryJdbcUrlUtility.OAUTH_CLIENT_ID_PROPERTY_NAME, "redactedClientId");
392392
authProperties.put(
393393
BigQueryJdbcUrlUtility.OAUTH_CLIENT_SECRET_PROPERTY_NAME, "redactedClientSecret");
394-
authProperties.put(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME, "1");
394+
authProperties.put(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME, "true");
395395

396396
UserAuthorizer authorizer =
397397
BigQueryJdbcOAuthUtility.getUserAuthorizer(
@@ -432,6 +432,35 @@ public void testGetUserAuthorizer_InvalidDriveScopeValue() throws URISyntaxExcep
432432
assertFalse(authorizer.getScopes().contains("https://www.googleapis.com/auth/drive.readonly"));
433433
}
434434

435+
@Test
436+
public void testParseOAuthProperties_ServiceAccount_RequestDriveScopeEnabled() {
437+
String url =
438+
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
439+
+ "OAuthType=0;OAuthServiceAcctEmail=dummy@email.com;OAuthPvtKey=key;"
440+
+ "RequestGoogleDriveScope=1;";
441+
Map<String, String> properties =
442+
BigQueryJdbcOAuthUtility.parseOAuthProperties(
443+
DataSource.fromUrl(url), this.getClass().getName());
444+
assertEquals(
445+
"true", properties.get(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME));
446+
}
447+
448+
@Test
449+
public void testGetCredentialsForPreGeneratedToken_WithDriveScope() {
450+
Map<String, String> authProperties =
451+
BigQueryJdbcOAuthUtility.parseOAuthProperties(
452+
DataSource.fromUrl(
453+
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
454+
+ "OAuthType=2;ProjectId=MyBigQueryProject;"
455+
+ "OAuthAccessToken=RedactedToken;"
456+
+ "RequestGoogleDriveScope=1;"),
457+
null);
458+
459+
GoogleCredentials credentials =
460+
BigQueryJdbcOAuthUtility.getCredentials(authProperties, Collections.EMPTY_MAP, null);
461+
assertThat(credentials).isNotNull();
462+
}
463+
435464
@Test
436465
public void testParseUserImpersonationDefault() {
437466
String connectionUri =

0 commit comments

Comments
 (0)