Skip to content
Open
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
1 change: 1 addition & 0 deletions .nextchanges/bundles/7948.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fix the bundle auth error "the host in the profile doesn’t match the host configured in the bundle" when only one of the hosts includes the default port, such as `:443`. ([#7948](https://github.com/databricks/cli/pull/7948))
17 changes: 17 additions & 0 deletions bundle/config/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,23 @@ func TestWorkspaceVerifyProfileForHost(t *testing.T) {
assert.NoError(t, err)
})

t.Run("default config file with match on the default port", func(t *testing.T) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] This fix removes a user-visible bundle error, but it is only covered by this Go unit test. .agents/rules/testing.md says user-visible CLI behavior gets acceptance tests first, extending an existing directory. Could acceptance/auth/bundle_and_profile get a case with workspace.host: https://<host>:443 and a profile without the port? Its golden would then show the command succeeding where it used to fail with "the host in the profile ... doesn’t match the host configured in the bundle".

setupWorkspaceTest(t)

err := databrickscfg.SaveToProfile(t.Context(), &config.Config{
Profile: "abc",
Host: "https://abc.test",
})
require.NoError(t, err)

w := Workspace{
Host: "https://abc.test:443",
Profile: "abc",
}
_, err = w.Client(t.Context())
assert.NoError(t, err)
})

t.Run("default config file with mismatch", func(t *testing.T) {
setupWorkspaceTest(t)

Expand Down
3 changes: 2 additions & 1 deletion cmd/configure/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

// normalizeHost ensures a https:// scheme is present and returns only scheme
// and host, consistent with the normalizeHost in libs/databrickscfg/host.go.
// and host, like the normalizeHost in libs/databrickscfg/host.go, which also
// drops the default port when matching profiles.
func normalizeHost(input string) string {
input = strings.TrimSpace(input)
u, err := url.Parse(input)
Expand Down
11 changes: 9 additions & 2 deletions libs/databrickscfg/host.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package databrickscfg

import "net/url"
import (
"net/url"
"strings"
)

// normalizeHost returns the string representation of only
// the scheme and host part of the specified host.
// the scheme and host part of the specified host, without
// the scheme's default port.
func normalizeHost(host string) string {
u, err := url.Parse(host)
if err != nil {
Expand All @@ -17,6 +21,9 @@ func normalizeHost(host string) string {
Scheme: u.Scheme,
Host: u.Host,
}
if port := u.Port(); (u.Scheme == "https" && port == "443") || (u.Scheme == "http" && port == "80") {
normalized.Host = strings.TrimSuffix(u.Host, ":"+port)
}

return normalized.String()
}
6 changes: 6 additions & 0 deletions libs/databrickscfg/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ func TestNormalizeHost(t *testing.T) {

// With port.
assert.Equal(t, "http://foo:123", normalizeHost("http://foo:123"))
assert.Equal(t, "https://foo:80", normalizeHost("https://foo:80"))

// With the scheme's default port.
assert.Equal(t, "https://foo", normalizeHost("https://foo:443"))
assert.Equal(t, "http://foo", normalizeHost("http://foo:80/"))
assert.Equal(t, "https://[::1]", normalizeHost("https://[::1]:443"))

// With trailing slash.
assert.Equal(t, "http://foo", normalizeHost("http://foo/"))
Expand Down
Loading