-
Notifications
You must be signed in to change notification settings - Fork 894
feat: Generate random admin user password in dev mode #1207
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
mafredri
merged 9 commits into
main
from
mafredri/feat-generate-random-dev-user-password
Apr 28, 2022
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
058b088
feat: Generate random admin user password in dev mode
mafredri e00c48c
Fix flaky test with done channel
mafredri 045260d
Add dev mode test with email/pass from env
mafredri 43f45ff
Fix typo
mafredri 72908d4
Set nolint for non-parallel test
mafredri ffcd5d9
Use t.Setenv for cleaner code
mafredri a277e8c
Set email/pass for playwright e2e test via cli flags
mafredri 80dddd2
Run prettier --write
mafredri 0026a12
Use sync.WaitGroup instead of channel
mafredri 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
Add dev mode test with email/pass from env
- Loading branch information
commit 045260dd8b4d48402590116821f55ae4186c3e6d
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,52 @@ func TestServer(t *testing.T) { | |
cancelFunc() | ||
<-done | ||
}) | ||
// Duplicated test from "Development" above to test setting email/password via env. | ||
t.Run("Development with email and password from env", func(t *testing.T) { | ||
// Cannot run parallell due to os.Setenv. | ||
ctx, cancelFunc := context.WithCancel(context.Background()) | ||
defer cancelFunc() | ||
|
||
wantEmail := "myadmin@coder.com" | ||
wantPassword := "testpass42" | ||
os.Setenv("CODER_DEV_ADMIN_EMAIL", wantEmail) | ||
defer os.Unsetenv("CODER_DEV_ADMIN_EMAIL") | ||
os.Setenv("CODER_DEV_ADMIN_PASSWORD", wantPassword) | ||
defer os.Unsetenv("CODER_DEV_ADMIN_PASSWORD") | ||
|
||
root, cfg := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0") | ||
var buf strings.Builder | ||
root.SetOutput(&buf) | ||
done := make(chan struct{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: another way to do this is to use
|
||
go func() { | ||
defer close(done) | ||
|
||
err := root.ExecuteContext(ctx) | ||
require.ErrorIs(t, err, context.Canceled) | ||
|
||
// Verify that credentials were output to the terminal. | ||
assert.Contains(t, buf.String(), fmt.Sprintf("email: %s", wantEmail), "expected output %q; got no match", wantEmail) | ||
assert.Contains(t, buf.String(), fmt.Sprintf("password: %s", wantPassword), "expected output %q; got no match", wantPassword) | ||
}() | ||
var token string | ||
require.Eventually(t, func() bool { | ||
var err error | ||
token, err = cfg.Session().Read() | ||
return err == nil | ||
}, 15*time.Second, 25*time.Millisecond) | ||
// Verify that authentication was properly set in dev-mode. | ||
accessURL, err := cfg.URL().Read() | ||
require.NoError(t, err) | ||
parsed, err := url.Parse(accessURL) | ||
require.NoError(t, err) | ||
client := codersdk.New(parsed) | ||
client.SessionToken = token | ||
_, err = client.User(ctx, codersdk.Me) | ||
require.NoError(t, err) | ||
|
||
cancelFunc() | ||
<-done | ||
}) | ||
t.Run("TLSBadVersion", func(t *testing.T) { | ||
t.Parallel() | ||
ctx, cancelFunc := context.WithCancel(context.Background()) | ||
|
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.
t.Setenv
handles this for you :-)