websocket 1.2.3 → 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +17 -0
- data/.github/workflows/publish.yml +17 -0
- data/.rubocop.yml +35 -3
- data/.travis.yml +14 -7
- data/CHANGELOG.md +24 -0
- data/Gemfile +12 -4
- data/README.md +3 -2
- data/Rakefile +8 -3
- data/lib/websocket.rb +4 -1
- data/lib/websocket/error.rb +8 -0
- data/lib/websocket/exception_handler.rb +3 -1
- data/lib/websocket/frame.rb +2 -0
- data/lib/websocket/frame/base.rb +5 -9
- data/lib/websocket/frame/data.rb +5 -2
- data/lib/websocket/frame/handler.rb +2 -0
- data/lib/websocket/frame/handler/base.rb +6 -4
- data/lib/websocket/frame/handler/handler03.rb +23 -16
- data/lib/websocket/frame/handler/handler04.rb +1 -0
- data/lib/websocket/frame/handler/handler05.rb +1 -0
- data/lib/websocket/frame/handler/handler07.rb +10 -9
- data/lib/websocket/frame/handler/handler75.rb +8 -7
- data/lib/websocket/frame/incoming.rb +2 -0
- data/lib/websocket/frame/incoming/client.rb +2 -0
- data/lib/websocket/frame/incoming/server.rb +2 -0
- data/lib/websocket/frame/outgoing.rb +3 -1
- data/lib/websocket/frame/outgoing/client.rb +2 -0
- data/lib/websocket/frame/outgoing/server.rb +2 -0
- data/lib/websocket/handshake.rb +2 -0
- data/lib/websocket/handshake/base.rb +26 -13
- data/lib/websocket/handshake/client.rb +17 -14
- data/lib/websocket/handshake/handler.rb +2 -0
- data/lib/websocket/handshake/handler/base.rb +2 -0
- data/lib/websocket/handshake/handler/client.rb +11 -0
- data/lib/websocket/handshake/handler/client01.rb +2 -0
- data/lib/websocket/handshake/handler/client04.rb +15 -4
- data/lib/websocket/handshake/handler/client11.rb +2 -0
- data/lib/websocket/handshake/handler/client75.rb +18 -2
- data/lib/websocket/handshake/handler/client76.rb +11 -5
- data/lib/websocket/handshake/handler/server.rb +2 -0
- data/lib/websocket/handshake/handler/server04.rb +12 -4
- data/lib/websocket/handshake/handler/server75.rb +21 -5
- data/lib/websocket/handshake/handler/server76.rb +14 -16
- data/lib/websocket/handshake/server.rb +7 -4
- data/lib/websocket/nice_inspect.rb +12 -0
- data/lib/websocket/version.rb +3 -1
- data/spec/frame/incoming_03_spec.rb +20 -17
- data/spec/frame/incoming_04_spec.rb +20 -17
- data/spec/frame/incoming_05_spec.rb +22 -19
- data/spec/frame/incoming_07_spec.rb +24 -21
- data/spec/frame/incoming_75_spec.rb +13 -10
- data/spec/frame/incoming_common_spec.rb +18 -8
- data/spec/frame/masking_spec.rb +3 -1
- data/spec/frame/outgoing_03_spec.rb +13 -10
- data/spec/frame/outgoing_04_spec.rb +13 -10
- data/spec/frame/outgoing_05_spec.rb +12 -9
- data/spec/frame/outgoing_07_spec.rb +13 -10
- data/spec/frame/outgoing_75_spec.rb +8 -5
- data/spec/frame/outgoing_common_spec.rb +11 -4
- data/spec/handshake/client_04_spec.rb +46 -3
- data/spec/handshake/client_11_spec.rb +5 -3
- data/spec/handshake/client_75_spec.rb +28 -1
- data/spec/handshake/client_76_spec.rb +30 -3
- data/spec/handshake/server_04_spec.rb +37 -4
- data/spec/handshake/server_75_spec.rb +25 -1
- data/spec/handshake/server_76_spec.rb +33 -9
- data/spec/spec_helper.rb +2 -2
- data/spec/support/all_client_drafts.rb +23 -21
- data/spec/support/all_server_drafts.rb +21 -16
- data/spec/support/frames_base.rb +2 -0
- data/spec/support/handshake_requests.rb +19 -17
- data/spec/support/incoming_frames.rb +46 -25
- data/spec/support/outgoing_frames.rb +30 -8
- data/spec/support/overwrites.rb +2 -0
- data/websocket.gemspec +4 -1
- metadata +7 -5
@@ -1,17 +1,20 @@
|
|
1
1
|
# encoding: binary
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
RSpec.describe 'Outgoing frame draft 04' do
|
5
|
-
|
7
|
+
subject { frame }
|
8
|
+
|
9
|
+
let(:version) { 4 }
|
6
10
|
let(:frame) { WebSocket::Frame::Outgoing.new(version: version, data: decoded_text, type: frame_type) }
|
7
11
|
let(:decoded_text) { '' }
|
8
12
|
let(:encoded_text) { "\x84\x00" }
|
9
13
|
let(:frame_type) { :text }
|
10
14
|
let(:require_sending) { true }
|
11
15
|
let(:error) { nil }
|
12
|
-
subject { frame }
|
13
16
|
|
14
|
-
|
17
|
+
it_behaves_like 'valid_outgoing_frame'
|
15
18
|
|
16
19
|
context 'should properly encode close frame' do
|
17
20
|
let(:frame_type) { :close }
|
@@ -19,7 +22,7 @@ RSpec.describe 'Outgoing frame draft 04' do
|
|
19
22
|
let(:encoded_text) { "\x81\x05" + decoded_text }
|
20
23
|
let(:require_sending) { true }
|
21
24
|
|
22
|
-
|
25
|
+
it_behaves_like 'valid_outgoing_frame'
|
23
26
|
end
|
24
27
|
|
25
28
|
context 'should properly encode ping frame' do
|
@@ -28,7 +31,7 @@ RSpec.describe 'Outgoing frame draft 04' do
|
|
28
31
|
let(:encoded_text) { "\x82\x05" + decoded_text }
|
29
32
|
let(:require_sending) { true }
|
30
33
|
|
31
|
-
|
34
|
+
it_behaves_like 'valid_outgoing_frame'
|
32
35
|
end
|
33
36
|
|
34
37
|
context 'should properly encode pong frame' do
|
@@ -37,7 +40,7 @@ RSpec.describe 'Outgoing frame draft 04' do
|
|
37
40
|
let(:encoded_text) { "\x83\x05" + decoded_text }
|
38
41
|
let(:require_sending) { true }
|
39
42
|
|
40
|
-
|
43
|
+
it_behaves_like 'valid_outgoing_frame'
|
41
44
|
end
|
42
45
|
|
43
46
|
context 'should properly encode text frame' do
|
@@ -45,7 +48,7 @@ RSpec.describe 'Outgoing frame draft 04' do
|
|
45
48
|
let(:encoded_text) { "\x84\x05" + decoded_text }
|
46
49
|
let(:require_sending) { true }
|
47
50
|
|
48
|
-
|
51
|
+
it_behaves_like 'valid_outgoing_frame'
|
49
52
|
end
|
50
53
|
|
51
54
|
context 'should properly encode 256 bytes binary frame' do
|
@@ -54,7 +57,7 @@ RSpec.describe 'Outgoing frame draft 04' do
|
|
54
57
|
let(:encoded_text) { "\x85\x7E\x01\x00" + decoded_text }
|
55
58
|
let(:require_sending) { true }
|
56
59
|
|
57
|
-
|
60
|
+
it_behaves_like 'valid_outgoing_frame'
|
58
61
|
end
|
59
62
|
|
60
63
|
context 'should properly encode 64KiB binary frame' do
|
@@ -63,7 +66,7 @@ RSpec.describe 'Outgoing frame draft 04' do
|
|
63
66
|
let(:encoded_text) { "\x85\x7F\x00\x00\x00\x00\x00\x01\x00\x00" + decoded_text }
|
64
67
|
let(:require_sending) { true }
|
65
68
|
|
66
|
-
|
69
|
+
it_behaves_like 'valid_outgoing_frame'
|
67
70
|
end
|
68
71
|
|
69
72
|
context 'should return error for unknown frame type' do
|
@@ -73,6 +76,6 @@ RSpec.describe 'Outgoing frame draft 04' do
|
|
73
76
|
let(:error) { :unknown_frame_type }
|
74
77
|
let(:require_sending) { false }
|
75
78
|
|
76
|
-
|
79
|
+
it_behaves_like 'valid_outgoing_frame'
|
77
80
|
end
|
78
81
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
# encoding: binary
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
RSpec.describe 'Outgoing frame draft 05' do
|
7
|
+
subject { frame }
|
8
|
+
|
5
9
|
let(:version) { 5 }
|
6
10
|
let(:frame) { WebSocket::Frame::Outgoing.new(version: version, data: decoded_text, type: frame_type) }
|
7
11
|
let(:decoded_text) { '' }
|
@@ -9,9 +13,8 @@ RSpec.describe 'Outgoing frame draft 05' do
|
|
9
13
|
let(:frame_type) { :text }
|
10
14
|
let(:require_sending) { true }
|
11
15
|
let(:error) { nil }
|
12
|
-
subject { frame }
|
13
16
|
|
14
|
-
|
17
|
+
it_behaves_like 'valid_outgoing_frame'
|
15
18
|
|
16
19
|
context 'should properly encode close frame' do
|
17
20
|
let(:frame_type) { :close }
|
@@ -19,7 +22,7 @@ RSpec.describe 'Outgoing frame draft 05' do
|
|
19
22
|
let(:encoded_text) { "\x81\x05" + decoded_text }
|
20
23
|
let(:require_sending) { true }
|
21
24
|
|
22
|
-
|
25
|
+
it_behaves_like 'valid_outgoing_frame'
|
23
26
|
end
|
24
27
|
|
25
28
|
context 'should properly encode ping frame' do
|
@@ -28,7 +31,7 @@ RSpec.describe 'Outgoing frame draft 05' do
|
|
28
31
|
let(:encoded_text) { "\x82\x05" + decoded_text }
|
29
32
|
let(:require_sending) { true }
|
30
33
|
|
31
|
-
|
34
|
+
it_behaves_like 'valid_outgoing_frame'
|
32
35
|
end
|
33
36
|
|
34
37
|
context 'should properly encode pong frame' do
|
@@ -37,7 +40,7 @@ RSpec.describe 'Outgoing frame draft 05' do
|
|
37
40
|
let(:encoded_text) { "\x83\x05" + decoded_text }
|
38
41
|
let(:require_sending) { true }
|
39
42
|
|
40
|
-
|
43
|
+
it_behaves_like 'valid_outgoing_frame'
|
41
44
|
end
|
42
45
|
|
43
46
|
context 'should properly encode text frame' do
|
@@ -45,7 +48,7 @@ RSpec.describe 'Outgoing frame draft 05' do
|
|
45
48
|
let(:encoded_text) { "\x84\x05" + decoded_text }
|
46
49
|
let(:require_sending) { true }
|
47
50
|
|
48
|
-
|
51
|
+
it_behaves_like 'valid_outgoing_frame'
|
49
52
|
end
|
50
53
|
|
51
54
|
context 'should properly encode 256 bytes binary frame' do
|
@@ -54,7 +57,7 @@ RSpec.describe 'Outgoing frame draft 05' do
|
|
54
57
|
let(:encoded_text) { "\x85\x7E\x01\x00" + decoded_text }
|
55
58
|
let(:require_sending) { true }
|
56
59
|
|
57
|
-
|
60
|
+
it_behaves_like 'valid_outgoing_frame'
|
58
61
|
end
|
59
62
|
|
60
63
|
context 'should properly encode 64KiB binary frame' do
|
@@ -63,7 +66,7 @@ RSpec.describe 'Outgoing frame draft 05' do
|
|
63
66
|
let(:encoded_text) { "\x85\x7F\x00\x00\x00\x00\x00\x01\x00\x00" + decoded_text }
|
64
67
|
let(:require_sending) { true }
|
65
68
|
|
66
|
-
|
69
|
+
it_behaves_like 'valid_outgoing_frame'
|
67
70
|
end
|
68
71
|
|
69
72
|
context 'should return error for unknown frame type' do
|
@@ -73,6 +76,6 @@ RSpec.describe 'Outgoing frame draft 05' do
|
|
73
76
|
let(:error) { :unknown_frame_type }
|
74
77
|
let(:require_sending) { false }
|
75
78
|
|
76
|
-
|
79
|
+
it_behaves_like 'valid_outgoing_frame'
|
77
80
|
end
|
78
81
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
# encoding: binary
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
RSpec.describe 'Outgoing frame draft 07' do
|
7
|
+
subject { frame }
|
8
|
+
|
5
9
|
let(:version) { 7 }
|
6
10
|
let(:frame) { WebSocket::Frame::Outgoing.new(version: version, data: decoded_text, type: frame_type, code: close_code) }
|
7
11
|
let(:decoded_text) { '' }
|
@@ -10,9 +14,8 @@ RSpec.describe 'Outgoing frame draft 07' do
|
|
10
14
|
let(:frame_type) { :text }
|
11
15
|
let(:require_sending) { true }
|
12
16
|
let(:error) { nil }
|
13
|
-
subject { frame }
|
14
17
|
|
15
|
-
|
18
|
+
it_behaves_like 'valid_outgoing_frame'
|
16
19
|
|
17
20
|
context 'should properly encode close frame without close code' do
|
18
21
|
let(:frame_type) { :close }
|
@@ -20,7 +23,7 @@ RSpec.describe 'Outgoing frame draft 07' do
|
|
20
23
|
let(:encoded_text) { "\x88\x07\x03\xE8" + decoded_text }
|
21
24
|
let(:require_sending) { true }
|
22
25
|
|
23
|
-
|
26
|
+
it_behaves_like 'valid_outgoing_frame'
|
24
27
|
end
|
25
28
|
|
26
29
|
context 'should properly encode close frame with close code' do
|
@@ -30,7 +33,7 @@ RSpec.describe 'Outgoing frame draft 07' do
|
|
30
33
|
let(:encoded_text) { "\x88\x07\x03\xE9" + decoded_text }
|
31
34
|
let(:require_sending) { true }
|
32
35
|
|
33
|
-
|
36
|
+
it_behaves_like 'valid_outgoing_frame'
|
34
37
|
end
|
35
38
|
|
36
39
|
context 'should properly encode ping frame' do
|
@@ -39,7 +42,7 @@ RSpec.describe 'Outgoing frame draft 07' do
|
|
39
42
|
let(:encoded_text) { "\x89\x05" + decoded_text }
|
40
43
|
let(:require_sending) { true }
|
41
44
|
|
42
|
-
|
45
|
+
it_behaves_like 'valid_outgoing_frame'
|
43
46
|
end
|
44
47
|
|
45
48
|
context 'should properly encode pong frame' do
|
@@ -48,7 +51,7 @@ RSpec.describe 'Outgoing frame draft 07' do
|
|
48
51
|
let(:encoded_text) { "\x8a\x05" + decoded_text }
|
49
52
|
let(:require_sending) { true }
|
50
53
|
|
51
|
-
|
54
|
+
it_behaves_like 'valid_outgoing_frame'
|
52
55
|
end
|
53
56
|
|
54
57
|
context 'should properly encode text frame' do
|
@@ -56,7 +59,7 @@ RSpec.describe 'Outgoing frame draft 07' do
|
|
56
59
|
let(:encoded_text) { "\x81\x05" + decoded_text }
|
57
60
|
let(:require_sending) { true }
|
58
61
|
|
59
|
-
|
62
|
+
it_behaves_like 'valid_outgoing_frame'
|
60
63
|
end
|
61
64
|
|
62
65
|
context 'should properly encode 256 bytes binary frame' do
|
@@ -65,7 +68,7 @@ RSpec.describe 'Outgoing frame draft 07' do
|
|
65
68
|
let(:encoded_text) { "\x82\x7E\x01\x00" + decoded_text }
|
66
69
|
let(:require_sending) { true }
|
67
70
|
|
68
|
-
|
71
|
+
it_behaves_like 'valid_outgoing_frame'
|
69
72
|
end
|
70
73
|
|
71
74
|
context 'should properly encode 64KiB binary frame' do
|
@@ -74,7 +77,7 @@ RSpec.describe 'Outgoing frame draft 07' do
|
|
74
77
|
let(:encoded_text) { "\x82\x7F\x00\x00\x00\x00\x00\x01\x00\x00" + decoded_text }
|
75
78
|
let(:require_sending) { true }
|
76
79
|
|
77
|
-
|
80
|
+
it_behaves_like 'valid_outgoing_frame'
|
78
81
|
end
|
79
82
|
|
80
83
|
context 'should return error for unknown frame type' do
|
@@ -84,6 +87,6 @@ RSpec.describe 'Outgoing frame draft 07' do
|
|
84
87
|
let(:error) { :unknown_frame_type }
|
85
88
|
let(:require_sending) { false }
|
86
89
|
|
87
|
-
|
90
|
+
it_behaves_like 'valid_outgoing_frame'
|
88
91
|
end
|
89
92
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
# encoding: binary
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
RSpec.describe 'Outgoing frame draft 75' do
|
7
|
+
subject { frame }
|
8
|
+
|
5
9
|
let(:version) { 75 }
|
6
10
|
let(:frame) { WebSocket::Frame::Outgoing.new(version: version, data: decoded_text, type: frame_type) }
|
7
11
|
let(:decoded_text) { '' }
|
@@ -9,16 +13,15 @@ RSpec.describe 'Outgoing frame draft 75' do
|
|
9
13
|
let(:frame_type) { :text }
|
10
14
|
let(:require_sending) { true }
|
11
15
|
let(:error) { nil }
|
12
|
-
subject { frame }
|
13
16
|
|
14
|
-
|
17
|
+
it_behaves_like 'valid_outgoing_frame'
|
15
18
|
|
16
19
|
context 'should properly encode text frame' do
|
17
20
|
let(:decoded_text) { 'abc' }
|
18
21
|
let(:encoded_text) { "\x00abc\xFF" }
|
19
22
|
let(:require_sending) { true }
|
20
23
|
|
21
|
-
|
24
|
+
it_behaves_like 'valid_outgoing_frame'
|
22
25
|
end
|
23
26
|
|
24
27
|
context 'should properly encode close frame' do
|
@@ -27,7 +30,7 @@ RSpec.describe 'Outgoing frame draft 75' do
|
|
27
30
|
let(:encoded_text) { "\xFF\x00" }
|
28
31
|
let(:require_sending) { true }
|
29
32
|
|
30
|
-
|
33
|
+
it_behaves_like 'valid_outgoing_frame'
|
31
34
|
end
|
32
35
|
|
33
36
|
context 'should return error for unknown frame type' do
|
@@ -37,6 +40,6 @@ RSpec.describe 'Outgoing frame draft 75' do
|
|
37
40
|
let(:error) { :unknown_frame_type }
|
38
41
|
let(:require_sending) { false }
|
39
42
|
|
40
|
-
|
43
|
+
it_behaves_like 'valid_outgoing_frame'
|
41
44
|
end
|
42
45
|
end
|
@@ -1,15 +1,22 @@
|
|
1
1
|
# encoding: binary
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
RSpec.describe 'Outgoing common frame' do
|
5
7
|
subject { WebSocket::Frame::Outgoing.new }
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
it 'is version 13' do
|
10
|
+
expect(subject.version).to be 13
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has no errors' do
|
14
|
+
expect(subject.error?).to be false
|
15
|
+
end
|
9
16
|
|
10
|
-
it '
|
17
|
+
it 'raises error on invalid version' do
|
11
18
|
subject = WebSocket::Frame::Incoming.new(version: 70)
|
12
19
|
expect(subject.error?).to be true
|
13
|
-
expect(subject.error).to
|
20
|
+
expect(subject.error).to be :unknown_protocol_version
|
14
21
|
end
|
15
22
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe 'Client draft 4 handshake' do
|
@@ -7,14 +9,55 @@ RSpec.describe 'Client draft 4 handshake' do
|
|
7
9
|
let(:client_request) { client_handshake_04({ key: handshake.handler.send(:key), version: version }.merge(@request_params || {})) }
|
8
10
|
let(:server_response) { server_handshake_04({ accept: handshake.handler.send(:accept) }.merge(@request_params || {})) }
|
9
11
|
|
10
|
-
|
12
|
+
it_behaves_like 'all client drafts'
|
11
13
|
|
12
|
-
it '
|
14
|
+
it 'disallows client with invalid challenge' do
|
13
15
|
@request_params = { accept: 'invalid' }
|
14
16
|
handshake << server_response
|
15
17
|
|
16
18
|
expect(handshake).to be_finished
|
17
19
|
expect(handshake).not_to be_valid
|
18
|
-
expect(handshake.error).to
|
20
|
+
expect(handshake.error).to be(:invalid_handshake_authentication)
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'protocol header specified' do
|
24
|
+
let(:handshake) { WebSocket::Handshake::Client.new(uri: 'ws://example.com/demo', origin: 'http://example.com', version: version, protocols: protocols) }
|
25
|
+
|
26
|
+
context 'single protocol requested' do
|
27
|
+
let(:protocols) { %w[binary] }
|
28
|
+
|
29
|
+
it 'returns a valid handshake' do
|
30
|
+
@request_params = { headers: { 'Sec-WebSocket-Protocol' => 'binary' } }
|
31
|
+
handshake << server_response
|
32
|
+
|
33
|
+
expect(handshake).to be_finished
|
34
|
+
expect(handshake).to be_valid
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'multiple protocols requested' do
|
39
|
+
let(:protocols) { %w[binary xmpp] }
|
40
|
+
|
41
|
+
it 'returns with a valid handshake' do
|
42
|
+
@request_params = { headers: { 'Sec-WebSocket-Protocol' => 'xmpp' } }
|
43
|
+
handshake << server_response
|
44
|
+
|
45
|
+
expect(handshake).to be_finished
|
46
|
+
expect(handshake).to be_valid
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'unsupported protocol requested' do
|
51
|
+
let(:protocols) { %w[binary xmpp] }
|
52
|
+
|
53
|
+
it 'fails with an unsupported protocol error' do
|
54
|
+
@request_params = { headers: { 'Sec-WebSocket-Protocol' => 'generic' } }
|
55
|
+
handshake << server_response
|
56
|
+
|
57
|
+
expect(handshake).to be_finished
|
58
|
+
expect(handshake).not_to be_valid
|
59
|
+
expect(handshake.error).to be(:unsupported_protocol)
|
60
|
+
end
|
61
|
+
end
|
19
62
|
end
|
20
63
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe 'Client draft 11 handshake' do
|
@@ -7,14 +9,14 @@ RSpec.describe 'Client draft 11 handshake' do
|
|
7
9
|
let(:client_request) { client_handshake_11({ key: handshake.handler.send(:key), version: version }.merge(@request_params || {})) }
|
8
10
|
let(:server_response) { server_handshake_11({ accept: handshake.handler.send(:accept) }.merge(@request_params || {})) }
|
9
11
|
|
10
|
-
|
12
|
+
it_behaves_like 'all client drafts'
|
11
13
|
|
12
|
-
it '
|
14
|
+
it 'disallows client with invalid challenge' do
|
13
15
|
@request_params = { accept: 'invalid' }
|
14
16
|
handshake << server_response
|
15
17
|
|
16
18
|
expect(handshake).to be_finished
|
17
19
|
expect(handshake).not_to be_valid
|
18
|
-
expect(handshake.error).to
|
20
|
+
expect(handshake.error).to be(:invalid_handshake_authentication)
|
19
21
|
end
|
20
22
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe 'Client draft 75 handshake' do
|
@@ -7,5 +9,30 @@ RSpec.describe 'Client draft 75 handshake' do
|
|
7
9
|
let(:client_request) { client_handshake_75(@request_params || {}) }
|
8
10
|
let(:server_response) { server_handshake_75(@request_params || {}) }
|
9
11
|
|
10
|
-
|
12
|
+
it_behaves_like 'all client drafts'
|
13
|
+
|
14
|
+
context 'protocol header specified' do
|
15
|
+
let(:handshake) { WebSocket::Handshake::Client.new(uri: 'ws://example.com/demo', origin: 'http://example.com', version: version, protocols: %w[binary]) }
|
16
|
+
|
17
|
+
context 'supported' do
|
18
|
+
it 'returns a valid handshake' do
|
19
|
+
@request_params = { headers: { 'WebSocket-Protocol' => 'binary' } }
|
20
|
+
handshake << server_response
|
21
|
+
|
22
|
+
expect(handshake).to be_finished
|
23
|
+
expect(handshake).to be_valid
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'unsupported' do
|
28
|
+
it 'fails with an unsupported protocol error' do
|
29
|
+
@request_params = { headers: { 'WebSocket-Protocol' => 'xmpp' } }
|
30
|
+
handshake << server_response
|
31
|
+
|
32
|
+
expect(handshake).to be_finished
|
33
|
+
expect(handshake).not_to be_valid
|
34
|
+
expect(handshake.error).to be(:unsupported_protocol)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
11
38
|
end
|