-
Notifications
You must be signed in to change notification settings - Fork 27
[CFX-6319] Actionable recovery path and --timeout on a login timeout #915
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
chasdr
wants to merge
9
commits into
main
Choose a base branch
from
chas/CFX-6319-timeout-recovery
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
Show all changes
9 commits
Select commit
Hold shift + click to select a range
368d1a8
[CFX-6319] feat(auth): recovery help and --timeout on login timeout
chasdr accdc79
[CFX-6319] docs(auth): login-timeout recovery path and --timeout
chasdr 6afe063
[CFX-6319] test(auth): assert.Less over assert.True for the timeout b…
chasdr 6128bb0
[CFX-6319] fix(auth): address bot review on the login-timeout help
chasdr e63cbd4
[CFX-6319] fix(auth): PowerShell syntax in the timeout help on Windows
chasdr c64c24b
[CFX-6319] fix(auth): friendly timeout in the templates setup login
chasdr 0d53ed5
[CFX-6319] fix(auth): errMsg.Unwrap so the setup timeout branch fires
chasdr 18290ac
[CFX-6319] fix(auth): shell-quote the endpoint in the timeout help
chasdr 1d8447d
[CFX-6319] fix(auth): name the env vars in prose, drop the copy-paste…
chasdr 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
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
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,105 @@ | ||
| // Copyright 2026 DataRobot, Inc. and its affiliates. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package login | ||
|
|
||
| import ( | ||
| "context" | ||
| "io" | ||
| "os" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/datarobot/cli/internal/cli" | ||
| "github.com/datarobot/cli/internal/config" | ||
| "github.com/datarobot/cli/internal/config/viperx" | ||
| "github.com/datarobot/cli/internal/testutil" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestCmd_HasTimeoutFlag(t *testing.T) { | ||
| cmd := Cmd() | ||
|
|
||
| f := cmd.Flags().Lookup("timeout") | ||
| require.NotNil(t, f, "dr auth login must expose --timeout") | ||
| assert.Equal(t, "0s", f.DefValue, "zero default means DefaultLoginTimeout applies") | ||
|
|
||
| require.NoError(t, cmd.Flags().Set("timeout", "30s")) | ||
|
|
||
| got, err := cmd.Flags().GetDuration("timeout") | ||
| require.NoError(t, err) | ||
| assert.Equal(t, 30*time.Second, got) | ||
| } | ||
|
|
||
| func TestCmd_HasNoBrowserFlag(t *testing.T) { | ||
| assert.NotNil(t, Cmd().Flags().Lookup("no-browser"), "dr auth login must keep --no-browser") | ||
| } | ||
|
|
||
| // TestRunE_TimeoutPrintsHelpAndReturnsSilent drives the timeout branch end to end: | ||
| // a tiny --timeout with no browser and a dead endpoint reaches ErrLoginTimedOut fast. | ||
| func TestRunE_TimeoutPrintsHelpAndReturnsSilent(t *testing.T) { | ||
| testutil.SetTestHomeDir(t, t.TempDir()) | ||
| t.Setenv("DATAROBOT_ENDPOINT", "") | ||
| t.Setenv("DATAROBOT_API_TOKEN", "") | ||
|
|
||
| viperx.Reset() | ||
| t.Cleanup(viperx.Reset) | ||
| viperx.Set(config.DataRobotURL, "https://nonexistent.invalid") | ||
|
|
||
| cmd := Cmd() | ||
| cmd.SetContext(context.Background()) | ||
| require.NoError(t, cmd.Flags().Set("no-browser", "true")) | ||
| require.NoError(t, cmd.Flags().Set("timeout", "50ms")) | ||
|
|
||
| oldOut, oldErr := os.Stdout, os.Stderr | ||
| rOut, wOut, err := os.Pipe() | ||
| require.NoError(t, err) | ||
|
|
||
| rErr, wErr, err := os.Pipe() | ||
| require.NoError(t, err) | ||
|
|
||
| os.Stdout, os.Stderr = wOut, wErr | ||
|
|
||
| runErr := RunE(cmd, nil) | ||
|
|
||
| require.NoError(t, wOut.Close()) | ||
| require.NoError(t, wErr.Close()) | ||
|
|
||
| os.Stdout, os.Stderr = oldOut, oldErr | ||
|
|
||
| stderr, _ := io.ReadAll(rErr) | ||
| _, _ = io.ReadAll(rOut) | ||
|
|
||
| require.ErrorIs(t, runErr, cli.ErrSilent, "a timeout returns the silent sentinel, not the raw error") | ||
| assert.Contains(t, string(stderr), "authorization came back", "the recovery help must reach stderr") | ||
| } | ||
|
|
||
| func TestRunE_RejectsNegativeTimeout(t *testing.T) { | ||
| testutil.SetTestHomeDir(t, t.TempDir()) | ||
| t.Setenv("DATAROBOT_ENDPOINT", "") | ||
| t.Setenv("DATAROBOT_API_TOKEN", "") | ||
|
|
||
| viperx.Reset() | ||
| t.Cleanup(viperx.Reset) | ||
| viperx.Set(config.DataRobotURL, "https://nonexistent.invalid") | ||
|
|
||
| cmd := Cmd() | ||
| cmd.SetContext(context.Background()) | ||
| require.NoError(t, cmd.Flags().Set("no-browser", "true")) | ||
| require.NoError(t, cmd.Flags().Set("timeout", "-1s")) | ||
|
|
||
| err := RunE(cmd, nil) | ||
| assert.ErrorIs(t, err, cli.ErrSilent, "a negative --timeout is rejected before the browser flow starts") | ||
| } |
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
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.