reel 0.4.0.pre → 0.4.0.pre2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of reel might be problematic. Click here for more details.

@@ -10,7 +10,7 @@ describe Reel::Response do
10
10
  connection.close
11
11
 
12
12
  response = client.read(4096)
13
- crlf = Reel::Response::CRLF
13
+ crlf = Reel::Response::Writer::CRLF
14
14
  fixture = "5#{crlf}Hello#{crlf}5#{crlf}World#{crlf}0#{crlf*2}"
15
15
  response[(response.length - fixture.length)..-1].should eq fixture
16
16
  end
@@ -35,7 +35,7 @@ describe Reel::Server do
35
35
  begin
36
36
  request = connection.request
37
37
  request.method.should eq 'POST'
38
- connection.respond :ok, request.body
38
+ connection.respond :ok, request.body.to_s
39
39
  rescue => ex
40
40
  end
41
41
  end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require 'net/http'
3
+
4
+ describe Reel::SSLServer do
5
+ let(:example_ssl_port) { example_port + 1 }
6
+ let(:example_url) { "https://#{example_addr}:#{example_ssl_port}#{example_path}" }
7
+ let(:endpoint) { URI(example_url) }
8
+ let(:response_body) { "ohai thar" }
9
+
10
+ let(:server_cert) { fixture_dir.join("server.crt").read }
11
+ let(:server_key) { fixture_dir.join("server.key").read }
12
+
13
+ it "receives HTTP requests and sends responses" do
14
+ ex = nil
15
+
16
+ handler = proc do |connection|
17
+ begin
18
+ request = connection.request
19
+ request.method.should eq 'GET'
20
+ request.version.should eq "1.1"
21
+ request.url.should eq example_path
22
+
23
+ connection.respond :ok, response_body
24
+ rescue => ex
25
+ end
26
+ end
27
+
28
+ with_reel_sslserver(handler) do
29
+ http = Net::HTTP.new(endpoint.host, endpoint.port)
30
+ http.use_ssl = true
31
+
32
+ # FIXME: VERIFY_NONE is bad! Authenticate the server cert!
33
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
34
+ request = Net::HTTP::Get.new(endpoint.path)
35
+ response = http.request(request)
36
+
37
+ response.body.should eq response_body
38
+ end
39
+
40
+ raise ex if ex
41
+ end
42
+
43
+ def with_reel_sslserver(handler, context = OpenSSL::SSL::SSLContext.new)
44
+ options = {
45
+ :cert => server_cert,
46
+ :key => server_key
47
+ }
48
+
49
+ server = Reel::SSLServer.new(example_addr, example_ssl_port, options, &handler)
50
+ yield server
51
+ ensure
52
+ server.terminate if server && server.alive?
53
+ end
54
+ end
@@ -10,13 +10,26 @@ describe Reel::WebSocket do
10
10
  with_socket_pair do |client, connection|
11
11
  client << handshake.to_data
12
12
 
13
- websocket = connection.request
13
+ request = connection.request
14
+ request.should be_websocket
15
+
16
+ websocket = request.websocket
14
17
  websocket.should be_a Reel::WebSocket
15
18
 
16
19
  handshake.errors.should be_empty
17
20
  end
18
21
  end
19
22
 
23
+ it "raises an error if trying to close a connection upgraded to socket" do
24
+ with_socket_pair do |client, connection|
25
+ client << handshake.to_data
26
+
27
+ websocket = connection.request.websocket
28
+ websocket.should be_a Reel::WebSocket
29
+ expect { connection.close }.to raise_error(Reel::Connection::StateError)
30
+ end
31
+ end
32
+
20
33
  it "knows its URL" do
21
34
  with_websocket_pair do |_, websocket|
22
35
  websocket.url.should == example_path
@@ -62,10 +75,29 @@ describe Reel::WebSocket do
62
75
  end
63
76
  end
64
77
 
78
+ it "raises a RequestError when connection used after it was upgraded" do
79
+ with_socket_pair do |client, connection|
80
+ client << handshake.to_data
81
+
82
+ remote_host = connection.remote_host
83
+
84
+ request = connection.request
85
+ request.should be_websocket
86
+ websocket = request.websocket
87
+ websocket.should be_a Reel::WebSocket
88
+
89
+ expect { connection.remote_host }.to raise_error(Reel::Connection::StateError)
90
+ websocket.remote_host.should == remote_host
91
+ end
92
+ end
93
+
65
94
  def with_websocket_pair
66
95
  with_socket_pair do |client, connection|
67
96
  client << handshake.to_data
68
- websocket = connection.request
97
+ request = connection.request
98
+
99
+ request.should be_websocket
100
+ websocket = request.websocket
69
101
  websocket.should be_a Reel::WebSocket
70
102
 
71
103
  # Discard handshake
@@ -1,11 +1,17 @@
1
- require 'bundler/setup'
2
- require 'reel'
3
1
  require 'coveralls'
4
2
  Coveralls.wear!
5
3
 
4
+ require 'bundler/setup'
5
+ require 'reel'
6
+ require 'pry'
7
+
6
8
  logfile = File.open(File.expand_path("../../log/test.log", __FILE__), 'a')
7
9
  Celluloid.logger = Logger.new(logfile)
8
10
 
11
+ def fixture_dir
12
+ Pathname.new File.expand_path("../fixtures", __FILE__)
13
+ end
14
+
9
15
  def example_addr; '127.0.0.1'; end
10
16
  def example_port; 1234; end
11
17
  def example_path; "/example"; end
@@ -18,7 +24,7 @@ ensure
18
24
  server.terminate if server && server.alive?
19
25
  end
20
26
 
21
- def with_socket_pair
27
+ def with_socket_pair(buffer_size = nil)
22
28
  host = '127.0.0.1'
23
29
  port = 10101
24
30
 
@@ -27,7 +33,7 @@ def with_socket_pair
27
33
  peer = server.accept
28
34
 
29
35
  begin
30
- connection = Reel::Connection.new(peer)
36
+ connection = Reel::Connection.new(peer, buffer_size)
31
37
  yield client, connection
32
38
  ensure
33
39
  server.close rescue nil
@@ -87,7 +93,7 @@ module WebSocketHelpers
87
93
  }
88
94
  end
89
95
 
90
- let(:handshake) { WebSocket::ClientHandshake.new(:get, example_url, handshake_headers) }
96
+ let(:handshake) { WebSocket::ClientHandshake.new(:get, example_url, handshake_headers) }
91
97
  end
92
98
  end
93
99
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.pre
4
+ version: 0.4.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-01 00:00:00.000000000 Z
11
+ date: 2013-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: celluloid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.14.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.14.1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: celluloid-io
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - '>='
18
32
  - !ruby/object:Gem::Version
19
- version: 0.8.0
33
+ version: 0.14.1
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - '>='
25
39
  - !ruby/object:Gem::Version
26
- version: 0.8.0
40
+ version: 0.14.1
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: http
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +58,28 @@ dependencies:
44
58
  requirements:
45
59
  - - '>='
46
60
  - !ruby/object:Gem::Version
47
- version: 0.5.3
61
+ version: 0.6.0.beta.2
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - '>='
53
67
  - !ruby/object:Gem::Version
54
- version: 0.5.3
68
+ version: 0.6.0.beta.2
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: websocket_parser
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - '>='
60
74
  - !ruby/object:Gem::Version
61
- version: 0.1.2
75
+ version: 0.1.4
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - '>='
67
81
  - !ruby/object:Gem::Version
68
- version: 0.1.2
82
+ version: 0.1.4
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rack
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +150,7 @@ files:
136
150
  - .travis.yml
137
151
  - CHANGES.md
138
152
  - Gemfile
153
+ - Guardfile
139
154
  - LICENSE.txt
140
155
  - README.md
141
156
  - Rakefile
@@ -148,6 +163,7 @@ files:
148
163
  - examples/hello_world.rb
149
164
  - examples/roundtrip.rb
150
165
  - examples/server-sent-events.rb
166
+ - examples/ssl_hello_world.rb
151
167
  - examples/stream.rb
152
168
  - examples/websocket-wall.rb
153
169
  - examples/websocket.ru
@@ -161,21 +177,30 @@ files:
161
177
  - lib/reel/mixins.rb
162
178
  - lib/reel/rack_worker.rb
163
179
  - lib/reel/request.rb
180
+ - lib/reel/request_body.rb
181
+ - lib/reel/request_info.rb
164
182
  - lib/reel/request_parser.rb
165
183
  - lib/reel/response.rb
184
+ - lib/reel/response_writer.rb
166
185
  - lib/reel/server.rb
186
+ - lib/reel/ssl_server.rb
167
187
  - lib/reel/stream.rb
168
188
  - lib/reel/version.rb
169
189
  - lib/reel/websocket.rb
170
190
  - log/.gitignore
171
191
  - logo.png
172
192
  - reel.gemspec
193
+ - spec/fixtures/client.crt
194
+ - spec/fixtures/client.key
173
195
  - spec/fixtures/example.txt
196
+ - spec/fixtures/server.crt
197
+ - spec/fixtures/server.key
174
198
  - spec/reel/app_spec.rb
175
199
  - spec/reel/connection_spec.rb
176
200
  - spec/reel/rack_worker_spec.rb
177
201
  - spec/reel/response_spec.rb
178
202
  - spec/reel/server_spec.rb
203
+ - spec/reel/ssl_server_spec.rb
179
204
  - spec/reel/websocket_spec.rb
180
205
  - spec/spec_helper.rb
181
206
  - tasks/rspec.rake
@@ -203,11 +228,16 @@ signing_key:
203
228
  specification_version: 4
204
229
  summary: A reel good HTTP server
205
230
  test_files:
231
+ - spec/fixtures/client.crt
232
+ - spec/fixtures/client.key
206
233
  - spec/fixtures/example.txt
234
+ - spec/fixtures/server.crt
235
+ - spec/fixtures/server.key
207
236
  - spec/reel/app_spec.rb
208
237
  - spec/reel/connection_spec.rb
209
238
  - spec/reel/rack_worker_spec.rb
210
239
  - spec/reel/response_spec.rb
211
240
  - spec/reel/server_spec.rb
241
+ - spec/reel/ssl_server_spec.rb
212
242
  - spec/reel/websocket_spec.rb
213
243
  - spec/spec_helper.rb