MCPcopy Index your code
hub / github.com/coder/coder / TestResetPassword

Function TestResetPassword

cli/resetpassword_test.go:20–110  ·  view source on GitHub ↗

nolint:paralleltest

(t *testing.T)

Source from the content-addressed store, hash-verified

18
19// nolint:paralleltest
20func TestResetPassword(t *testing.T) {
21 // dbtestutil.Open() seems to be creating race conditions when run in parallel.
22 // t.Parallel()
23
24 if runtime.GOOS != "linux" || testing.Short() {
25 // Skip on non-Linux because it spawns a PostgreSQL instance.
26 t.SkipNow()
27 }
28
29 const email = "some@one.com"
30 const username = "example"
31 const oldPassword = "MyOldPassword!"
32 const newPassword = "MyNewPassword!"
33
34 // start postgres and coder server processes
35 connectionURL, err := dbtestutil.Open(t)
36 require.NoError(t, err)
37 ctx, cancelFunc := context.WithCancel(context.Background())
38 serverDone := make(chan struct{})
39 serverinv, cfg := clitest.New(t,
40 "server",
41 "--http-address", ":0",
42 "--access-url", "http://example.com",
43 "--postgres-url", connectionURL,
44 "--cache-dir", t.TempDir(),
45 )
46 go func() {
47 defer close(serverDone)
48 err = serverinv.WithContext(ctx).Run()
49 assert.NoError(t, err)
50 }()
51 var rawURL string
52 require.Eventually(t, func() bool {
53 rawURL, err = cfg.URL().Read()
54 return err == nil && rawURL != ""
55 }, testutil.WaitLong, testutil.IntervalFast)
56 accessURL, err := url.Parse(rawURL)
57 require.NoError(t, err)
58 client := codersdk.New(accessURL)
59
60 _, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{
61 Email: email,
62 Username: username,
63 Password: oldPassword,
64 })
65 require.NoError(t, err)
66
67 // reset the password
68
69 resetinv, cmdCfg := clitest.New(t, "reset-password", "--postgres-url", connectionURL, username)
70 clitest.SetupConfig(t, client, cmdCfg)
71 cmdDone := make(chan struct{})
72 pty := ptytest.New(t)
73 resetinv.Stdin = pty.Input()
74 resetinv.Stdout = pty.Output()
75 go func() {
76 defer close(cmdDone)
77 err = resetinv.Run()

Callers

nothing calls this directly

Calls 15

OpenFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
SkipNowMethod · 0.80
WithContextMethod · 0.80
CreateFirstUserMethod · 0.80
WriteLineMethod · 0.80
LoginWithPasswordMethod · 0.80
TempDirMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected