-
Notifications
You must be signed in to change notification settings - Fork 2k
Prep before SSO login flow work #798
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
db8dfce
Clean up login a bit and start using cobra
23815f9
Handle cancellation
784ab47
Add a login test before doing sso work
d0ac202
Restructure to avoid race condition with user interaction
db6a402
Check non-nil of analytics resp before using
1dd6940
http methods no longer using default mux, better error reporting in test
39b8f89
Use a graceful shutdown of the server
da2ac2f
Merge branch 'main' into gsoltis/add_login_test
eab6459
Merge branch 'main' into gsoltis/add_login_test
jaredpalmer 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package login | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/hashicorp/go-hclog" | ||
"github.com/vercel/turborepo/cli/internal/client" | ||
"github.com/vercel/turborepo/cli/internal/config" | ||
"github.com/vercel/turborepo/cli/internal/ui" | ||
) | ||
|
||
type dummyClient struct { | ||
setToken string | ||
} | ||
|
||
func (d *dummyClient) SetToken(t string) { | ||
d.setToken = t | ||
} | ||
|
||
func (d *dummyClient) GetUser() (*client.UserResponse, error) { | ||
return &client.UserResponse{}, nil | ||
} | ||
|
||
func Test_run(t *testing.T) { | ||
logger := hclog.Default() | ||
cf := &config.Config{ | ||
Logger: logger, | ||
TurboVersion: "test", | ||
ApiUrl: "api-url", | ||
LoginUrl: "login-url", | ||
} | ||
|
||
ch := make(chan struct{}, 1) | ||
openedURL := "" | ||
urlOpener := func(url string) error { | ||
openedURL = url | ||
ch <- struct{}{} | ||
return nil | ||
} | ||
|
||
// When we get the ping, send a token | ||
var clientErr error | ||
go func() { | ||
<-ch | ||
client := &http.Client{ | ||
CheckRedirect: func(req *http.Request, via []*http.Request) error { | ||
return http.ErrUseLastResponse | ||
}, | ||
} | ||
resp, err := client.Get("http://127.0.0.1:9789/?token=my-token") | ||
if err != nil { | ||
clientErr = err | ||
} else if resp != nil && resp.StatusCode != http.StatusFound { | ||
clientErr = fmt.Errorf("invalid status %v", resp.StatusCode) | ||
} | ||
ch <- struct{}{} | ||
}() | ||
|
||
var writtenConfig *config.TurborepoConfig | ||
writeConfig := func(cf *config.TurborepoConfig) error { | ||
writtenConfig = cf | ||
return nil | ||
} | ||
|
||
client := &dummyClient{} | ||
err := run(cf, loginDeps{ | ||
openURL: urlOpener, | ||
ui: ui.Default(), | ||
writeConfig: writeConfig, | ||
client: client, | ||
}) | ||
if err != nil { | ||
t.Errorf("expected to succeed, got error %v", err) | ||
} | ||
<-ch | ||
if clientErr != nil { | ||
t.Errorf("test client had error %v", clientErr) | ||
} | ||
|
||
expectedURL := "login-url/turborepo/token?redirect_uri=http://127.0.0.1:9789" | ||
if openedURL != expectedURL { | ||
t.Errorf("openedURL got %v, want %v", openedURL, expectedURL) | ||
} | ||
|
||
if writtenConfig.Token != "my-token" { | ||
t.Errorf("config token got %v, want my-token", writtenConfig.Token) | ||
} | ||
if client.setToken != "my-token" { | ||
t.Errorf("user client token got %v, want my-token", client.setToken) | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:smart_meme: