Strip trailing slash from host in auth and configure commands#4633
Strip trailing slash from host in auth and configure commands#4633varundeepsaini wants to merge 3 commits intodatabricks:mainfrom
Conversation
simonfaltum
left a comment
There was a problem hiding this comment.
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
cmd/auth/login.go
Outdated
| // 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, "/") |
There was a problem hiding this comment.
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?
16c3003 to
00ed36c
Compare
dfd5ed1 to
81f2d25
Compare
Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
81f2d25 to
5db8392
Compare
|
@simonfaltum could you run the ci ? |
|
An authorized user can trigger integration tests manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
Fixes #4628
Summary
setHostAndAccountId(used byauth loginandauth token)normalizeHost(used bydatabricks configure)Test plan
setHostAndAccountId(flag and positional arg)normalizeHosttest expectations for trailing slash inputs