Skip to content

Strip trailing slash from host in auth and configure commands#4633

Open
varundeepsaini wants to merge 3 commits intodatabricks:mainfrom
varundeepsaini:fix-auto-strip-backslash-auth-host
Open

Strip trailing slash from host in auth and configure commands#4633
varundeepsaini wants to merge 3 commits intodatabricks:mainfrom
varundeepsaini:fix-auto-strip-backslash-auth-host

Conversation

@varundeepsaini
Copy link
Contributor

Fixes #4628

Summary

  • Strip trailing slash from host URL in setHostAndAccountId (used by auth login and auth token)
  • Strip trailing slash in normalizeHost (used by databricks configure)

Test plan

  • Added test cases for trailing slash stripping in setHostAndAccountId (flag and positional arg)
  • Updated normalizeHost test expectations for trailing slash inputs
  • Verified all existing tests pass

simonfaltum
simonfaltum previously approved these changes Mar 3, 2026
Copy link
Member

@simonfaltum simonfaltum left a comment

Choose a reason for hiding this comment

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

LGTM

@simonfaltum simonfaltum dismissed their stale review March 3, 2026 11:53

Just taking another look

Copy link
Member

@simonfaltum simonfaltum left a comment

Choose a reason for hiding this comment

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

Had an extra look. Would you be up for adding some tests for the auth token path?
The setHostAndAccountId function is also called from cmd/auth/token.go:166 and token.go:426

// Strip trailing slash from host. Users often copy-paste URLs with a
// trailing slash from browsers or docs; normalize here to avoid errors
// from downstream validation in the SDK.
authArguments.Host = strings.TrimRight(authArguments.Host, "/")
Copy link
Member

Choose a reason for hiding this comment

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

Using strings.TrimRight(input, "/"), which strips all trailing / characters from the right side of the string, character by character. I think this is subtly wrong for edge cases.

Look at the test expectation on line 32 of host_test.go: {"https://", "https:"},

TrimRight("https://", "/") strips both trailing slashes from https://, producing "https:". That's clearly broken. The input https:// is an invalid host either way, but the function is now actively mangling it in a confusing way. I think the correct function to use is strings.TrimSuffix(input, "/") which only removes a single trailing /.

For https://example.com/ both functions produce the same result, but TrimRight is a future trap for multi-slash paths or edge cases, I think?

@varundeepsaini varundeepsaini force-pushed the fix-auto-strip-backslash-auth-host branch from 16c3003 to 00ed36c Compare March 3, 2026 12:47
@varundeepsaini varundeepsaini force-pushed the fix-auto-strip-backslash-auth-host branch 2 times, most recently from dfd5ed1 to 81f2d25 Compare March 3, 2026 12:51
Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
@varundeepsaini varundeepsaini force-pushed the fix-auto-strip-backslash-auth-host branch from 81f2d25 to 5db8392 Compare March 3, 2026 12:58
Copy link
Member

@simonfaltum simonfaltum left a comment

Choose a reason for hiding this comment

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

Thanks Varun! LGTM

@varundeepsaini
Copy link
Contributor Author

varundeepsaini commented Mar 3, 2026

@simonfaltum could you run the ci ?

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

An authorized user can trigger integration tests manually by following the instructions below:

Trigger:
go/deco-tests-run/cli

Inputs:

  • PR number: 4633
  • Commit SHA: 5149e4611294a209290a64bdd3fbf9fa1cb92796

Checks will be approved automatically on success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

databricks auth login: strip trailing slash from host instead of erroring

2 participants