Skip to content

Commit 7810145

Browse files
committed
Mock HTTP client in accounts OIDC test to avoid hitting live endpoint
The openIDConnectEndPointsTestAccounts test was making real HTTP calls to accounts.cloud.databricks.com, causing failures when the endpoint returned HTML instead of JSON. Use a mock HttpClient that stubs the host metadata call, since account OIDC endpoints are computed locally. Also apply spotless formatting fixes. Co-authored-by: Isaac
1 parent 27eafd3 commit 7810145

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ public void testIsAccountClientForWorkspaceHost() {
9090
public void testIsAccountClientForNonAccountsHost() {
9191
// Non-accounts hosts are not account clients
9292
assertFalse(
93-
new DatabricksConfig()
94-
.setHost("https://mycompany.databricks.com")
95-
.isAccountClient());
93+
new DatabricksConfig().setHost("https://mycompany.databricks.com").isAccountClient());
9694
}
9795

9896
// --- Environment Variable Tests ---

databricks-sdk-java/src/test/java/com/databricks/sdk/core/oauth/ExternalBrowserCredentialsProviderTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,27 @@ void clientAndConsentTestWithCustomRedirectUrl() throws IOException {
122122

123123
@Test
124124
void openIDConnectEndPointsTestAccounts() throws IOException {
125+
HttpClient mockHttpClient = Mockito.mock(HttpClient.class);
126+
// Mock the host metadata call (resolve) to return 404, matching FixtureServer auto-stub
127+
// behavior. The actual OIDC endpoints for account clients are computed locally without HTTP.
128+
Mockito.doAnswer(
129+
invocation -> {
130+
Request req = invocation.getArgument(0);
131+
if (req.getUrl().contains("/.well-known/databricks-config")) {
132+
return new Response(
133+
"{\"error_code\":\"NOT_FOUND\",\"message\":\"not found\"}",
134+
new URL(req.getUrl()));
135+
}
136+
throw new IOException("Unexpected request: " + req.getUrl());
137+
})
138+
.when(mockHttpClient)
139+
.execute(any(Request.class));
140+
125141
DatabricksConfig config =
126142
new DatabricksConfig()
127143
.setAuthType("external-browser")
128144
.setHost("https://accounts.cloud.databricks.com")
129-
.setHttpClient(new CommonsHttpClient.Builder().withTimeoutSeconds(30).build())
145+
.setHttpClient(mockHttpClient)
130146
.setAccountId("testAccountId");
131147
config.resolve();
132148

databricks-sdk-java/src/test/java/com/databricks/sdk/service/gentesting/unittests/IdempotencyTestingAPITest.java

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)