websocket 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/websocket/error.rb +4 -0
- data/lib/websocket/frame/base.rb +1 -1
- data/lib/websocket/frame/handler/handler07.rb +15 -0
- data/lib/websocket/version.rb +1 -1
- data/spec/frame/incoming_07_spec.rb +16 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d5e949888cd78a33c1418916aa773e1408a9302
|
4
|
+
data.tar.gz: d74a71f238b56bf1711dd7b117cde1d3cf5bc037
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a7e71df6d11c0fc817d094845dd059a0d2ec00586f7373a714bde6d3ee9dbf15e27ecbb94c00aef039f2fc85da34933b21110d767429a8aa2bce35cb192cd9f
|
7
|
+
data.tar.gz: 48e22828b858a469f179bcf08ecc8acbc427f6f863e1cf38a3ca3e5b36a9a4c06a93a72b024e6dd5b7f1b11864cb6abefbef6334c7f789cfbe1451e766c0a0ed
|
data/CHANGELOG.md
CHANGED
data/lib/websocket/error.rb
CHANGED
@@ -47,6 +47,10 @@ module WebSocket
|
|
47
47
|
def message; :unknown_opcode; end
|
48
48
|
end
|
49
49
|
|
50
|
+
class UnknownCloseCode < ::WebSocket::Error::Frame
|
51
|
+
def message; :unknown_close_code; end
|
52
|
+
end
|
53
|
+
|
50
54
|
class UnknownVersion < ::WebSocket::Error::Frame
|
51
55
|
def message; :unknown_protocol_version; end
|
52
56
|
end
|
data/lib/websocket/frame/base.rb
CHANGED
@@ -21,6 +21,7 @@ module WebSocket
|
|
21
21
|
def encode_frame
|
22
22
|
if @frame.type == :close
|
23
23
|
code = @frame.code || 1000
|
24
|
+
raise WebSocket::Error::Frame::UnknownCloseCode unless valid_code?(code)
|
24
25
|
@frame.data = Data.new([code].pack('n') + @frame.data.to_s)
|
25
26
|
@frame.code = nil
|
26
27
|
end
|
@@ -32,12 +33,26 @@ module WebSocket
|
|
32
33
|
if has_close_code?(result)
|
33
34
|
code = result.data.slice!(0..1)
|
34
35
|
result.code = code.unpack('n').first
|
36
|
+
raise WebSocket::Error::Frame::UnknownCloseCode unless valid_code?(result.code)
|
37
|
+
raise WebSocket::Error::Frame::InvalidPayloadEncoding unless valid_encoding?(result.data)
|
35
38
|
end
|
36
39
|
result
|
37
40
|
end
|
38
41
|
|
39
42
|
private
|
40
43
|
|
44
|
+
def valid_code?(code)
|
45
|
+
[1000,1001,1002,1003,1007,1008,1009,1010,1011].include?(code) || (3000..4999).include?(code)
|
46
|
+
end
|
47
|
+
|
48
|
+
def valid_encoding?(data)
|
49
|
+
return true if data.nil? || !data.respond_to?(:encode)
|
50
|
+
data.encode('UTF-8')
|
51
|
+
true
|
52
|
+
rescue
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
41
56
|
def has_close_code?(frame)
|
42
57
|
frame && frame.type == :close && !frame.data.empty?
|
43
58
|
end
|
data/lib/websocket/version.rb
CHANGED
@@ -21,6 +21,22 @@ describe 'Incoming frame draft 07' do
|
|
21
21
|
it_should_behave_like 'valid_incoming_frame'
|
22
22
|
end
|
23
23
|
|
24
|
+
context "should raise error with invalid close code" do
|
25
|
+
let(:encoded_text) { "\x88\x07\x03\xEDHello" }
|
26
|
+
let(:decoded_text) { nil }
|
27
|
+
let(:error) { WebSocket::Error::Frame::UnknownCloseCode }
|
28
|
+
|
29
|
+
it_should_behave_like 'valid_incoming_frame'
|
30
|
+
end
|
31
|
+
|
32
|
+
context "should properly decode close frame with invalid UTF-8 message" do
|
33
|
+
let(:encoded_text) { "\x88\x03\x03\xE8\xE3" }
|
34
|
+
let(:decoded_text) { nil }
|
35
|
+
let(:error) { WebSocket::Error::Frame::InvalidPayloadEncoding }
|
36
|
+
|
37
|
+
it_should_behave_like 'valid_incoming_frame'
|
38
|
+
end
|
39
|
+
|
24
40
|
context "should properly decode ping frame" do
|
25
41
|
let(:encoded_text) { "\x89\x05" + decoded_text }
|
26
42
|
let(:frame_type) { :ping }
|