websocket 1.1.4 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +2 -6
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -1
- data/README.md +10 -6
- data/Rakefile +1 -1
- data/lib/websocket.rb +1 -1
- data/lib/websocket/exception_handler.rb +6 -0
- data/lib/websocket/frame/base.rb +1 -1
- data/lib/websocket/frame/data.rb +11 -9
- data/lib/websocket/frame/handler.rb +1 -1
- data/lib/websocket/frame/handler/handler03.rb +17 -17
- data/lib/websocket/frame/handler/handler07.rb +8 -8
- data/lib/websocket/frame/handler/handler75.rb +8 -7
- data/lib/websocket/frame/incoming.rb +1 -1
- data/lib/websocket/frame/outgoing.rb +1 -1
- data/lib/websocket/handshake/base.rb +7 -7
- data/lib/websocket/handshake/client.rb +5 -3
- data/lib/websocket/handshake/handler/base.rb +5 -5
- data/lib/websocket/handshake/handler/client.rb +6 -1
- data/lib/websocket/handshake/handler/client04.rb +7 -6
- data/lib/websocket/handshake/handler/client75.rb +5 -4
- data/lib/websocket/handshake/handler/client76.rb +5 -5
- data/lib/websocket/handshake/handler/server04.rb +11 -6
- data/lib/websocket/handshake/handler/server75.rb +5 -5
- data/lib/websocket/handshake/handler/server76.rb +9 -9
- data/lib/websocket/handshake/server.rb +25 -24
- data/lib/websocket/version.rb +1 -1
- data/spec/frame/incoming_03_spec.rb +25 -25
- data/spec/frame/incoming_04_spec.rb +25 -25
- data/spec/frame/incoming_05_spec.rb +29 -29
- data/spec/frame/incoming_07_spec.rb +31 -31
- data/spec/frame/incoming_75_spec.rb +13 -13
- data/spec/frame/incoming_common_spec.rb +12 -13
- data/spec/frame/masking_spec.rb +10 -10
- data/spec/frame/outgoing_03_spec.rb +17 -17
- data/spec/frame/outgoing_04_spec.rb +17 -17
- data/spec/frame/outgoing_05_spec.rb +17 -17
- data/spec/frame/outgoing_07_spec.rb +19 -19
- data/spec/frame/outgoing_75_spec.rb +9 -9
- data/spec/frame/outgoing_common_spec.rb +7 -8
- data/spec/handshake/client_04_spec.rb +9 -9
- data/spec/handshake/client_75_spec.rb +2 -2
- data/spec/handshake/client_76_spec.rb +9 -9
- data/spec/handshake/server_04_spec.rb +5 -5
- data/spec/handshake/server_75_spec.rb +1 -1
- data/spec/handshake/server_76_spec.rb +21 -21
- data/spec/spec_helper.rb +4 -1
- data/spec/support/all_client_drafts.rb +62 -52
- data/spec/support/all_server_drafts.rb +49 -49
- data/spec/support/handshake_requests.rb +16 -16
- data/spec/support/incoming_frames.rb +28 -28
- data/spec/support/outgoing_frames.rb +10 -10
- data/websocket.gemspec +1 -1
- metadata +42 -22
- checksums.yaml +0 -7
@@ -1,10 +1,10 @@
|
|
1
1
|
# encoding: binary
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'Outgoing frame draft 75' do
|
4
|
+
RSpec.describe 'Outgoing frame draft 75' do
|
5
5
|
let(:version) { 75 }
|
6
|
-
let(:frame) { WebSocket::Frame::Outgoing.new(:
|
7
|
-
let(:decoded_text) {
|
6
|
+
let(:frame) { WebSocket::Frame::Outgoing.new(version: version, data: decoded_text, type: frame_type) }
|
7
|
+
let(:decoded_text) { '' }
|
8
8
|
let(:encoded_text) { "\x00\xFF" }
|
9
9
|
let(:frame_type) { :text }
|
10
10
|
let(:require_sending) { true }
|
@@ -13,26 +13,26 @@ describe 'Outgoing frame draft 75' do
|
|
13
13
|
|
14
14
|
it_should_behave_like 'valid_outgoing_frame'
|
15
15
|
|
16
|
-
context
|
17
|
-
let(:decoded_text) {
|
16
|
+
context 'should properly encode text frame' do
|
17
|
+
let(:decoded_text) { 'abc' }
|
18
18
|
let(:encoded_text) { "\x00abc\xFF" }
|
19
19
|
let(:require_sending) { true }
|
20
20
|
|
21
21
|
it_should_behave_like 'valid_outgoing_frame'
|
22
22
|
end
|
23
23
|
|
24
|
-
context
|
24
|
+
context 'should properly encode close frame' do
|
25
25
|
let(:frame_type) { :close }
|
26
|
-
let(:decoded_text) {
|
26
|
+
let(:decoded_text) { 'abc' }
|
27
27
|
let(:encoded_text) { "\xFF\x00" }
|
28
28
|
let(:require_sending) { true }
|
29
29
|
|
30
30
|
it_should_behave_like 'valid_outgoing_frame'
|
31
31
|
end
|
32
32
|
|
33
|
-
context
|
33
|
+
context 'should return error for unknown frame type' do
|
34
34
|
let(:frame_type) { :unknown }
|
35
|
-
let(:decoded_text) {
|
35
|
+
let(:decoded_text) { 'Hello' }
|
36
36
|
let(:encoded_text) { nil }
|
37
37
|
let(:error) { :unknown_frame_type }
|
38
38
|
let(:require_sending) { false }
|
@@ -1,16 +1,15 @@
|
|
1
1
|
# encoding: binary
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'Outgoing common frame' do
|
4
|
+
RSpec.describe 'Outgoing common frame' do
|
5
5
|
subject { WebSocket::Frame::Outgoing.new }
|
6
6
|
|
7
|
-
its(:version) {
|
8
|
-
|
9
|
-
# its(:error?) { should be_false }
|
7
|
+
its(:version) { is_expected.to eql(13) }
|
8
|
+
its(:error?) { is_expected.to be false }
|
10
9
|
|
11
|
-
it
|
12
|
-
subject = WebSocket::Frame::Incoming.new(:
|
13
|
-
subject.error
|
14
|
-
subject.error.
|
10
|
+
it 'should raise error on invalid version' do
|
11
|
+
subject = WebSocket::Frame::Incoming.new(version: 70)
|
12
|
+
expect(subject.error?).to be true
|
13
|
+
expect(subject.error).to eql(:unknown_protocol_version)
|
15
14
|
end
|
16
15
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'Client draft 4 handshake' do
|
4
|
-
let(:handshake) { WebSocket::Handshake::Client.new({ :
|
3
|
+
RSpec.describe 'Client draft 4 handshake' do
|
4
|
+
let(:handshake) { WebSocket::Handshake::Client.new({ uri: 'ws://example.com/demo', origin: 'http://example.com', version: version }.merge(@request_params || {})) }
|
5
5
|
|
6
6
|
let(:version) { 4 }
|
7
|
-
let(:client_request) { client_handshake_04({ :
|
8
|
-
let(:server_response) { server_handshake_04({ :
|
7
|
+
let(:client_request) { client_handshake_04({ key: handshake.handler.send(:key), version: version }.merge(@request_params || {})) }
|
8
|
+
let(:server_response) { server_handshake_04({ accept: handshake.handler.send(:accept) }.merge(@request_params || {})) }
|
9
9
|
|
10
10
|
it_should_behave_like 'all client drafts'
|
11
11
|
|
12
|
-
it
|
13
|
-
@request_params = { :
|
12
|
+
it 'should disallow client with invalid challenge' do
|
13
|
+
@request_params = { accept: 'invalid' }
|
14
14
|
handshake << server_response
|
15
15
|
|
16
|
-
handshake.
|
17
|
-
handshake.
|
18
|
-
handshake.error.
|
16
|
+
expect(handshake).to be_finished
|
17
|
+
expect(handshake).not_to be_valid
|
18
|
+
expect(handshake.error).to eql(:invalid_handshake_authentication)
|
19
19
|
end
|
20
20
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'Client draft 75 handshake' do
|
4
|
-
let(:handshake) { WebSocket::Handshake::Client.new({ :
|
3
|
+
RSpec.describe 'Client draft 75 handshake' do
|
4
|
+
let(:handshake) { WebSocket::Handshake::Client.new({ uri: 'ws://example.com/demo', origin: 'http://example.com', version: version }.merge(@request_params || {})) }
|
5
5
|
|
6
6
|
let(:version) { 75 }
|
7
7
|
let(:client_request) { client_handshake_75(@request_params || {}) }
|
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'Client draft 76 handshake' do
|
4
|
-
let(:handshake) { WebSocket::Handshake::Client.new({ :
|
3
|
+
RSpec.describe 'Client draft 76 handshake' do
|
4
|
+
let(:handshake) { WebSocket::Handshake::Client.new({ uri: 'ws://example.com/demo', origin: 'http://example.com', version: version }.merge(@request_params || {})) }
|
5
5
|
|
6
6
|
let(:version) { 76 }
|
7
|
-
let(:client_request) { client_handshake_76({ :
|
8
|
-
let(:server_response) { server_handshake_76({ :
|
7
|
+
let(:client_request) { client_handshake_76({ key1: handshake.handler.send(:key1), key2: handshake.handler.send(:key2), key3: handshake.handler.send(:key3) }.merge(@request_params || {})) }
|
8
|
+
let(:server_response) { server_handshake_76({ challenge: handshake.handler.send(:challenge) }.merge(@request_params || {})) }
|
9
9
|
|
10
10
|
it_should_behave_like 'all client drafts'
|
11
11
|
|
12
|
-
it
|
13
|
-
@request_params = { :
|
12
|
+
it 'should disallow client with invalid challenge' do
|
13
|
+
@request_params = { challenge: 'invalid' }
|
14
14
|
handshake << server_response
|
15
15
|
|
16
|
-
handshake.
|
17
|
-
handshake.
|
18
|
-
handshake.error.
|
16
|
+
expect(handshake).to be_finished
|
17
|
+
expect(handshake).not_to be_valid
|
18
|
+
expect(handshake.error).to eql(:invalid_handshake_authentication)
|
19
19
|
end
|
20
20
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'Server draft 04 handshake' do
|
3
|
+
RSpec.describe 'Server draft 04 handshake' do
|
4
4
|
let(:handshake) { WebSocket::Handshake::Server.new }
|
5
5
|
let(:version) { 04 }
|
6
6
|
let(:client_request) { client_handshake_04(@request_params || {}) }
|
@@ -8,11 +8,11 @@ describe 'Server draft 04 handshake' do
|
|
8
8
|
|
9
9
|
it_should_behave_like 'all server drafts'
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'should disallow request without Sec-WebSocket-Key' do
|
12
12
|
handshake << client_request.gsub(/^Sec-WebSocket-Key:.*\n/, '')
|
13
13
|
|
14
|
-
handshake.
|
15
|
-
handshake.
|
16
|
-
handshake.error.
|
14
|
+
expect(handshake).to be_finished
|
15
|
+
expect(handshake).not_to be_valid
|
16
|
+
expect(handshake.error).to eql(:invalid_handshake_authentication)
|
17
17
|
end
|
18
18
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'Server draft 76 handshake' do
|
3
|
+
RSpec.describe 'Server draft 76 handshake' do
|
4
4
|
let(:handshake) { WebSocket::Handshake::Server.new }
|
5
5
|
let(:version) { 76 }
|
6
6
|
let(:client_request) { client_handshake_76(@request_params || {}) }
|
@@ -8,39 +8,39 @@ describe 'Server draft 76 handshake' do
|
|
8
8
|
|
9
9
|
it_should_behave_like 'all server drafts'
|
10
10
|
|
11
|
-
it
|
12
|
-
@request_params = { :
|
11
|
+
it 'should disallow request without spaces in key 1' do
|
12
|
+
@request_params = { key1: '4@146546xW%0l15' }
|
13
13
|
handshake << client_request
|
14
14
|
|
15
|
-
handshake.
|
16
|
-
handshake.
|
17
|
-
handshake.error.
|
15
|
+
expect(handshake).to be_finished
|
16
|
+
expect(handshake).not_to be_valid
|
17
|
+
expect(handshake.error).to eql(:invalid_handshake_authentication)
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
@request_params = { :
|
20
|
+
it 'should disallow request without spaces in key 2' do
|
21
|
+
@request_params = { key2: '129985Y31.P00' }
|
22
22
|
handshake << client_request
|
23
23
|
|
24
|
-
handshake.
|
25
|
-
handshake.
|
26
|
-
handshake.error.
|
24
|
+
expect(handshake).to be_finished
|
25
|
+
expect(handshake).not_to be_valid
|
26
|
+
expect(handshake.error).to eql(:invalid_handshake_authentication)
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
@request_params = { :
|
29
|
+
it 'should disallow request with invalid number of spaces or numbers in key 1' do
|
30
|
+
@request_params = { key1: '4 @1 46546xW%0l 1 5' }
|
31
31
|
handshake << client_request
|
32
32
|
|
33
|
-
handshake.
|
34
|
-
handshake.
|
35
|
-
handshake.error.
|
33
|
+
expect(handshake).to be_finished
|
34
|
+
expect(handshake).not_to be_valid
|
35
|
+
expect(handshake.error).to eql(:invalid_handshake_authentication)
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
39
|
-
@request_params = { :
|
38
|
+
it 'should disallow request with invalid number of spaces or numbers in key 2' do
|
39
|
+
@request_params = { key2: '12998 5 Y3 1 .P00' }
|
40
40
|
handshake << client_request
|
41
41
|
|
42
|
-
handshake.
|
43
|
-
handshake.
|
44
|
-
handshake.error.
|
42
|
+
expect(handshake).to be_finished
|
43
|
+
expect(handshake).not_to be_valid
|
44
|
+
expect(handshake.error).to eql(:invalid_handshake_authentication)
|
45
45
|
end
|
46
46
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'rspec'
|
2
|
+
require 'rspec/its'
|
2
3
|
require 'webrick'
|
3
4
|
|
4
5
|
require 'websocket'
|
5
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
6
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
6
7
|
|
7
8
|
RSpec.configure do |config|
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
8
11
|
config.before(:suite) do
|
9
12
|
WebSocket.max_frame_size = 100 * 1024 # 100kb
|
10
13
|
end
|
@@ -1,98 +1,108 @@
|
|
1
|
-
shared_examples_for 'all client drafts' do
|
1
|
+
RSpec.shared_examples_for 'all client drafts' do
|
2
2
|
def validate_request
|
3
|
-
handshake.to_s.
|
3
|
+
expect(handshake.to_s).to eql(client_request)
|
4
4
|
|
5
5
|
handshake << server_response
|
6
6
|
|
7
|
-
handshake.error.
|
8
|
-
handshake.
|
9
|
-
handshake.
|
7
|
+
expect(handshake.error).to be_nil
|
8
|
+
expect(handshake).to be_finished
|
9
|
+
expect(handshake).to be_valid
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'should be valid' do
|
13
13
|
handshake << server_response
|
14
14
|
|
15
|
-
handshake.error.
|
16
|
-
handshake.
|
17
|
-
handshake.
|
15
|
+
expect(handshake.error).to be_nil
|
16
|
+
expect(handshake).to be_finished
|
17
|
+
expect(handshake).to be_valid
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
handshake.version.
|
20
|
+
it 'should return valid version' do
|
21
|
+
expect(handshake.version).to eql(version)
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
@request_params = { :
|
26
|
-
handshake.host.
|
24
|
+
it 'should return valid host' do
|
25
|
+
@request_params = { host: 'www.test.cc' }
|
26
|
+
expect(handshake.host).to eql('www.test.cc')
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
@request_params = { :
|
31
|
-
handshake.path.
|
29
|
+
it 'should return valid path' do
|
30
|
+
@request_params = { path: '/custom' }
|
31
|
+
expect(handshake.path).to eql('/custom')
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
@request_params = { :
|
36
|
-
handshake.query.
|
34
|
+
it 'should return valid query' do
|
35
|
+
@request_params = { query: 'aaa=bbb' }
|
36
|
+
expect(handshake.query).to eql('aaa=bbb')
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
40
|
-
@request_params = { :
|
41
|
-
handshake.port.
|
39
|
+
it 'should return valid port' do
|
40
|
+
@request_params = { port: 123 }
|
41
|
+
expect(handshake.port).to eql(123)
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
45
|
-
@request_params = { :
|
46
|
-
handshake.
|
47
|
-
handshake.port.should eql(301)
|
48
|
-
handshake.path.should eql('/test_path')
|
49
|
-
handshake.query.should eql('query=true')
|
44
|
+
it 'should return valid headers' do
|
45
|
+
@request_params = { headers: { 'aaa' => 'bbb' } }
|
46
|
+
expect(handshake.headers).to eql({ 'aaa' => 'bbb' })
|
50
47
|
end
|
51
48
|
|
52
|
-
it
|
53
|
-
@request_params = { :
|
54
|
-
handshake.host.
|
55
|
-
handshake.port.
|
56
|
-
handshake.path.
|
57
|
-
handshake.query.
|
49
|
+
it 'should parse uri' do
|
50
|
+
@request_params = { uri: 'ws://test.example.org:301/test_path?query=true' }
|
51
|
+
expect(handshake.host).to eql('test.example.org')
|
52
|
+
expect(handshake.port).to eql(301)
|
53
|
+
expect(handshake.path).to eql('/test_path')
|
54
|
+
expect(handshake.query).to eql('query=true')
|
58
55
|
end
|
59
56
|
|
60
|
-
it
|
61
|
-
@request_params = { :
|
62
|
-
handshake.
|
57
|
+
it 'should parse url' do
|
58
|
+
@request_params = { url: 'ws://test.example.org:301/test_path?query=true' }
|
59
|
+
expect(handshake.host).to eql('test.example.org')
|
60
|
+
expect(handshake.port).to eql(301)
|
61
|
+
expect(handshake.path).to eql('/test_path')
|
62
|
+
expect(handshake.query).to eql('query=true')
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
65
|
+
it 'should resolve correct path with root server provided' do
|
66
|
+
@request_params = { url: 'ws://test.example.org' }
|
67
|
+
expect(handshake.path).to eql('/')
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should return valid response' do
|
71
|
+
validate_request
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should allow custom path' do
|
75
|
+
@request_params = { path: '/custom' }
|
66
76
|
validate_request
|
67
77
|
end
|
68
78
|
|
69
|
-
it
|
70
|
-
@request_params = { :
|
79
|
+
it 'should allow query in path' do
|
80
|
+
@request_params = { query: 'test=true' }
|
71
81
|
validate_request
|
72
82
|
end
|
73
83
|
|
74
|
-
it
|
75
|
-
@request_params = { :
|
84
|
+
it 'should allow custom port' do
|
85
|
+
@request_params = { port: 123 }
|
76
86
|
validate_request
|
77
87
|
end
|
78
88
|
|
79
|
-
it
|
80
|
-
@request_params = { :
|
89
|
+
it 'should allow custom headers' do
|
90
|
+
@request_params = { headers: { 'aaa' => 'bbb' } }
|
81
91
|
validate_request
|
82
92
|
end
|
83
93
|
|
84
|
-
it
|
94
|
+
it 'should recognize unfinished requests' do
|
85
95
|
handshake << server_response[0..-20]
|
86
96
|
|
87
|
-
handshake.
|
88
|
-
handshake.
|
97
|
+
expect(handshake).not_to be_finished
|
98
|
+
expect(handshake).not_to be_valid
|
89
99
|
end
|
90
100
|
|
91
|
-
it
|
101
|
+
it 'should disallow requests with invalid request method' do
|
92
102
|
handshake << server_response.gsub('101', '404')
|
93
103
|
|
94
|
-
handshake.
|
95
|
-
handshake.
|
96
|
-
handshake.error.
|
104
|
+
expect(handshake).to be_finished
|
105
|
+
expect(handshake).not_to be_valid
|
106
|
+
expect(handshake.error).to eql(:invalid_status_code)
|
97
107
|
end
|
98
108
|
end
|
@@ -1,117 +1,117 @@
|
|
1
|
-
shared_examples_for 'all server drafts' do
|
1
|
+
RSpec.shared_examples_for 'all server drafts' do
|
2
2
|
def validate_request
|
3
3
|
handshake << client_request
|
4
4
|
|
5
|
-
handshake.error.
|
6
|
-
handshake.
|
7
|
-
handshake.
|
8
|
-
handshake.to_s.
|
5
|
+
expect(handshake.error).to be_nil
|
6
|
+
expect(handshake).to be_finished
|
7
|
+
expect(handshake).to be_valid
|
8
|
+
expect(handshake.to_s).to eql(server_response)
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'should be valid' do
|
12
12
|
handshake << client_request
|
13
13
|
|
14
|
-
handshake.error.
|
15
|
-
handshake.
|
16
|
-
handshake.
|
14
|
+
expect(handshake.error).to be_nil
|
15
|
+
expect(handshake).to be_finished
|
16
|
+
expect(handshake).to be_valid
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'should return valid version' do
|
20
20
|
handshake << client_request
|
21
21
|
|
22
|
-
handshake.version.
|
22
|
+
expect(handshake.version).to eql(version)
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
@request_params = { :
|
25
|
+
it 'should return valid host' do
|
26
|
+
@request_params = { host: 'www.test.cc' }
|
27
27
|
handshake << client_request
|
28
28
|
|
29
|
-
handshake.host.
|
29
|
+
expect(handshake.host).to eql('www.test.cc')
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
33
|
-
@request_params = { :
|
32
|
+
it 'should return valid path' do
|
33
|
+
@request_params = { path: '/custom' }
|
34
34
|
handshake << client_request
|
35
35
|
|
36
|
-
handshake.path.
|
36
|
+
expect(handshake.path).to eql('/custom')
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
40
|
-
@request_params = { :
|
39
|
+
it 'should return valid query' do
|
40
|
+
@request_params = { path: '/custom?aaa=bbb' }
|
41
41
|
handshake << client_request
|
42
42
|
|
43
|
-
handshake.query.
|
43
|
+
expect(handshake.query).to eql('aaa=bbb')
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
47
|
-
@request_params = { :
|
46
|
+
it 'should return valid port' do
|
47
|
+
@request_params = { port: 123 }
|
48
48
|
handshake << client_request
|
49
49
|
|
50
|
-
handshake.port.
|
50
|
+
expect(handshake.port).to eql('123')
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it 'should return valid response' do
|
54
54
|
validate_request
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
58
|
-
@request_params = { :
|
57
|
+
it 'should allow custom path' do
|
58
|
+
@request_params = { path: '/custom' }
|
59
59
|
validate_request
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
63
|
-
@request_params = { :
|
62
|
+
it 'should allow query in path' do
|
63
|
+
@request_params = { path: '/custom?test=true' }
|
64
64
|
validate_request
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
68
|
-
@request_params = { :
|
67
|
+
it 'should allow custom port' do
|
68
|
+
@request_params = { port: 123 }
|
69
69
|
validate_request
|
70
70
|
end
|
71
71
|
|
72
|
-
it
|
72
|
+
it 'should recognize unfinished requests' do
|
73
73
|
handshake << client_request[0..-10]
|
74
74
|
|
75
|
-
handshake.
|
76
|
-
handshake.
|
75
|
+
expect(handshake).not_to be_finished
|
76
|
+
expect(handshake).not_to be_valid
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
79
|
+
it 'should disallow requests with invalid request method' do
|
80
80
|
handshake << client_request.gsub('GET', 'POST')
|
81
81
|
|
82
|
-
handshake.
|
83
|
-
handshake.
|
84
|
-
handshake.error.
|
82
|
+
expect(handshake).to be_finished
|
83
|
+
expect(handshake).not_to be_valid
|
84
|
+
expect(handshake.error).to eql(:get_request_required)
|
85
85
|
end
|
86
86
|
|
87
|
-
it
|
88
|
-
request = WEBrick::HTTPRequest.new(
|
89
|
-
request.parse(StringIO.new(client_request)).
|
87
|
+
it 'should parse a rack request' do
|
88
|
+
request = WEBrick::HTTPRequest.new(ServerSoftware: 'rspec')
|
89
|
+
expect(request.parse(StringIO.new(client_request))).to be true
|
90
90
|
rest = client_request.slice((request.to_s.length..-1))
|
91
91
|
|
92
92
|
handshake.from_rack(request.meta_vars.merge(
|
93
|
-
|
93
|
+
'rack.input' => StringIO.new(rest)
|
94
94
|
))
|
95
95
|
validate_request
|
96
96
|
end
|
97
97
|
|
98
|
-
it
|
99
|
-
request = WEBrick::HTTPRequest.new(
|
100
|
-
request.parse(StringIO.new(client_request)).
|
98
|
+
it 'should parse a hash request' do
|
99
|
+
request = WEBrick::HTTPRequest.new(ServerSoftware: 'rspec')
|
100
|
+
expect(request.parse(StringIO.new(client_request))).to be true
|
101
101
|
body = client_request.slice((request.to_s.length..-1))
|
102
102
|
|
103
103
|
path = request.path
|
104
104
|
query = request.query_string
|
105
|
-
headers = request.header.
|
105
|
+
headers = request.header.reduce({}) do |hash, header|
|
106
106
|
hash[header[0]] = header[1].first if header[0] && header[1]
|
107
107
|
hash
|
108
108
|
end
|
109
109
|
|
110
110
|
handshake.from_hash({
|
111
|
-
:
|
112
|
-
:
|
113
|
-
:
|
114
|
-
:
|
111
|
+
headers: headers,
|
112
|
+
path: path,
|
113
|
+
query: query,
|
114
|
+
body: body
|
115
115
|
})
|
116
116
|
|
117
117
|
validate_request
|