Skip to content

test(oauth2lib): add live smoke tests against Google endpoints - #217

Merged
agrawalradhika-cell merged 3 commits into
google:masterfrom
agrawalradhika-cell:test/oauth2lib-d3
Dec 2, 2026
Merged

agrawalradhika-cell merged 3 commits into
google:masterfrom
agrawalradhika-cell:test/oauth2lib-d3

Conversation

@agrawalradhika-cell

@agrawalradhika-cell agrawalradhika-cell commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Adds oauth2lib/live_smoke_test.go: live tests against Google's real token and IAM endpoints
. They're behind the smoke build tag, so CI skips them. Each case skips unless its OAUTH2LIB_SMOKE_* env vars are set; the file header lists them all.

cd oauth2lib && go test -tags=smoke -count=1 -v -run TestSmoke_ .

Cases

  • User refresh with a RAPT; reauth required (rapt_required, invalid_rapt); revoked refresh token
  • CAA denial: a certificate-based access (CBA) account without a client certificate → ErrCAADenied
  • Service account: OAuth and self-signed JWT
  • Impersonation: one-hop, two-hop, custom endpoint; impersonated_service_account JSON via BuildCredentials and via ParseImpersonatedServiceAccountJSON + SourceConfig + Impersonate
  • Client-certificate refusal → ErrAccessDenied (local server, runs without credentials); optional live mTLS refresh

For 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 makes enterprise-certificate-proxy a direct (test-only) requirement, at the same version as before.

Based on burkedavison's template, plus: per-test transports so goleak passes, the RAPT on impersonation sources, named subtests, a gcloud-scopes option, and CBA support.

Testing

  • vet, go test -race (97.5%), tidy, compat script; smoke run without credentials: refusal passes, the rest skip.
  • Live at f456a10 (Nov 30 – Dec 1), CBA on unless noted. Passed:
    • TestSmoke_AuthorizedUserRefresh (also with OAUTH2LIB_SMOKE_SCOPES and OAUTH2LIB_SMOKE_API_URL)
    • TestSmoke_CAADenied
    • TestSmoke_MTLSAndClientCertRefusal/refusal
    • TestSmoke_MTLSAndClientCertRefusal/live_mtls_token_endpoint (non-corp test account, self-signed PEM cert, no ECP)
    • TestSmoke_RevokedRefreshToken
    • TestSmoke_ServiceAccount/2lo_oauth, TestSmoke_ServiceAccount/self_signed_jwt (with OAUTH2LIB_SMOKE_API_URL)
    • TestSmoke_Impersonate/one_hop (also with OAUTH2LIB_SMOKE_IMPERSONATE_LIFETIME, OAUTH2LIB_SMOKE_IMPERSONATE_SCOPES=gcloud, OAUTH2LIB_SMOKE_API_URL), two_hop, custom_endpoint
    • TestSmoke_Impersonate/impersonated_service_account_json/parse_then_impersonate
  • Skipped as designed under CBA: TestSmoke_Impersonate/impersonated_service_account_json/build_credentials (ErrCAADenied).
  • Not run live: 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 the user_rapt_required, user_invalid_rapt and user_refresh_scopes_rapt golden vectors (test(oauth2lib): add golden vectors and run them against oauth2lib #216).

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.
Comment thread oauth2lib/live_smoke_test.go Resolved
Comment thread oauth2lib/live_smoke_test.go Resolved
Comment thread oauth2lib/live_smoke_test.go Resolved
Comment thread oauth2lib/live_smoke_test.go Resolved
Comment thread oauth2lib/live_smoke_test.go Resolved
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.
@agrawalradhika-cell
agrawalradhika-cell merged commit bc2de45 into google:master Dec 2, 2026
10 checks passed
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.

3 participants