Repository navigation
test(oauth2lib): add live smoke tests against Google endpoints - #217
Merged
agrawalradhika-cell merged 3 commits intoDec 2, 2026
Merged
Conversation
Add oauth2lib/live_smoke_test.go behind the smoke build tag, so normal builds and CI skip it. Each case reads its inputs from OAUTH2LIB_SMOKE_* environment variables and skips when they are unset. Cases: authorized_user refresh with a RAPT; reauth required with no RAPT (rapt_required) and with an expired RAPT (invalid_rapt); a revoked refresh token; a service account through OAuth and as a self-signed JWT; one-hop, two-hop and custom-endpoint impersonation; impersonated_service_account JSON through BuildCredentials and through ParseImpersonatedServiceAccountJSON + SourceConfig + Impersonate; a client-certificate refusal (hermetic); and an optional live mTLS refresh. Based on burkedavison's template, with these changes: - Each test gets its own transport and closes its idle connections at cleanup; otherwise keep-alive read loops fail goleak.VerifyTestMain. - authorized_user impersonation sources and the live mTLS user get the RAPT, as Go gcloud will send it. - Impersonation cases are split into named subtests, and the reauth case covers both error subtypes. - OAUTH2LIB_SMOKE_IMPERSONATE_SCOPES can send gcloud's default scopes.
…ests Accounts that require certificate-based access (CBA), such as @google.com accounts on corp machines, are refused on the plain token endpoint with access_denied "Account restricted". A live run with such an account failed the user refresh and reauth cases that way. With OAUTH2LIB_SMOKE_ECP_CONFIG set (gcloud's context_aware/certificate_config_file_path), the smoke tests now do what Go gcloud does under CBA: - every test transport presents the Enterprise Certificate Proxy certificate (ecpclient.Cred), and the signer is stopped at cleanup; - authorized_user and service_account refreshes use https://oauth2.mtls.googleapis.com/token; - impersonation uses https://iamcredentials.mtls.googleapis.com/ unless an endpoint is given. Also add TestSmoke_CAADenied (OAUTH2LIB_SMOKE_CAA_USER_JSON): a CBA account refreshed without a client certificate must return an error that matches ErrCAADenied and ErrAccessDenied, not ErrReauthRequired or ErrTransient. Under CBA, the impersonated_service_account JSON case that goes through BuildCredentials skips on ErrCAADenied, because that JSON keeps its source's token_uri and its own IAM host. github.com/googleapis/enterprise-certificate-proxy v0.3.17 moves from an indirect to a direct requirement; only the smoke tests import it.
burkedavison
approved these changes
Dec 2, 2026
newSmokeTransport starts an ECP signer when OAUTH2LIB_SMOKE_ECP_CONFIG is set, but live_mtls_token_endpoint replaces TLSClientConfig with the PEM key pair anyway. Use newPlainSmokeTransport and drop the stale comment about swapping in ecpclient.Cred.
andyrzhao
approved these changes
Dec 2, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds
oauth2lib/live_smoke_test.go: live tests against Google's real token and IAM endpoints. They're behind the
smokebuild tag, so CI skips them. Each case skips unless itsOAUTH2LIB_SMOKE_*env vars are set; the file header lists them all.Cases
rapt_required,invalid_rapt); revoked refresh tokenErrCAADeniedimpersonated_service_accountJSON viaBuildCredentialsand viaParseImpersonatedServiceAccountJSON+SourceConfig+ImpersonateErrAccessDenied(local server, runs without credentials); optional live mTLS refreshFor CBA accounts (e.g. @google.com on corp machines), set
OAUTH2LIB_SMOKE_ECP_CONFIG. The tests then present the Enterprise Certificate Proxy certificate and use the mTLS token and IAM hosts, as Go gcloud will. This makesenterprise-certificate-proxya direct (test-only) requirement, at the same version as before.Based on burkedavison's template, plus: per-test transports so
goleakpasses, the RAPT on impersonation sources, named subtests, a gcloud-scopes option, and CBA support.Testing
go test -race(97.5%), tidy, compat script; smoke run without credentials:refusalpasses, the rest skip.f456a10(Nov 30 – Dec 1), CBA on unless noted. Passed:TestSmoke_AuthorizedUserRefresh(also withOAUTH2LIB_SMOKE_SCOPESandOAUTH2LIB_SMOKE_API_URL)TestSmoke_CAADeniedTestSmoke_MTLSAndClientCertRefusal/refusalTestSmoke_MTLSAndClientCertRefusal/live_mtls_token_endpoint(non-corp test account, self-signed PEM cert, no ECP)TestSmoke_RevokedRefreshTokenTestSmoke_ServiceAccount/2lo_oauth,TestSmoke_ServiceAccount/self_signed_jwt(withOAUTH2LIB_SMOKE_API_URL)TestSmoke_Impersonate/one_hop(also withOAUTH2LIB_SMOKE_IMPERSONATE_LIFETIME,OAUTH2LIB_SMOKE_IMPERSONATE_SCOPES=gcloud,OAUTH2LIB_SMOKE_API_URL),two_hop,custom_endpointTestSmoke_Impersonate/impersonated_service_account_json/parse_then_impersonateTestSmoke_Impersonate/impersonated_service_account_json/build_credentials(ErrCAADenied).TestSmoke_ReauthRequired/rapt_required,TestSmoke_ReauthRequired/invalid_rapt, and the RAPT echo with a real RAPT. None of the available test accounts is reauth-enforced; the echo passed with a placeholder RAPT only. Covered by theuser_rapt_required,user_invalid_raptanduser_refresh_scopes_raptgolden vectors (test(oauth2lib): add golden vectors and run them against oauth2lib #216).