Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

=== Without account_id (should error)
Error: the command is being run in a non-interactive environment, please specify an account ID using --account-id

Exit code: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Test that unified host login requires account_id
# In non-interactive mode, this should fail with a helpful error message

sethome "./home"

title "Without account_id (should error)\n"
errcode $CLI auth login --host https://unified.databricks.com --experimental-is-unified-host --profile test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Ignore = [
"home"
]
6 changes: 6 additions & 0 deletions cmd/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func promptForAccountID(ctx context.Context) (string, error) {
prompt.Label = "Databricks account ID"
prompt.Default = ""
prompt.AllowEdit = true
prompt.Validate = func(s string) error {
if s == "" {
return errors.New("account ID is required")
}
return nil
}
return prompt.Run()
}

Expand Down
33 changes: 33 additions & 0 deletions cmd/auth/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package auth

import (
"context"
"errors"
"testing"

"github.com/databricks/cli/libs/auth"
Expand Down Expand Up @@ -169,6 +170,38 @@ func TestPromptForWorkspaceIdInNonInteractiveMode(t *testing.T) {
assert.Equal(t, "", workspaceID)
}

func TestSetAccountIdForUnifiedHost(t *testing.T) {
t.Setenv("DATABRICKS_CONFIG_FILE", "./testdata/.databrickscfg")
ctx, _ := cmdio.SetupTest(context.Background(), cmdio.TestOptions{})

// Test that unified host requires account_id - should prompt in non-interactive mode and fail
authArguments := auth.AuthArguments{
Host: "https://unified.databricks.com",
IsUnifiedHost: true,
}
err := setHostAndAccountId(ctx, nil, &authArguments, []string{})
assert.EqualError(t, err, "the command is being run in a non-interactive environment, please specify an account ID using --account-id")
}

func TestAccountIDValidationForUnifiedHost(t *testing.T) {
// Test the validation function used for unified hosts
// This validation is only applied when --experimental-is-unified-host is set
validate := func(s string) error {
if s == "" {
return errors.New("account ID is required")
}
return nil
}

// Test that empty string fails validation
err := validate("")
assert.EqualError(t, err, "account ID is required")

// Test that non-empty string passes validation
err = validate("some-account-id")
assert.NoError(t, err)
}

func TestLoadProfileByNameAndClusterID(t *testing.T) {
testCases := []struct {
name string
Expand Down