@@ -22,7 +22,6 @@ import (
22
22
"github.com/stretchr/testify/assert"
23
23
"github.com/stretchr/testify/require"
24
24
"golang.org/x/xerrors"
25
- "nhooyr.io/websocket"
26
25
27
26
"github.com/coder/coder/coderd/coderdtest"
28
27
"github.com/coder/coder/coderd/rbac"
@@ -72,7 +71,13 @@ func Run(t *testing.T, factory DeploymentFactory) {
72
71
// Run the test against the path app hostname since that's where the
73
72
// reconnecting-pty proxy server we want to test is mounted.
74
73
client := appDetails .AppClient (t )
75
- conn , err := client .WorkspaceAgentReconnectingPTY (ctx , appDetails .Agent .ID , uuid .New (), 80 , 80 , "/bin/bash" )
74
+ conn , err := client .WorkspaceAgentReconnectingPTY (ctx , codersdk.WorkspaceAgentReconnectingPTYOpts {
75
+ AgentID : appDetails .Agent .ID ,
76
+ Reconnect : uuid .New (),
77
+ Height : 80 ,
78
+ Width : 80 ,
79
+ Command : "/bin/bash" ,
80
+ })
76
81
require .NoError (t , err )
77
82
defer conn .Close ()
78
83
@@ -125,29 +130,42 @@ func Run(t *testing.T, factory DeploymentFactory) {
125
130
})
126
131
require .NoError (t , err )
127
132
128
- // Try to connect to the endpoint with the signed token and no other
129
- // authentication.
130
- q := u .Query ()
131
- q .Set ("reconnect" , uuid .NewString ())
132
- q .Set ("height" , strconv .Itoa (24 ))
133
- q .Set ("width" , strconv .Itoa (80 ))
134
- q .Set ("command" , `/bin/sh -c "echo test"` )
135
- q .Set (codersdk .SignedAppTokenQueryParameter , issueRes .SignedToken )
136
- u .RawQuery = q .Encode ()
137
-
138
- //nolint:bodyclose
139
- wsConn , res , err := websocket .Dial (ctx , u .String (), nil )
140
- if ! assert .NoError (t , err ) {
141
- dump , err := httputil .DumpResponse (res , true )
142
- if err == nil {
143
- t .Log (string (dump ))
144
- }
145
- return
146
- }
147
- defer wsConn .Close (websocket .StatusNormalClosure , "" )
148
- conn := websocket .NetConn (ctx , wsConn , websocket .MessageBinary )
133
+ // Make an unauthenticated client.
134
+ unauthedAppClient := codersdk .New (appDetails .AppClient (t ).URL )
135
+ conn , err := unauthedAppClient .WorkspaceAgentReconnectingPTY (ctx , codersdk.WorkspaceAgentReconnectingPTYOpts {
136
+ AgentID : appDetails .Agent .ID ,
137
+ Reconnect : uuid .New (),
138
+ Height : 80 ,
139
+ Width : 80 ,
140
+ Command : "/bin/bash" ,
141
+ SignedToken : issueRes .SignedToken ,
142
+ })
143
+ require .NoError (t , err )
144
+ defer conn .Close ()
145
+
146
+ // First attempt to resize the TTY.
147
+ // The websocket will close if it fails!
148
+ data , err := json .Marshal (codersdk.ReconnectingPTYRequest {
149
+ Height : 250 ,
150
+ Width : 250 ,
151
+ })
152
+ require .NoError (t , err )
153
+ _ , err = conn .Write (data )
154
+ require .NoError (t , err )
149
155
bufRead := bufio .NewReader (conn )
150
156
157
+ // Brief pause to reduce the likelihood that we send keystrokes while
158
+ // the shell is simultaneously sending a prompt.
159
+ time .Sleep (100 * time .Millisecond )
160
+
161
+ data , err = json .Marshal (codersdk.ReconnectingPTYRequest {
162
+ Data : "echo test\r \n " ,
163
+ })
164
+ require .NoError (t , err )
165
+ _ , err = conn .Write (data )
166
+ require .NoError (t , err )
167
+
168
+ expectLine (t , bufRead , matchEchoCommand )
151
169
expectLine (t , bufRead , matchEchoOutput )
152
170
})
153
171
})
0 commit comments