File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed
Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 11Juan Antonio Martín Lucas <dev@jaml.pro>
22Aurora Nockert <aurora@aventine.se>
3+ Thomas Morgan <tm@iprog.com>
Original file line number Diff line number Diff line change @@ -20,9 +20,10 @@ class UpgradeRequest < ::Protocol::HTTP::Request
2020 include ::Protocol ::WebSocket ::Headers
2121
2222 class Wrapper
23- def initialize ( response )
23+ def initialize ( response , verified : )
2424 @response = response
2525 @stream = nil
26+ @verified = verified
2627 end
2728
2829 def close
@@ -32,7 +33,7 @@ def close
3233 attr_accessor :response
3334
3435 def stream?
35- @response . status == 101
36+ @response . status == 101 && @verified
3637 end
3738
3839 def status
@@ -74,7 +75,7 @@ def call(connection)
7475 end
7576 end
7677
77- return Wrapper . new ( response )
78+ return Wrapper . new ( response , verified : !! accept_digest )
7879 end
7980 end
8081 end
Original file line number Diff line number Diff line change 110110 with 'http/1' do
111111 let ( :protocol ) { Async ::HTTP ::Protocol ::HTTP1 }
112112 it_behaves_like ClientExamples
113+
114+ with 'invalid sec-websocket-accept header' do
115+ let ( :app ) do
116+ Protocol ::HTTP ::Middleware . for do |request |
117+ Protocol ::HTTP ::Response [ 101 , { 'sec-websocket-accept' => 'wrong-digest' } , [ ] ]
118+ end
119+ end
120+
121+ it 'raises an error' do
122+ expect do
123+ Async ::WebSocket ::Client . connect ( client_endpoint ) { }
124+ end . to raise_exception ( Async ::WebSocket ::ProtocolError , message : be =~ /Invalid accept digest/ )
125+ end
126+ end
127+
128+ with 'missing sec-websocket-accept header' do
129+ let ( :app ) do
130+ Protocol ::HTTP ::Middleware . for do |request |
131+ Protocol ::HTTP ::Response [ 101 , { } , [ ] ]
132+ end
133+ end
134+
135+ it 'raises an error' do
136+ expect do
137+ Async ::WebSocket ::Client . connect ( client_endpoint ) { }
138+ end . to raise_exception ( Async ::WebSocket ::ProtocolError , message : be =~ /Failed to negotiate connection/ )
139+ end
140+ end
113141 end
114142
115143 with 'http/2' do
You can’t perform that action at this time.
0 commit comments