-
Notifications
You must be signed in to change notification settings - Fork 173
feat(go/adbc/driver/bigquery): Support BigQuery scopes #3523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yu-iskw
wants to merge
3
commits into
apache:main
Choose a base branch
from
yu-iskw:issue-3522
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1589,3 +1589,231 @@ func TestAuthTypeConsolidation(t *testing.T) { | |
| t.Errorf("Expected error message to contain 'unknown database auth type value', got: %v", err) | ||
| } | ||
| } | ||
|
|
||
| // ---- Auth Scopes Tests ---- | ||
|
|
||
| // TestAuthScopesSetGet tests setting and getting regular auth scopes | ||
| func TestAuthScopesSetGet(t *testing.T) { | ||
| mem := memory.NewCheckedAllocator(memory.DefaultAllocator) | ||
| defer mem.AssertSize(t, 0) | ||
|
|
||
| drv := driver.NewDriver(mem) | ||
| db, err := drv.NewDatabase(nil) | ||
| if err != nil { | ||
| t.Fatalf("Failed to create database: %v", err) | ||
| } | ||
| defer func() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
| _ = db.Close() | ||
| }() | ||
|
|
||
| // Test setting auth scopes | ||
| expectedScopes := "https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/cloud-platform" | ||
| err = db.SetOptions(map[string]string{ | ||
| driver.OptionStringAuthScopes: expectedScopes, | ||
| }) | ||
| if err != nil { | ||
| t.Errorf("Failed to set auth scopes: %v", err) | ||
| } | ||
|
|
||
| // Test getting auth scopes | ||
| getSetDB, ok := db.(interface { | ||
| GetOption(string) (string, error) | ||
| }) | ||
| if !ok { | ||
| t.Fatal("Database does not implement GetOption") | ||
| } | ||
|
|
||
| retrievedScopes, err := getSetDB.GetOption(driver.OptionStringAuthScopes) | ||
| if err != nil { | ||
| t.Errorf("Failed to get auth scopes: %v", err) | ||
| } | ||
|
|
||
| if retrievedScopes != expectedScopes { | ||
| t.Errorf("Expected scopes %s, got %s", expectedScopes, retrievedScopes) | ||
| } | ||
| } | ||
|
|
||
| // TestAuthScopesSeparateFromImpersonateScopes verifies that auth scopes and impersonate scopes are separate | ||
| func TestAuthScopesSeparateFromImpersonateScopes(t *testing.T) { | ||
| mem := memory.NewCheckedAllocator(memory.DefaultAllocator) | ||
| defer mem.AssertSize(t, 0) | ||
|
|
||
| drv := driver.NewDriver(mem) | ||
| db, err := drv.NewDatabase(nil) | ||
| if err != nil { | ||
| t.Fatalf("Failed to create database: %v", err) | ||
| } | ||
| defer func() { | ||
| _ = db.Close() | ||
| }() | ||
|
|
||
| authScopes := "https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/cloud-platform" | ||
| impersonateScopes := "https://www.googleapis.com/auth/bigquery,https://www.googleapis.com/auth/devstorage.read_write" | ||
|
|
||
| // Set both types of scopes | ||
| err = db.SetOptions(map[string]string{ | ||
| driver.OptionStringAuthScopes: authScopes, | ||
| driver.OptionStringImpersonateScopes: impersonateScopes, | ||
| }) | ||
| if err != nil { | ||
| t.Errorf("Failed to set scopes: %v", err) | ||
| } | ||
|
|
||
| getSetDB, ok := db.(interface { | ||
| GetOption(string) (string, error) | ||
| }) | ||
| if !ok { | ||
| t.Fatal("Database does not implement GetOption") | ||
| } | ||
|
|
||
| // Verify auth scopes | ||
| retrievedAuthScopes, err := getSetDB.GetOption(driver.OptionStringAuthScopes) | ||
| if err != nil { | ||
| t.Errorf("Failed to get auth scopes: %v", err) | ||
| } | ||
| if retrievedAuthScopes != authScopes { | ||
| t.Errorf("Expected auth scopes %s, got %s", authScopes, retrievedAuthScopes) | ||
| } | ||
|
|
||
| // Verify impersonate scopes (they should be different) | ||
| retrievedImpScopes, err := getSetDB.GetOption(driver.OptionStringImpersonateScopes) | ||
| if err != nil { | ||
| t.Errorf("Failed to get impersonate scopes: %v", err) | ||
| } | ||
|
|
||
| // The retrieved impersonate scopes should match what we set | ||
| t.Logf("Auth scopes: %s", retrievedAuthScopes) | ||
| t.Logf("Impersonate scopes: %s", retrievedImpScopes) | ||
|
|
||
| // The key point: they should be stored separately | ||
| if retrievedAuthScopes == impersonateScopes { | ||
| t.Error("Auth scopes and impersonate scopes should be different but got the same value") | ||
| } | ||
| } | ||
|
|
||
| // TestAuthScopesEmptyByDefault tests that auth scopes default to empty | ||
| func TestAuthScopesEmptyByDefault(t *testing.T) { | ||
| mem := memory.NewCheckedAllocator(memory.DefaultAllocator) | ||
| defer mem.AssertSize(t, 0) | ||
|
|
||
| drv := driver.NewDriver(mem) | ||
| db, err := drv.NewDatabase(nil) | ||
| if err != nil { | ||
| t.Fatalf("Failed to create database: %v", err) | ||
| } | ||
| defer func() { | ||
| _ = db.Close() | ||
| }() | ||
|
|
||
| getSetDB, ok := db.(interface { | ||
| GetOption(string) (string, error) | ||
| }) | ||
| if !ok { | ||
| t.Fatal("Database does not implement GetOption") | ||
| } | ||
|
|
||
| // Get auth scopes without setting them | ||
| scopes, err := getSetDB.GetOption(driver.OptionStringAuthScopes) | ||
| if err != nil { | ||
| t.Errorf("Failed to get auth scopes: %v", err) | ||
| } | ||
|
|
||
| if scopes != "" { | ||
| t.Errorf("Expected empty scopes by default, got %s", scopes) | ||
| } | ||
| } | ||
|
|
||
| // TestAuthScopesCommaSeparated tests that multiple scopes are properly handled | ||
| func TestAuthScopesCommaSeparated(t *testing.T) { | ||
| mem := memory.NewCheckedAllocator(memory.DefaultAllocator) | ||
| defer mem.AssertSize(t, 0) | ||
|
|
||
| drv := driver.NewDriver(mem) | ||
| db, err := drv.NewDatabase(nil) | ||
| if err != nil { | ||
| t.Fatalf("Failed to create database: %v", err) | ||
| } | ||
| defer func() { | ||
| _ = db.Close() | ||
| }() | ||
|
|
||
| scopes := []string{ | ||
| "https://www.googleapis.com/auth/drive", | ||
| "https://www.googleapis.com/auth/cloud-platform", | ||
| "https://www.googleapis.com/auth/bigquery", | ||
| } | ||
| scopesStr := strings.Join(scopes, ",") | ||
|
|
||
| err = db.SetOptions(map[string]string{ | ||
| driver.OptionStringAuthScopes: scopesStr, | ||
| }) | ||
| if err != nil { | ||
| t.Errorf("Failed to set auth scopes: %v", err) | ||
| } | ||
|
|
||
| getSetDB, ok := db.(interface { | ||
| GetOption(string) (string, error) | ||
| }) | ||
| if !ok { | ||
| t.Fatal("Database does not implement GetOption") | ||
| } | ||
|
|
||
| retrievedScopes, err := getSetDB.GetOption(driver.OptionStringAuthScopes) | ||
| if err != nil { | ||
| t.Errorf("Failed to get auth scopes: %v", err) | ||
| } | ||
|
|
||
| if retrievedScopes != scopesStr { | ||
| t.Errorf("Expected scopes %s, got %s", scopesStr, retrievedScopes) | ||
| } | ||
|
|
||
| // Verify the scopes contain all expected values | ||
| retrievedParts := strings.Split(retrievedScopes, ",") | ||
| if len(retrievedParts) != len(scopes) { | ||
| t.Errorf("Expected %d scopes, got %d", len(scopes), len(retrievedParts)) | ||
| } | ||
| } | ||
|
|
||
| // TestAuthScopesPropagatedToConnection tests that scopes are propagated from database to connection | ||
| func TestAuthScopesPropagatedToConnection(t *testing.T) { | ||
| // Note: This test doesn't actually open a connection (which would require valid GCP credentials) | ||
| // but verifies that the scopes are stored in the database impl | ||
| mem := memory.NewCheckedAllocator(memory.DefaultAllocator) | ||
| defer mem.AssertSize(t, 0) | ||
|
|
||
| drv := driver.NewDriver(mem) | ||
|
|
||
| scopes := "https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/cloud-platform" | ||
|
|
||
| db, err := drv.NewDatabase(map[string]string{ | ||
| driver.OptionStringProjectID: "test-project", | ||
| driver.OptionStringAuthScopes: scopes, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("Failed to create database: %v", err) | ||
| } | ||
| defer func() { | ||
| _ = db.Close() | ||
| }() | ||
|
|
||
| // Verify the scopes were set | ||
| getSetDB, ok := db.(interface { | ||
| GetOption(string) (string, error) | ||
| }) | ||
| if !ok { | ||
| t.Fatal("Database does not implement GetOption") | ||
| } | ||
|
|
||
| retrievedScopes, err := getSetDB.GetOption(driver.OptionStringAuthScopes) | ||
| if err != nil { | ||
| t.Errorf("Failed to get auth scopes: %v", err) | ||
| } | ||
|
|
||
| if retrievedScopes != scopes { | ||
| t.Errorf("Expected scopes %s, got %s", scopes, retrievedScopes) | ||
| } | ||
|
|
||
| // Note: We can't test actual connection opening without valid credentials, | ||
| // but the struct propagation is tested in the databaseImpl.Open() method | ||
| t.Log("Scopes successfully stored in database and ready for connection propagation") | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it should error if both are set?