Skip to content

Commit 7defeec

Browse files
committed
Add unit tests
1 parent 32f18f9 commit 7defeec

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,17 @@ public DatabricksConfig setAzureUseMsi(boolean azureUseMsi) {
410410
return this;
411411
}
412412

413-
/** @deprecated Use {@link #getAzureUseMsi()} instead. */
413+
/**
414+
* @deprecated Use {@link #getAzureUseMsi()} instead.
415+
*/
414416
@Deprecated()
415417
public boolean getAzureUseMSI() {
416418
return azureUseMsi;
417419
}
418420

419-
/** @deprecated Use {@link #setAzureUseMsi(boolean)} instead. */
421+
/**
422+
* @deprecated Use {@link #setAzureUseMsi(boolean)} instead.
423+
*/
420424
@Deprecated
421425
public DatabricksConfig setAzureUseMSI(boolean azureUseMsi) {
422426
this.azureUseMsi = azureUseMsi;
@@ -745,12 +749,11 @@ public String getEffectiveOAuthRedirectUrl() {
745749
}
746750

747751
/**
748-
* Determines if Azure-specific OIDC endpoints should be used.
749-
* This is true in two cases:
750-
* 1. When auth type is not specified (this is only in case of external browser auth)
751-
* 2. When Azure client ID is present (service principal auth)
752+
* Determines if Azure-specific OIDC endpoints should be used. This is true in two cases: 1. When
753+
* auth type is not specified (this is only in case of external browser auth) 2. When Azure client
754+
* ID is present (service principal auth)
752755
*/
753-
private boolean shouldUseAzureOidcEndpoints() {
756+
boolean shouldUseAzureOidcEndpoints() {
754757
return Objects.equals(getAuthType(), null) || getAzureClientId() != null;
755758
}
756759
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,35 @@ public void testGetTokenSourceWithOAuth() {
251251
assertFalse(tokenSource instanceof ErrorTokenSource);
252252
assertEquals(tokenSource.getToken().getAccessToken(), "test-token");
253253
}
254+
255+
@Test
256+
public void testShouldUseAzureOidcEndpointsForExternalBrowserAuth() {
257+
DatabricksConfig config =
258+
new DatabricksConfig()
259+
.setHost("https://adb-1234567890.0.azuredatabricks.net/")
260+
.setAuthType(null);
261+
assertTrue(config.shouldUseAzureOidcEndpoints());
262+
}
263+
264+
@Test
265+
public void testShouldUseAzureOidcEndpointsForServicePrincipal() {
266+
DatabricksConfig config =
267+
new DatabricksConfig()
268+
.setHost("https://adb-1234567890.0.azuredatabricks.net/")
269+
.setAzureClientId("test-client-id")
270+
.setAzureClientSecret("test-client-secret")
271+
.setAzureTenantId("test-tenant-id");
272+
assertTrue(config.shouldUseAzureOidcEndpoints());
273+
}
274+
275+
@Test
276+
public void testShouldNotUseAzureOidcEndpointsForAzureM2M() {
277+
DatabricksConfig config =
278+
new DatabricksConfig()
279+
.setHost("https://adb-1234567890.0.azuredatabricks.net/")
280+
.setAuthType("oauth-m2m")
281+
.setClientId("test-client-id")
282+
.setClientSecret("test-client-secret");
283+
assertFalse(config.shouldUseAzureOidcEndpoints());
284+
}
254285
}

0 commit comments

Comments
 (0)