Skip to content

Commit c41cc01

Browse files
Add OIDC endpoint helper tests (#679)
## 🥞 Stacked PR Use this [link](https://github.com/databricks/databricks-sdk-java/pull/679/files) to review incremental changes. - [**stack/config-auto-complete-2**](#679) [[Files changed](https://github.com/databricks/databricks-sdk-java/pull/679/files)] - [stack/config-auto-complete-3](#680) [[Files changed](https://github.com/databricks/databricks-sdk-java/pull/680/files/3b4e6d886efaf9fdedf7de2a5d356ea7eea18617..733d3aefce14ba9aac8ecc82e694f9c2e85fda3e)] --------- ## Summary Adds tests covering OIDC endpoint resolution directly from a discovery URL, exercising the existing `discoveryUrl` config field and the `getDatabricksOidcEndpoints()` short-circuit path. ## Why The OIDC discovery URL returned by `/.well-known/databricks-config` points to a standard OAuth 2.0 authorization server metadata document (`authorization_endpoint`, `token_endpoint`). The Java SDK already has `discoveryUrl` (`DATABRICKS_DISCOVERY_URL`) and `getDatabricksOidcEndpoints()` fetching directly from it when set — this is the Java equivalent of the Python SDK's `get_endpoints_from_url()` addition. This PR adds the missing test coverage for those paths. ## What changed ### Interface changes None. The `discoveryUrl` config field (`DATABRICKS_DISCOVERY_URL`) and the `getDatabricksOidcEndpoints()` short-circuit were already present in the Java SDK. ### Behavioral changes None. No existing code paths are modified. ### Internal changes - `testDiscoveryUrlFromEnv` — verifies `DATABRICKS_DISCOVERY_URL` env var is loaded into `discoveryUrl`. - `testDatabricksOidcEndpointsUsesDiscoveryUrl` — verifies `getDatabricksOidcEndpoints()` short-circuits to fetch directly from `discoveryUrl` when set. ## How is this tested? Unit tests in `DatabricksConfigTest` using `FixtureServer`. NO_CHANGELOG=true
1 parent 30b5035 commit c41cc01

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,4 +479,36 @@ public void testGetHostMetadataRaisesOnHttpError() throws IOException {
479479
assertTrue(ex.getMessage().contains("Failed to fetch host metadata"));
480480
}
481481
}
482+
483+
// --- discoveryUrl / OIDC endpoint tests ---
484+
485+
@Test
486+
public void testDiscoveryUrlFromEnv() {
487+
Map<String, String> env = new HashMap<>();
488+
env.put("DATABRICKS_DISCOVERY_URL", "https://custom.idp.example.com/oidc");
489+
DatabricksConfig config = new DatabricksConfig();
490+
config.resolve(new Environment(env, new ArrayList<>(), System.getProperty("os.name")));
491+
assertEquals("https://custom.idp.example.com/oidc", config.getDiscoveryUrl());
492+
}
493+
494+
@Test
495+
public void testDatabricksOidcEndpointsUsesDiscoveryUrl() throws IOException {
496+
String discoveryUrlSuffix = "/oidc";
497+
String discoveryUrlResponse =
498+
"{\"authorization_endpoint\":\"https://ws.databricks.com/oidc/v1/authorize\","
499+
+ "\"token_endpoint\":\"https://ws.databricks.com/oidc/v1/token\"}";
500+
try (FixtureServer server =
501+
new FixtureServer().with("GET", discoveryUrlSuffix, discoveryUrlResponse, 200)) {
502+
String discoveryUrl = server.getUrl() + discoveryUrlSuffix;
503+
OpenIDConnectEndpoints endpoints =
504+
new DatabricksConfig()
505+
.setHost(server.getUrl())
506+
.setDiscoveryUrl(discoveryUrl)
507+
.setHttpClient(new CommonsHttpClient.Builder().withTimeoutSeconds(30).build())
508+
.getDatabricksOidcEndpoints();
509+
assertEquals(
510+
"https://ws.databricks.com/oidc/v1/authorize", endpoints.getAuthorizationEndpoint());
511+
assertEquals("https://ws.databricks.com/oidc/v1/token", endpoints.getTokenEndpoint());
512+
}
513+
}
482514
}

0 commit comments

Comments
 (0)