|
18 | 18 |
|
19 | 19 | import static com.google.common.truth.Truth.assertThat; |
20 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; |
21 | | -import static org.junit.jupiter.api.Assertions.assertFalse; |
22 | 21 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
23 | 22 | import static org.junit.jupiter.api.Assertions.assertNull; |
24 | 23 | import static org.junit.jupiter.api.Assertions.assertTrue; |
@@ -338,128 +337,6 @@ public void testParseBYOIDProps() { |
338 | 337 | assertThat(result.get("BYOID_TokenUri")).isEqualTo("https://testuri.com/v1/token"); |
339 | 338 | } |
340 | 339 |
|
341 | | - @Test |
342 | | - public void testParseOAuthProperties_UserAccount_RequestDriveScopeEnabled() { |
343 | | - String url = |
344 | | - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" |
345 | | - + "OAuthType=1;OAuthClientId=redactedClientId;OAuthClientSecret=redactedClientSecret;" |
346 | | - + "RequestGoogleDriveScope=1;"; |
347 | | - Map<String, String> properties = |
348 | | - BigQueryJdbcOAuthUtility.parseOAuthProperties( |
349 | | - DataSource.fromUrl(url), this.getClass().getName()); |
350 | | - assertEquals( |
351 | | - String.valueOf(BigQueryJdbcOAuthUtility.AuthType.GOOGLE_USER_ACCOUNT), |
352 | | - properties.get(BigQueryJdbcUrlUtility.OAUTH_TYPE_PROPERTY_NAME)); |
353 | | - assertEquals( |
354 | | - "redactedClientId", properties.get(BigQueryJdbcUrlUtility.OAUTH_CLIENT_ID_PROPERTY_NAME)); |
355 | | - assertEquals( |
356 | | - "redactedClientSecret", |
357 | | - properties.get(BigQueryJdbcUrlUtility.OAUTH_CLIENT_SECRET_PROPERTY_NAME)); |
358 | | - assertEquals( |
359 | | - "true", properties.get(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME)); |
360 | | - } |
361 | | - |
362 | | - @Test |
363 | | - public void testParseOAuthProperties_UserAccount_RequestDriveScopeDisabled() { |
364 | | - String url = |
365 | | - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" |
366 | | - + "OAuthType=1;OAuthClientId=redactedClientId;OAuthClientSecret=redactedClientSecret;" |
367 | | - + "RequestGoogleDriveScope=0;"; |
368 | | - Map<String, String> properties = |
369 | | - BigQueryJdbcOAuthUtility.parseOAuthProperties( |
370 | | - DataSource.fromUrl(url), this.getClass().getName()); |
371 | | - assertEquals( |
372 | | - "false", properties.get(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME)); |
373 | | - } |
374 | | - |
375 | | - @Test |
376 | | - public void testParseOAuthProperties_UserAccount_RequestDriveScopeDefault() { |
377 | | - String url = |
378 | | - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" |
379 | | - + "OAuthType=1;OAuthClientId=redactedClientId;OAuthClientSecret=redactedClientSecret;"; |
380 | | - Map<String, String> properties = |
381 | | - BigQueryJdbcOAuthUtility.parseOAuthProperties( |
382 | | - DataSource.fromUrl(url), this.getClass().getName()); |
383 | | - assertEquals( |
384 | | - "false", properties.get(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME)); |
385 | | - } |
386 | | - |
387 | | - @Test |
388 | | - public void testGetUserAuthorizer_WithDriveScope() throws URISyntaxException { |
389 | | - Map<String, String> authProperties = new HashMap<>(); |
390 | | - authProperties.put(BigQueryJdbcUrlUtility.OAUTH_CLIENT_ID_PROPERTY_NAME, "redactedClientId"); |
391 | | - authProperties.put( |
392 | | - BigQueryJdbcUrlUtility.OAUTH_CLIENT_SECRET_PROPERTY_NAME, "redactedClientSecret"); |
393 | | - authProperties.put(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME, "true"); |
394 | | - |
395 | | - UserAuthorizer authorizer = |
396 | | - BigQueryJdbcOAuthUtility.getUserAuthorizer( |
397 | | - authProperties, Collections.emptyMap(), 12345, this.getClass().getName()); |
398 | | - |
399 | | - assertTrue(authorizer.getScopes().contains("https://www.googleapis.com/auth/bigquery")); |
400 | | - assertTrue(authorizer.getScopes().contains("https://www.googleapis.com/auth/drive.readonly")); |
401 | | - assertEquals(2, authorizer.getScopes().size()); |
402 | | - } |
403 | | - |
404 | | - @Test |
405 | | - public void testGetUserAuthorizer_WithoutDriveScope() throws URISyntaxException { |
406 | | - Map<String, String> authProperties = new HashMap<>(); |
407 | | - authProperties.put(BigQueryJdbcUrlUtility.OAUTH_CLIENT_ID_PROPERTY_NAME, "redactedClientId"); |
408 | | - authProperties.put( |
409 | | - BigQueryJdbcUrlUtility.OAUTH_CLIENT_SECRET_PROPERTY_NAME, "redactedClientSecret"); |
410 | | - authProperties.put(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME, "0"); |
411 | | - |
412 | | - UserAuthorizer authorizer = |
413 | | - BigQueryJdbcOAuthUtility.getUserAuthorizer( |
414 | | - authProperties, Collections.emptyMap(), 12345, this.getClass().getName()); |
415 | | - assertTrue(authorizer.getScopes().contains("https://www.googleapis.com/auth/bigquery")); |
416 | | - assertFalse(authorizer.getScopes().contains("https://www.googleapis.com/auth/drive.readonly")); |
417 | | - assertEquals(1, authorizer.getScopes().size()); |
418 | | - } |
419 | | - |
420 | | - @Test |
421 | | - public void testGetUserAuthorizer_InvalidDriveScopeValue() throws URISyntaxException { |
422 | | - Map<String, String> authProperties = new HashMap<>(); |
423 | | - authProperties.put(BigQueryJdbcUrlUtility.OAUTH_CLIENT_ID_PROPERTY_NAME, "redactedClientId"); |
424 | | - authProperties.put( |
425 | | - BigQueryJdbcUrlUtility.OAUTH_CLIENT_SECRET_PROPERTY_NAME, "redactedClientSecret"); |
426 | | - authProperties.put( |
427 | | - BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME, "invalid_value"); |
428 | | - UserAuthorizer authorizer = |
429 | | - BigQueryJdbcOAuthUtility.getUserAuthorizer( |
430 | | - authProperties, Collections.emptyMap(), 12345, this.getClass().getName()); |
431 | | - assertFalse(authorizer.getScopes().contains("https://www.googleapis.com/auth/drive.readonly")); |
432 | | - } |
433 | | - |
434 | | - @Test |
435 | | - public void testParseOAuthProperties_ServiceAccount_RequestDriveScopeEnabled() { |
436 | | - String url = |
437 | | - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" |
438 | | - + "OAuthType=0;OAuthServiceAcctEmail=dummy@email.com;OAuthPvtKey=key;" |
439 | | - + "RequestGoogleDriveScope=1;"; |
440 | | - Map<String, String> properties = |
441 | | - BigQueryJdbcOAuthUtility.parseOAuthProperties( |
442 | | - DataSource.fromUrl(url), this.getClass().getName()); |
443 | | - assertEquals( |
444 | | - "true", properties.get(BigQueryJdbcUrlUtility.REQUEST_GOOGLE_DRIVE_SCOPE_PROPERTY_NAME)); |
445 | | - } |
446 | | - |
447 | | - @Test |
448 | | - public void testGetCredentialsForPreGeneratedToken_WithDriveScope() { |
449 | | - Map<String, String> authProperties = |
450 | | - BigQueryJdbcOAuthUtility.parseOAuthProperties( |
451 | | - DataSource.fromUrl( |
452 | | - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" |
453 | | - + "OAuthType=2;ProjectId=MyBigQueryProject;" |
454 | | - + "OAuthAccessToken=RedactedToken;" |
455 | | - + "RequestGoogleDriveScope=1;"), |
456 | | - null); |
457 | | - |
458 | | - GoogleCredentials credentials = |
459 | | - BigQueryJdbcOAuthUtility.getCredentials(authProperties, Collections.EMPTY_MAP, true, null); |
460 | | - assertThat(credentials).isNotNull(); |
461 | | - } |
462 | | - |
463 | 340 | @Test |
464 | 341 | public void testParseUserImpersonationDefault() { |
465 | 342 | String connectionUri = |
|
0 commit comments