@@ -43,6 +43,7 @@ func TestLogin(t *testing.T) {
43
43
"username" ,"testuser" ,
44
44
"email" ,"user@coder.com" ,
45
45
"password" ,"password" ,
46
+ "password" ,"password" ,// Confirm.
46
47
}
47
48
for i := 0 ;i < len (matches );i += 2 {
48
49
match := matches [i ]
@@ -54,6 +55,44 @@ func TestLogin(t *testing.T) {
54
55
<- doneChan
55
56
})
56
57
58
+ t .Run ("InitialUserTTYConfirmPasswordFailAndReprompt" ,func (t * testing.T ) {
59
+ t .Parallel ()
60
+ ctx ,cancel := context .WithCancel (context .Background ())
61
+ defer cancel ()
62
+ client := coderdtest .New (t ,nil )
63
+ // The --force-tty flag is required on Windows, because the `isatty` library does not
64
+ // accurately detect Windows ptys when they are not attached to a process:
65
+ // https://github.com/mattn/go-isatty/issues/59
66
+ doneChan := make (chan struct {})
67
+ root ,_ := clitest .New (t ,"login" ,"--force-tty" ,client .URL .String ())
68
+ pty := ptytest .New (t )
69
+ root .SetIn (pty .Input ())
70
+ root .SetOut (pty .Output ())
71
+ go func () {
72
+ defer close (doneChan )
73
+ err := root .ExecuteContext (ctx )
74
+ require .ErrorIs (t ,err ,context .Canceled )
75
+ }()
76
+
77
+ matches := []string {
78
+ "first user?" ,"yes" ,
79
+ "username" ,"testuser" ,
80
+ "email" ,"user@coder.com" ,
81
+ "password" ,"mypass" ,
82
+ "password" ,"wrongpass" ,// Confirm.
83
+ }
84
+ for i := 0 ;i < len (matches );i += 2 {
85
+ match := matches [i ]
86
+ value := matches [i + 1 ]
87
+ pty .ExpectMatch (match )
88
+ pty .WriteLine (value )
89
+ }
90
+ pty .ExpectMatch ("Passwords do not match" )
91
+ pty .ExpectMatch ("password" )// Re-prompt password.
92
+ cancel ()
93
+ <- doneChan
94
+ })
95
+
57
96
t .Run ("ExistingUserValidTokenTTY" ,func (t * testing.T ) {
58
97
t .Parallel ()
59
98
client := coderdtest .New (t ,nil )