Skip to content

tests(langchain-sdk): Update conftest to be able to run tests in local#222

Closed
twishabansal wants to merge 4 commits into
mainfrom
auth-test-local
Closed

tests(langchain-sdk): Update conftest to be able to run tests in local#222
twishabansal wants to merge 4 commits into
mainfrom
auth-test-local

Conversation

@twishabansal

@twishabansal twishabansal commented Jan 17, 2025

Copy link
Copy Markdown
Contributor

Getting an id token from metadata server does not work on local systems. This causes test failures for auth tests locally. This PR fixes the issue.

This unblocks https://b.corp.google.com/issues/385051620

@twishabansal twishabansal marked this pull request as ready for review January 17, 2025 07:18
@twishabansal twishabansal requested a review from a team January 17, 2025 07:18
@twishabansal twishabansal enabled auto-merge (squash) January 17, 2025 07:21
@twishabansal twishabansal disabled auto-merge January 17, 2025 07:28
Comment on lines +84 to +101
# Try getting the token using gcloud (for local development)
result = subprocess.run(
["gcloud", "auth", "print-identity-token"],
capture_output=True,
text=True,
check=True,
)
return result.stdout.strip()
except (subprocess.CalledProcessError, FileNotFoundError):
request = google.auth.transport.requests.Request()
credentials = compute_engine.IDTokenCredentials(
request=request,
target_audience=client_id,
use_metadata_identity_endpoint=True,
)
if not credentials.valid:
credentials.refresh(request)
return credentials.token

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I agree with this flow. I think ideally it should be trying the metadata server first, and falling back to gcloud if it's unable to reach. An alternative would be use an env var to signal which to use.

Ideally, we should not rely on "gcloud auth" as it's not semantically versioned (and I've personally been bit by it changing int the past)

@Yuan325 Yuan325 closed this Feb 5, 2025
@Yuan325

Yuan325 commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

Migrated PR to googleapis/mcp-toolbox-sdk-python#18

@twishabansal twishabansal deleted the auth-test-local branch July 15, 2025 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants