@@ -16,6 +16,7 @@ import (
16
16
17
17
"github.com/coder/coder/v2/coderd/httpapi"
18
18
"github.com/coder/coder/v2/codersdk"
19
+ "github.com/coder/coder/v2/testutil"
19
20
)
20
21
21
22
func TestInternalServerError (t * testing.T ) {
@@ -158,9 +159,25 @@ func TestWebsocketCloseMsg(t *testing.T) {
158
159
159
160
func TestOneWayWebSocket (t * testing.T ) {
160
161
t .Parallel ()
162
+ url := "ws://www.fake-website.com/logs"
161
163
162
164
t .Run ("Produces an error if the socket connection could not be established" , func (t * testing.T ) {
163
165
t .Parallel ()
166
+
167
+ // WebSocket connections cannot be created on HTTP/1.0 and below
168
+ ctx := testutil .Context (t , testutil .WaitShort )
169
+ r , err := http .NewRequestWithContext (ctx , http .MethodGet , url , nil )
170
+ require .NoError (t , err )
171
+ r .ProtoMajor = 1
172
+ r .ProtoMinor = 0
173
+ r .Proto = "HTTP/1.0"
174
+
175
+ _ , _ , err = httpapi .OneWayWebSocket [any ](httptest .NewRecorder (), r )
176
+ require .ErrorContains (
177
+ t ,
178
+ err ,
179
+ "WebSocket protocol violation: handshake request must be at least HTTP/1.1:" ,
180
+ )
164
181
})
165
182
166
183
t .Run ("Returned callback can publish a new event to the WebSocket connection" , func (t * testing.T ) {
@@ -183,7 +200,7 @@ func TestOneWayWebSocket(t *testing.T) {
183
200
t .Parallel ()
184
201
})
185
202
186
- t .Run ("Renders the socket inert if the parent context cancels" , func (t * testing.T ) {
203
+ t .Run ("Renders the socket inert if the request context cancels" , func (t * testing.T ) {
187
204
t .Parallel ()
188
205
})
189
206
}
0 commit comments