-
Notifications
You must be signed in to change notification settings - Fork 36
Add new OIDC Auth integration tests #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hectorcast-db
wants to merge
3
commits into
main
Choose a base branch
from
add-oidc-auth-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
...bricks-sdk-java/src/test/java/com/databricks/sdk/integration/DatabricksOidcAccountIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package com.databricks.sdk.integration; | ||
|
|
||
| import com.databricks.sdk.AccountClient; | ||
| import com.databricks.sdk.core.DatabricksConfig; | ||
| import com.databricks.sdk.integration.framework.EnvContext; | ||
| import com.databricks.sdk.integration.framework.EnvOrSkip; | ||
| import com.databricks.sdk.integration.framework.EnvTest; | ||
| import com.databricks.sdk.service.iam.ListAccountServicePrincipalsRequest; | ||
| import com.databricks.sdk.service.iam.ServicePrincipal; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| @ExtendWith(EnvTest.class) | ||
| @EnvContext("account") | ||
| public class DatabricksOidcAccountIT { | ||
| private static final Logger LOG = LoggerFactory.getLogger(DatabricksOidcAccountIT.class); | ||
|
|
||
| @Test | ||
| void testAccountOAuthM2MAuth( | ||
| @EnvOrSkip("CLOUD_ENV") String cloudEnv, | ||
| @EnvOrSkip("DATABRICKS_HOST") String host, | ||
| @EnvOrSkip("DATABRICKS_ACCOUNT_ID") String accountId, | ||
| @EnvOrSkip("TEST_DATABRICKS_CLIENT_ID") String clientId, | ||
| @EnvOrSkip("TEST_DATABRICKS_CLIENT_SECRET") String clientSecret) { | ||
| LOG.info("Cloud environment: {}", cloudEnv); | ||
|
|
||
| // Create account client with OAuth M2M authentication | ||
| DatabricksConfig config = | ||
| new DatabricksConfig() | ||
| .setHost(host) | ||
| .setAccountId(accountId) | ||
| .setClientId(clientId) | ||
| .setClientSecret(clientSecret) | ||
| .setAuthType("oauth-m2m"); | ||
|
|
||
| AccountClient ac = new AccountClient(config); | ||
|
|
||
| // List service principals to verify authentication works | ||
| Iterable<ServicePrincipal> servicePrincipals = | ||
| ac.servicePrincipals().list(new ListAccountServicePrincipalsRequest()); | ||
| servicePrincipals.iterator().next(); | ||
| } | ||
|
|
||
| @Test | ||
| void testAccountAzureClientSecretAuth( | ||
| @EnvOrSkip("CLOUD_ENV") String cloudEnv, | ||
| @EnvOrSkip("DATABRICKS_HOST") String host, | ||
| @EnvOrSkip("DATABRICKS_ACCOUNT_ID") String accountId, | ||
| @EnvOrSkip("ARM_CLIENT_ID") String azureClientId, | ||
| @EnvOrSkip("ARM_CLIENT_SECRET") String azureClientSecret, | ||
| @EnvOrSkip("ARM_TENANT_ID") String azureTenantId) { | ||
| LOG.info("Cloud environment: {}", cloudEnv); | ||
|
|
||
| // Create account client with Azure client secret authentication | ||
| DatabricksConfig config = | ||
| new DatabricksConfig() | ||
| .setHost(host) | ||
| .setAccountId(accountId) | ||
| .setAzureClientId(azureClientId) | ||
| .setAzureClientSecret(azureClientSecret) | ||
| .setAzureTenantId(azureTenantId) | ||
| .setAuthType("azure-client-secret"); | ||
|
|
||
| AccountClient ac = new AccountClient(config); | ||
|
|
||
| // List service principals to verify authentication works | ||
| Iterable<ServicePrincipal> servicePrincipals = | ||
| ac.servicePrincipals().list(new ListAccountServicePrincipalsRequest()); | ||
| servicePrincipals.iterator().next(); | ||
| } | ||
| } |
72 changes: 72 additions & 0 deletions
72
...icks-sdk-java/src/test/java/com/databricks/sdk/integration/DatabricksOidcWorkspaceIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package com.databricks.sdk.integration; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| import com.databricks.sdk.WorkspaceClient; | ||
| import com.databricks.sdk.core.DatabricksConfig; | ||
| import com.databricks.sdk.integration.framework.EnvContext; | ||
| import com.databricks.sdk.integration.framework.EnvOrSkip; | ||
| import com.databricks.sdk.integration.framework.EnvTest; | ||
| import com.databricks.sdk.service.iam.User; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| @ExtendWith(EnvTest.class) | ||
| @EnvContext("ucws") | ||
| public class DatabricksOidcWorkspaceIT { | ||
| private static final Logger LOG = LoggerFactory.getLogger(DatabricksOidcWorkspaceIT.class); | ||
|
|
||
| @Test | ||
| void testWorkspaceOAuthM2MAuth( | ||
| @EnvOrSkip("CLOUD_ENV") String cloudEnv, | ||
| @EnvOrSkip("DATABRICKS_HOST") String host, | ||
| @EnvOrSkip("TEST_DATABRICKS_CLIENT_ID") String clientId, | ||
| @EnvOrSkip("TEST_DATABRICKS_CLIENT_SECRET") String clientSecret) { | ||
| LOG.info("Cloud environment: {}", cloudEnv); | ||
|
|
||
| // Create workspace client with OAuth M2M authentication | ||
| DatabricksConfig config = | ||
| new DatabricksConfig() | ||
| .setHost(host) | ||
| .setClientId(clientId) | ||
| .setClientSecret(clientSecret) | ||
| .setAuthType("oauth-m2m"); | ||
|
|
||
| WorkspaceClient ws = new WorkspaceClient(config); | ||
|
|
||
| // Call the "me" API | ||
| User me = ws.currentUser().me(); | ||
|
|
||
| // Verify we got a valid response | ||
| assertNotNull(me.getUserName(), "Expected non-empty UserName"); | ||
| } | ||
|
|
||
| @Test | ||
| void testWorkspaceAzureClientSecretAuth( | ||
| @EnvOrSkip("CLOUD_ENV") String cloudEnv, | ||
| @EnvOrSkip("DATABRICKS_HOST") String host, | ||
| @EnvOrSkip("ARM_CLIENT_ID") String azureClientId, | ||
| @EnvOrSkip("ARM_CLIENT_SECRET") String azureClientSecret, | ||
| @EnvOrSkip("ARM_TENANT_ID") String azureTenantId) { | ||
| LOG.info("Cloud environment: {}", cloudEnv); | ||
|
|
||
| // Create workspace client with Azure client secret authentication | ||
| DatabricksConfig config = | ||
| new DatabricksConfig() | ||
| .setHost(host) | ||
| .setAzureClientId(azureClientId) | ||
| .setAzureClientSecret(azureClientSecret) | ||
| .setAzureTenantId(azureTenantId) | ||
| .setAuthType("azure-client-secret"); | ||
|
|
||
| WorkspaceClient ws = new WorkspaceClient(config); | ||
|
|
||
| // Call the "me" API | ||
| User me = ws.currentUser().me(); | ||
|
|
||
| // Verify we got a valid response | ||
| assertNotNull(me.getUserName(), "Expected non-empty UserName"); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are running this only for ucws?