Skip to content

Add parametrized unit tests for auth types across host profiles#771

Merged
hectorcast-db merged 2 commits intomainfrom
hector/auth-profiles-tests
Apr 22, 2026
Merged

Add parametrized unit tests for auth types across host profiles#771
hectorcast-db merged 2 commits intomainfrom
hector/auth-profiles-tests

Conversation

@hectorcast-db
Copy link
Copy Markdown
Contributor

Summary

  • Adds AuthProfilesTest.java with 138 parametrized subtests covering 8 auth types across 6 host profiles (LW, NW, LA, NA, SPOGW, SPOGA) on AWS, Azure, and GCP.
  • Mirrors databricks/databricks-sdk-go#1627 and databricks/databricks-sdk-py#1357.
  • Java has no HostMetadataResolver seam, so each test mocks GET /.well-known/databricks-config and calls resolve() so that DatabricksConfig.resolveHostMetadata() actually runs and populates discoveryUrl (and accountId/workspaceId for bare-host profiles) from the mocked metadata — the production path Go's resolver injection shortcuts.
  • Adds a dedicated hostMetadataResolutionPopulatesDiscoveryUrl subtest that asserts the derivation explicitly, so a regression where metadata resolution silently no-ops cannot be masked.

Profiles tested

Profile Description Derivation
LW Legacy Workspace Baseline
NW New Workspace LW + account_id + workspace_id
LA Legacy Account Baseline
NA New Account Structurally same as LA
SPOGW SPOG workspace Unified host + account_id + workspace_id
SPOGA SPOG account Unified host + account_id

Auth types covered

pat, basic, oauth-m2m, github-oidc, env-oidc, file-oidc, azure-client-secret, github-oidc-azure

Not covered (with rationale)

  • databricks-cli, azure-cli: invoke external processes via ProcessBuilder; mocking requires MockedConstruction + spy per-profile. Covered at the unit level by DatabricksCliCredentialsProviderTest / AzureCliCredentialsProviderTest / CliTokenSourceTest.
  • azure-devops-oidc: AzureDevOpsIDTokenSource reads SYSTEM_* variables via System.getenv() at construction time (not via config.getEnv()); overriding those in-process requires JUnit Pioneer or reflection, neither of which is in the project's dep set.
  • metadata-service: no equivalent auth type in the Java SDK. AzureMsiCredentialsProvider hits the Azure IMDS endpoint, not a Databricks-hosted metadata service.
  • google-credentials, google-id: delegate to Google SDK functions that parse real crypto keys with no seam for HTTP injection (matches Go SDK's exclusion).

Test plan

  • All 138 new subtests pass locally (mvn test -Dtest=AuthProfilesTest)
  • Existing com.databricks.sdk.core.* tests unaffected (908 pass)

This pull request was AI-assisted by Isaac.

Copy link
Copy Markdown
Contributor

@tejaskochar-db tejaskochar-db left a comment

Choose a reason for hiding this comment

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

Couple of nits

Comment thread databricks-sdk-java/src/test/java/com/databricks/sdk/core/AuthProfilesTest.java Outdated
Comment thread databricks-sdk-java/src/test/java/com/databricks/sdk/core/AuthProfilesTest.java Outdated
sb.append("{");
sb.append("\"oidc_endpoint\":\"").append(metadataOidcEndpoint()).append("\"");
sb.append(",\"account_id\":\"").append(TEST_ACCOUNT_ID).append("\"");
if (kind != ProfileKind.ACCOUNT && kind != ProfileKind.UNIFIED) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as kind == ProfileKind.WORKSPACE right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The else if branch also does exactly the same thing, should we combine the two?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So the condition for including workspace id in metadata response is - it is either a workspace profile, or a unified profile with workspace ID set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes — with only three ProfileKind values, kind != ACCOUNT && kind != UNIFIED is just kind == WORKSPACE. Rewritten in f54db1e.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Combined in f54db1e. The two branches produced identical JSON; new single condition is kind == WORKSPACE || (kind == UNIFIED && configWorkspaceId != null).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Exactly. Codified that as the single combined condition in f54db1e, with a short comment explaining the rule.

Comment thread databricks-sdk-java/src/test/java/com/databricks/sdk/core/AuthProfilesTest.java Outdated
Tests each auth type resolves correctly on every applicable host profile
(LW, NW, LA, NA, SPOGW, SPOGA) across AWS, Azure, and GCP clouds. Covers
pat, basic, oauth-m2m, github-oidc, env-oidc, file-oidc,
azure-client-secret, and github-oidc-azure (138 subtests total).

Java has no HostMetadataResolver seam, so each test mocks
GET /.well-known/databricks-config and calls resolve() so that
DatabricksConfig.resolveHostMetadata() actually runs and populates
discoveryUrl (and accountId/workspaceId for bare-host profiles) from the
mocked metadata response — the production path Go's resolver injection
shortcuts. A dedicated hostMetadataResolutionPopulatesDiscoveryUrl test
asserts that derivation explicitly.

Mirrors databricks/databricks-sdk-go#1627.

NO_CHANGELOG=false

Co-authored-by: Isaac
- Drop PR cross-reference numbers from class Javadoc; keep the explanation of why the test mocks the well-known endpoint.
- Collapse the two branches of the workspace_id inclusion check into a single condition (kind == WORKSPACE || (kind == UNIFIED && configWorkspaceId != null)).
- Replace hardcoded "Linux" system name in the test Environment helpers with System.getProperty("os.name"), matching existing tests under src/test/java/com/databricks/sdk/core/.

Co-authored-by: Isaac
@github-actions
Copy link
Copy Markdown
Contributor

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-java

Inputs:

  • PR number: 771
  • Commit SHA: 5eb959af2c76dd7e2b1af8d6065c32b9d39e9172

Checks will be approved automatically on success.

@hectorcast-db hectorcast-db added this pull request to the merge queue Apr 22, 2026
Merged via the queue into main with commit fa18f39 Apr 22, 2026
16 checks passed
@hectorcast-db hectorcast-db deleted the hector/auth-profiles-tests branch April 22, 2026 09:04
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.

2 participants