mongrel2 0.38.0 → 0.39.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +6 -0
- data/Manifest.txt +5 -3
- data/Rakefile +2 -2
- data/data/mongrel2/config.sql +6 -1
- data/lib/mongrel2.rb +5 -2
- data/lib/mongrel2/config.rb +1 -0
- data/lib/mongrel2/config/server.rb +15 -0
- data/lib/mongrel2/config/xrequest.rb +45 -0
- data/lib/mongrel2/connection.rb +4 -5
- data/lib/mongrel2/control.rb +2 -2
- data/lib/mongrel2/handler.rb +1 -1
- data/spec/{lib/constants.rb → constants.rb} +0 -2
- data/spec/{lib/helpers.rb → helpers.rb} +9 -12
- data/spec/{lib/matchers.rb → matchers.rb} +2 -12
- data/spec/mongrel2/config/directory_spec.rb +16 -27
- data/spec/mongrel2/config/dsl_spec.rb +115 -98
- data/spec/mongrel2/config/filter_spec.rb +1 -12
- data/spec/mongrel2/config/handler_spec.rb +23 -33
- data/spec/mongrel2/config/host_spec.rb +1 -12
- data/spec/mongrel2/config/log_spec.rb +13 -24
- data/spec/mongrel2/config/proxy_spec.rb +1 -12
- data/spec/mongrel2/config/route_spec.rb +5 -15
- data/spec/mongrel2/config/server_spec.rb +23 -34
- data/spec/mongrel2/config/setting_spec.rb +1 -12
- data/spec/mongrel2/config/statistic_spec.rb +1 -12
- data/spec/mongrel2/config/xrequest_spec.rb +19 -0
- data/spec/mongrel2/config_spec.rb +17 -29
- data/spec/mongrel2/connection_spec.rb +41 -53
- data/spec/mongrel2/constants_spec.rb +2 -14
- data/spec/mongrel2/control_spec.rb +44 -56
- data/spec/mongrel2/handler_spec.rb +64 -76
- data/spec/mongrel2/httprequest_spec.rb +21 -31
- data/spec/mongrel2/httpresponse_spec.rb +55 -67
- data/spec/mongrel2/request_spec.rb +53 -62
- data/spec/mongrel2/response_spec.rb +15 -24
- data/spec/mongrel2/table_spec.rb +41 -53
- data/spec/mongrel2/websocket_spec.rb +95 -104
- data/spec/mongrel2_spec.rb +3 -12
- metadata +13 -11
- metadata.gz.sig +0 -0
@@ -1,22 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#encoding: utf-8
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
7
|
-
|
8
|
-
libdir = basedir + "lib"
|
9
|
-
|
10
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
11
|
-
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
12
|
-
}
|
4
|
+
require_relative '../helpers'
|
13
5
|
|
14
6
|
require 'rspec'
|
7
|
+
|
15
8
|
require 'tnetstring'
|
16
9
|
require 'securerandom'
|
17
10
|
|
18
|
-
require 'spec/lib/helpers'
|
19
|
-
|
20
11
|
require 'mongrel2'
|
21
12
|
require 'mongrel2/websocket'
|
22
13
|
|
@@ -28,7 +19,7 @@ require 'mongrel2/websocket'
|
|
28
19
|
describe Mongrel2::WebSocket do
|
29
20
|
|
30
21
|
before( :all ) do
|
31
|
-
setup_logging(
|
22
|
+
setup_logging()
|
32
23
|
@factory = Mongrel2::WebSocketFrameFactory.new( route: '/websock' )
|
33
24
|
end
|
34
25
|
|
@@ -56,17 +47,17 @@ describe Mongrel2::WebSocket do
|
|
56
47
|
describe 'ClientHandshake' do
|
57
48
|
|
58
49
|
it "is the registered request type for WEBSOCKET_HANDSHAKE requests" do
|
59
|
-
Mongrel2::Request.request_types[:WEBSOCKET_HANDSHAKE].
|
50
|
+
expect( Mongrel2::Request.request_types[:WEBSOCKET_HANDSHAKE] ).to eq( Mongrel2::WebSocket::ClientHandshake )
|
60
51
|
end
|
61
52
|
|
62
53
|
it "knows what subprotocols were requested" do
|
63
54
|
handshake = @factory.handshake( '/websock', 'echo', 'superecho' )
|
64
|
-
handshake.protocols.
|
55
|
+
expect( handshake.protocols ).to eq( ['echo', 'superecho'] )
|
65
56
|
end
|
66
57
|
|
67
58
|
it "doesn't error if no subprotocols were requested" do
|
68
59
|
handshake = @factory.handshake( '/websock' )
|
69
|
-
handshake.protocols.
|
60
|
+
expect( handshake.protocols ).to eq( [] )
|
70
61
|
end
|
71
62
|
|
72
63
|
it "can create a response WebSocket::ServerHandshake for itself" do
|
@@ -74,16 +65,16 @@ describe Mongrel2::WebSocket do
|
|
74
65
|
result = handshake.response
|
75
66
|
handshake.body.rewind
|
76
67
|
|
77
|
-
result.
|
78
|
-
result.sender_id.
|
79
|
-
result.conn_id.
|
80
|
-
result.header.sec_websocket_accept.
|
81
|
-
result.status.
|
82
|
-
result.header.connection.
|
83
|
-
result.header.upgrade.
|
68
|
+
expect( result ).to be_a( Mongrel2::WebSocket::ServerHandshake )
|
69
|
+
expect( result.sender_id ).to eq( handshake.sender_id )
|
70
|
+
expect( result.conn_id ).to eq( handshake.conn_id )
|
71
|
+
expect( result.header.sec_websocket_accept ).to eq( handshake.body.string )
|
72
|
+
expect( result.status ).to eq( HTTP::SWITCHING_PROTOCOLS )
|
73
|
+
expect( result.header.connection ).to match( /upgrade/i )
|
74
|
+
expect( result.header.upgrade ).to match( /websocket/i )
|
84
75
|
|
85
76
|
result.body.rewind
|
86
|
-
result.body.read.
|
77
|
+
expect( result.body.read ).to eq( '' )
|
87
78
|
end
|
88
79
|
|
89
80
|
it "can create a response WebSocket::ServerHandshake with a valid sub-protocol for itself" do
|
@@ -91,17 +82,17 @@ describe Mongrel2::WebSocket do
|
|
91
82
|
result = handshake.response( :superecho )
|
92
83
|
handshake.body.rewind
|
93
84
|
|
94
|
-
result.
|
95
|
-
result.sender_id.
|
96
|
-
result.conn_id.
|
97
|
-
result.header.sec_websocket_accept.
|
98
|
-
result.status.
|
99
|
-
result.header.connection.
|
100
|
-
result.header.upgrade.
|
101
|
-
result.protocols.
|
85
|
+
expect( result ).to be_a( Mongrel2::WebSocket::ServerHandshake )
|
86
|
+
expect( result.sender_id ).to eq( handshake.sender_id )
|
87
|
+
expect( result.conn_id ).to eq( handshake.conn_id )
|
88
|
+
expect( result.header.sec_websocket_accept ).to eq( handshake.body.string )
|
89
|
+
expect( result.status ).to eq( HTTP::SWITCHING_PROTOCOLS )
|
90
|
+
expect( result.header.connection ).to match( /upgrade/i )
|
91
|
+
expect( result.header.upgrade ).to match( /websocket/i )
|
92
|
+
expect( result.protocols ).to eq( ['superecho'] )
|
102
93
|
|
103
94
|
result.body.rewind
|
104
|
-
result.body.read.
|
95
|
+
expect( result.body.read ).to eq( '' )
|
105
96
|
end
|
106
97
|
|
107
98
|
it "raises an exception if the specified protocol is not one of the client's advertised ones" do
|
@@ -114,7 +105,7 @@ describe Mongrel2::WebSocket do
|
|
114
105
|
|
115
106
|
it "has a socket identifier" do
|
116
107
|
handshake = @factory.handshake( '/websock', 'echo', 'superecho' )
|
117
|
-
handshake.socket_id.
|
108
|
+
expect( handshake.socket_id ).to eq( "#{handshake.sender_id}:#{handshake.conn_id}" )
|
118
109
|
end
|
119
110
|
|
120
111
|
end
|
@@ -124,121 +115,121 @@ describe Mongrel2::WebSocket do
|
|
124
115
|
describe 'Frame' do
|
125
116
|
|
126
117
|
it "is the registered request type for WEBSOCKET requests" do
|
127
|
-
Mongrel2::Request.request_types[:WEBSOCKET].
|
118
|
+
expect( Mongrel2::Request.request_types[:WEBSOCKET] ).to eq( Mongrel2::WebSocket::Frame )
|
128
119
|
end
|
129
120
|
|
130
121
|
it "knows that its FIN flag is not set if its FLAG header doesn't include that bit" do
|
131
122
|
frame = @factory.text( '/websock', 'Hello!' )
|
132
123
|
frame.flags ^= ( frame.flags & Mongrel2::WebSocket::FIN_FLAG )
|
133
|
-
frame.
|
124
|
+
expect( frame ).to_not be_fin()
|
134
125
|
end
|
135
126
|
|
136
127
|
it "knows that its FIN flag is set if its FLAG header includes that bit" do
|
137
128
|
frame = @factory.text( '/websock', 'Hello!', :fin )
|
138
|
-
frame.
|
129
|
+
expect( frame ).to be_fin()
|
139
130
|
end
|
140
131
|
|
141
132
|
it "can unset its FIN flag" do
|
142
133
|
frame = @factory.text( '/websock', 'Hello!', :fin )
|
143
134
|
frame.fin = false
|
144
|
-
frame.
|
135
|
+
expect( frame ).to_not be_fin()
|
145
136
|
end
|
146
137
|
|
147
138
|
it "can set its FIN flag" do
|
148
139
|
frame = @factory.text( '/websock', 'Hello!' )
|
149
140
|
frame.fin = true
|
150
|
-
frame.
|
141
|
+
expect( frame ).to be_fin()
|
151
142
|
end
|
152
143
|
|
153
144
|
it "knows that its opcode is continuation if its opcode is 0x0" do
|
154
|
-
@factory.continuation( '/websock' ).opcode.
|
145
|
+
expect( @factory.continuation( '/websock' ).opcode ).to eq( :continuation )
|
155
146
|
end
|
156
147
|
|
157
148
|
it "knows that is opcode is 'text' if its opcode is 0x1" do
|
158
|
-
@factory.text( '/websock', 'Hello!' ).opcode.
|
149
|
+
expect( @factory.text( '/websock', 'Hello!' ).opcode ).to eq( :text )
|
159
150
|
end
|
160
151
|
|
161
152
|
it "knows that is opcode is 'binary' if its opcode is 0x2" do
|
162
|
-
@factory.binary( '/websock', 'Hello!' ).opcode.
|
153
|
+
expect( @factory.binary( '/websock', 'Hello!' ).opcode ).to eq( :binary )
|
163
154
|
end
|
164
155
|
|
165
156
|
it "knows that is opcode is 'close' if its opcode is 0x8" do
|
166
|
-
@factory.close( '/websock' ).opcode.
|
157
|
+
expect( @factory.close( '/websock' ).opcode ).to eq( :close )
|
167
158
|
end
|
168
159
|
|
169
160
|
it "knows that is opcode is 'ping' if its opcode is 0x9" do
|
170
|
-
@factory.ping( '/websock' ).opcode.
|
161
|
+
expect( @factory.ping( '/websock' ).opcode ).to eq( :ping )
|
171
162
|
end
|
172
163
|
|
173
164
|
it "knows that is opcode is 'pong' if its opcode is 0xA" do
|
174
|
-
@factory.pong( '/websock' ).opcode.
|
165
|
+
expect( @factory.pong( '/websock' ).opcode ).to eq( :pong )
|
175
166
|
end
|
176
167
|
|
177
168
|
it "knows that its opcode is one of the reserved ones if it's 0x3" do
|
178
|
-
@factory.create( '/websocket', '', 0x3 ).opcode.
|
169
|
+
expect( @factory.create( '/websocket', '', 0x3 ).opcode ).to eq( :reserved )
|
179
170
|
end
|
180
171
|
|
181
172
|
it "knows that its opcode is one of the reserved ones if it's 0x4" do
|
182
|
-
@factory.create( '/websocket', '', 0x4 ).opcode.
|
173
|
+
expect( @factory.create( '/websocket', '', 0x4 ).opcode ).to eq( :reserved )
|
183
174
|
end
|
184
175
|
|
185
176
|
it "knows that its opcode is one of the reserved ones if it's 0xB" do
|
186
|
-
@factory.create( '/websocket', '', 0xB ).opcode.
|
177
|
+
expect( @factory.create( '/websocket', '', 0xB ).opcode ).to eq( :reserved )
|
187
178
|
end
|
188
179
|
|
189
180
|
it "knows that its opcode is one of the reserved ones if it's 0xD" do
|
190
|
-
@factory.create( '/websocket', '', 0xD ).opcode.
|
181
|
+
expect( @factory.create( '/websocket', '', 0xD ).opcode ).to eq( :reserved )
|
191
182
|
end
|
192
183
|
|
193
184
|
it "knows that its opcode is one of the reserved ones if it's 0xF" do
|
194
|
-
@factory.create( '/websocket', '', 0xF ).opcode.
|
185
|
+
expect( @factory.create( '/websocket', '', 0xF ).opcode ).to eq( :reserved )
|
195
186
|
end
|
196
187
|
|
197
188
|
it "allows its opcode to be set Symbolically" do
|
198
189
|
frame = @factory.text( '/websocket', 'data' )
|
199
190
|
frame.opcode = :binary
|
200
|
-
frame.numeric_opcode.
|
191
|
+
expect( frame.numeric_opcode ).to eq( OPCODE[:binary] )
|
201
192
|
end
|
202
193
|
|
203
194
|
it "allows its opcode to be set Numerically" do
|
204
195
|
frame = @factory.binary( '/websocket', 'data' )
|
205
196
|
frame.opcode = :text
|
206
|
-
frame.numeric_opcode.
|
197
|
+
expect( frame.numeric_opcode ).to eq( OPCODE[:text] )
|
207
198
|
end
|
208
199
|
|
209
200
|
it "allows its opcode to be set to one of the reserved opcodes Numerically" do
|
210
201
|
frame = @factory.binary( '/websocket', 'data' )
|
211
202
|
frame.opcode = 0xC
|
212
|
-
frame.opcode.
|
213
|
-
frame.numeric_opcode.
|
203
|
+
expect( frame.opcode ).to eq( :reserved )
|
204
|
+
expect( frame.numeric_opcode ).to eq( 0xC )
|
214
205
|
end
|
215
206
|
|
216
207
|
it "knows that its RSV1 flag is set if its FLAG header includes that bit" do
|
217
|
-
@factory.ping( '/websock', 'test', :rsv1 ).
|
208
|
+
expect( @factory.ping( '/websock', 'test', :rsv1 ) ).to be_rsv1()
|
218
209
|
end
|
219
210
|
|
220
211
|
it "knows that its RSV2 flag is set if its FLAG header includes that bit" do
|
221
|
-
@factory.ping( '/websock', 'test', :rsv2 ).
|
212
|
+
expect( @factory.ping( '/websock', 'test', :rsv2 ) ).to be_rsv2()
|
222
213
|
end
|
223
214
|
|
224
215
|
it "knows that its RSV3 flag is set if its FLAG header includes that bit" do
|
225
|
-
@factory.ping( '/websock', 'test', :rsv3 ).
|
216
|
+
expect( @factory.ping( '/websock', 'test', :rsv3 ) ).to be_rsv3()
|
226
217
|
end
|
227
218
|
|
228
219
|
it "knows that one of its RSV flags is set if its FLAG header includes RSV1" do
|
229
|
-
@factory.ping( '/websock', 'test', :rsv1 ).
|
220
|
+
expect( @factory.ping( '/websock', 'test', :rsv1 ) ).to have_rsv_flags()
|
230
221
|
end
|
231
222
|
|
232
223
|
it "knows that one of its RSV flags is set if its FLAG header includes RSV2" do
|
233
|
-
@factory.ping( '/websock', 'test', :rsv2 ).
|
224
|
+
expect( @factory.ping( '/websock', 'test', :rsv2 ) ).to have_rsv_flags()
|
234
225
|
end
|
235
226
|
|
236
227
|
it "knows that one of its RSV flags is set if its FLAG header includes RSV3" do
|
237
|
-
@factory.ping( '/websock', 'test', :rsv3 ).
|
228
|
+
expect( @factory.ping( '/websock', 'test', :rsv3 ) ).to have_rsv_flags()
|
238
229
|
end
|
239
230
|
|
240
231
|
it "knows that no RSV flags are set if its FLAG header doesn't have any RSV bits" do
|
241
|
-
@factory.ping( '/websock', 'test' ).
|
232
|
+
expect( @factory.ping( '/websock', 'test' ) ).to_not have_rsv_flags()
|
242
233
|
end
|
243
234
|
|
244
235
|
it "can create a response WebSocket::Frame for itself" do
|
@@ -246,13 +237,13 @@ describe Mongrel2::WebSocket do
|
|
246
237
|
|
247
238
|
result = frame.response
|
248
239
|
|
249
|
-
result.
|
250
|
-
result.sender_id.
|
251
|
-
result.conn_id.
|
252
|
-
result.opcode.
|
240
|
+
expect( result ).to be_a( Mongrel2::WebSocket::Frame )
|
241
|
+
expect( result.sender_id ).to eq( frame.sender_id )
|
242
|
+
expect( result.conn_id ).to eq( frame.conn_id )
|
243
|
+
expect( result.opcode ).to eq( :text )
|
253
244
|
|
254
245
|
result.payload.rewind
|
255
|
-
result.payload.read.
|
246
|
+
expect( result.payload.read ).to eq( '' )
|
256
247
|
end
|
257
248
|
|
258
249
|
it "creates PONG responses with the same payload for PING frames" do
|
@@ -260,13 +251,13 @@ describe Mongrel2::WebSocket do
|
|
260
251
|
|
261
252
|
result = frame.response
|
262
253
|
|
263
|
-
result.
|
264
|
-
result.sender_id.
|
265
|
-
result.conn_id.
|
266
|
-
result.opcode.
|
254
|
+
expect( result ).to be_a( Mongrel2::WebSocket::Frame )
|
255
|
+
expect( result.sender_id ).to eq( frame.sender_id )
|
256
|
+
expect( result.conn_id ).to eq( frame.conn_id )
|
257
|
+
expect( result.opcode ).to eq( :pong )
|
267
258
|
|
268
259
|
result.payload.rewind
|
269
|
-
result.payload.read.
|
260
|
+
expect( result.payload.read ).to eq( 'WOO' )
|
270
261
|
end
|
271
262
|
|
272
263
|
it "allows header flags and/or opcode to be specified when creating a response" do
|
@@ -274,14 +265,14 @@ describe Mongrel2::WebSocket do
|
|
274
265
|
|
275
266
|
result = frame.response( :close, :fin )
|
276
267
|
|
277
|
-
result.
|
278
|
-
result.sender_id.
|
279
|
-
result.conn_id.
|
280
|
-
result.opcode.
|
281
|
-
result.
|
268
|
+
expect( result ).to be_a( Mongrel2::WebSocket::Frame )
|
269
|
+
expect( result.sender_id ).to eq( frame.sender_id )
|
270
|
+
expect( result.conn_id ).to eq( frame.conn_id )
|
271
|
+
expect( result.opcode ).to eq( :close )
|
272
|
+
expect( result ).to be_fin()
|
282
273
|
|
283
274
|
result.payload.rewind
|
284
|
-
result.payload.read.
|
275
|
+
expect( result.payload.read ).to eq( '' )
|
285
276
|
end
|
286
277
|
|
287
278
|
it "allows reserved opcodes to be specified when creating a response" do
|
@@ -289,14 +280,14 @@ describe Mongrel2::WebSocket do
|
|
289
280
|
|
290
281
|
result = frame.response( 0xB )
|
291
282
|
|
292
|
-
result.
|
293
|
-
result.sender_id.
|
294
|
-
result.conn_id.
|
295
|
-
result.opcode.
|
296
|
-
result.numeric_opcode.
|
283
|
+
expect( result ).to be_a( Mongrel2::WebSocket::Frame )
|
284
|
+
expect( result.sender_id ).to eq( frame.sender_id )
|
285
|
+
expect( result.conn_id ).to eq( frame.conn_id )
|
286
|
+
expect( result.opcode ).to eq( :reserved )
|
287
|
+
expect( result.numeric_opcode ).to eq( 0xB )
|
297
288
|
|
298
289
|
result.payload.rewind
|
299
|
-
result.payload.read.
|
290
|
+
expect( result.payload.read ).to eq( '' )
|
300
291
|
end
|
301
292
|
|
302
293
|
it "can be streamed in chunks instead of read all at once" do
|
@@ -304,15 +295,15 @@ describe Mongrel2::WebSocket do
|
|
304
295
|
binary = @factory.binary( '/websock', data, :fin )
|
305
296
|
|
306
297
|
binary.chunksize = 16
|
307
|
-
binary.each_chunk.to_a[0,2].
|
298
|
+
expect( binary.each_chunk.to_a[0,2] ).to eq([
|
308
299
|
"\x82\x7F\x00\x00\x00\x00\x00\x01\x00\x00\a\xBD\xB3\xFE\x87\xEB".force_encoding('binary'),
|
309
300
|
"\xA9\x0En2q\xCE\x85\xAF)\x88w_d\xD6M\x9E".force_encoding('binary'),
|
310
|
-
]
|
301
|
+
])
|
311
302
|
end
|
312
303
|
|
313
304
|
it "has a socket identifier" do
|
314
305
|
frame = @factory.text( '/websock', "data" )
|
315
|
-
frame.socket_id.
|
306
|
+
expect( frame.socket_id ).to eq( "#{frame.sender_id}:#{frame.conn_id}" )
|
316
307
|
end
|
317
308
|
|
318
309
|
end
|
@@ -329,9 +320,9 @@ describe Mongrel2::WebSocket do
|
|
329
320
|
@frame << text
|
330
321
|
|
331
322
|
# 2-byte header
|
332
|
-
@frame.bytes.to_a[ 2..-1 ].
|
333
|
-
[0xD0, 0xA1, 0xD1, 0x82, 0xD1, 0x80, 0xD0, 0xB5, 0xD0, 0xBB, 0xD0,
|
334
|
-
0xBA, 0xD0, 0xB5, 0x21]
|
323
|
+
expect( @frame.bytes.to_a[ 2..-1 ] ).
|
324
|
+
to eq([0xD0, 0xA1, 0xD1, 0x82, 0xD1, 0x80, 0xD0, 0xB5, 0xD0, 0xBB, 0xD0,
|
325
|
+
0xBA, 0xD0, 0xB5, 0x21])
|
335
326
|
end
|
336
327
|
|
337
328
|
end
|
@@ -344,9 +335,9 @@ describe Mongrel2::WebSocket do
|
|
344
335
|
|
345
336
|
it "doesn't try to transcode non-UTF8 data" do
|
346
337
|
# 4-byte header
|
347
|
-
@frame.bytes.to_a[ 4, 16 ].
|
348
|
-
[ 0x07, 0xbd, 0xb3, 0xfe, 0x87, 0xeb, 0xa9, 0x0e, 0x6e, 0x32, 0x71,
|
349
|
-
0xce, 0x85, 0xaf, 0x29, 0x88 ]
|
338
|
+
expect( @frame.bytes.to_a[ 4, 16 ] ).
|
339
|
+
to eq([ 0x07, 0xbd, 0xb3, 0xfe, 0x87, 0xeb, 0xa9, 0x0e, 0x6e, 0x32, 0x71,
|
340
|
+
0xce, 0x85, 0xaf, 0x29, 0x88 ])
|
350
341
|
end
|
351
342
|
end
|
352
343
|
|
@@ -359,8 +350,8 @@ describe Mongrel2::WebSocket do
|
|
359
350
|
it "has convenience methods for setting its payload via integer status code" do
|
360
351
|
@frame.set_status( CLOSE_BAD_DATA )
|
361
352
|
@frame.payload.rewind
|
362
|
-
@frame.payload.read.
|
363
|
-
[
|
353
|
+
expect( @frame.payload.read ).
|
354
|
+
to eq( "%d %s\n" % [CLOSE_BAD_DATA, CLOSING_STATUS_DESC[CLOSE_BAD_DATA]] )
|
364
355
|
end
|
365
356
|
|
366
357
|
end
|
@@ -393,16 +384,16 @@ describe Mongrel2::WebSocket do
|
|
393
384
|
|
394
385
|
it "generates a single-frame unmasked text message correctly" do
|
395
386
|
raw_response = @factory.text( '/websock', "Hello", :fin ).to_s
|
396
|
-
raw_response.bytes.to_a.
|
397
|
-
raw_response.encoding.
|
387
|
+
expect( raw_response.bytes.to_a ).to eq( [ 0x81, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f ] )
|
388
|
+
expect( raw_response.encoding ).to eq( Encoding::BINARY )
|
398
389
|
end
|
399
390
|
|
400
391
|
it "generates both parts of a fragmented unmasked text message correctly" do
|
401
392
|
first = @factory.text( '/websock', 'Hel' )
|
402
393
|
last = @factory.continuation( '/websock', 'lo', :fin )
|
403
394
|
|
404
|
-
first.bytes.to_a.
|
405
|
-
last.bytes.to_a.
|
395
|
+
expect( first.bytes.to_a ).to eq( [ 0x01, 0x03, 0x48, 0x65, 0x6c ] )
|
396
|
+
expect( last.bytes.to_a ).to eq( [ 0x80, 0x02, 0x6c, 0x6f ] )
|
406
397
|
end
|
407
398
|
|
408
399
|
# The RFC's example is a masked response, but we're never a client, so never
|
@@ -411,8 +402,8 @@ describe Mongrel2::WebSocket do
|
|
411
402
|
ping = @factory.ping( '/websock', 'Hello' )
|
412
403
|
pong = @factory.pong( '/websock', 'Hello' )
|
413
404
|
|
414
|
-
ping.bytes.to_a.
|
415
|
-
pong.bytes.to_a.
|
405
|
+
expect( ping.bytes.to_a ).to eq( [ 0x89, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f ] )
|
406
|
+
expect( pong.bytes.to_a ).to eq( [ 0x8a, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f ] )
|
416
407
|
end
|
417
408
|
|
418
409
|
|
@@ -420,8 +411,8 @@ describe Mongrel2::WebSocket do
|
|
420
411
|
binary = @factory.binary( '/websock', BINARY_DATA, :fin )
|
421
412
|
|
422
413
|
# 1 + 1 + 2
|
423
|
-
binary.bytes.to_a[0,4].
|
424
|
-
binary.to_s[4..-1].
|
414
|
+
expect( binary.bytes.to_a[0,4] ).to eq( [ 0x82, 0x7E, 0x01, 0x00 ] )
|
415
|
+
expect( binary.to_s[4..-1] ).to eq( BINARY_DATA )
|
425
416
|
end
|
426
417
|
|
427
418
|
it "generates a 64KiB binary message in a single unmasked frame correctly" do
|
@@ -430,9 +421,9 @@ describe Mongrel2::WebSocket do
|
|
430
421
|
binary = @factory.binary( '/websock', data, :fin )
|
431
422
|
|
432
423
|
# 1 + 1 + 8
|
433
|
-
binary.bytes.to_a[0,10].
|
434
|
-
[ 0x82, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 ]
|
435
|
-
binary.to_s[10..-1].
|
424
|
+
expect( binary.bytes.to_a[0,10] ).
|
425
|
+
to eq([ 0x82, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 ])
|
426
|
+
expect( binary.to_s[10..-1] ).to eq( data )
|
436
427
|
end
|
437
428
|
|
438
429
|
end
|
data/spec/mongrel2_spec.rb
CHANGED
@@ -1,18 +1,9 @@
|
|
1
1
|
#!/usr/bin/env rspec -cfd -b
|
2
2
|
|
3
|
-
|
4
|
-
require 'pathname'
|
5
|
-
basedir = Pathname( __FILE__ ).dirname.parent
|
6
|
-
libdir = basedir + 'lib'
|
7
|
-
|
8
|
-
$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
|
9
|
-
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
10
|
-
}
|
3
|
+
require_relative 'helpers'
|
11
4
|
|
12
5
|
require 'rspec'
|
13
6
|
|
14
|
-
require 'spec/lib/helpers'
|
15
|
-
|
16
7
|
require 'loggability'
|
17
8
|
require 'mongrel2'
|
18
9
|
|
@@ -21,12 +12,12 @@ describe Mongrel2 do
|
|
21
12
|
|
22
13
|
describe "version methods" do
|
23
14
|
it "returns a version string if asked" do
|
24
|
-
Mongrel2.version_string.
|
15
|
+
expect( Mongrel2.version_string ).to match( /\w+ [\d.]+/ )
|
25
16
|
end
|
26
17
|
|
27
18
|
|
28
19
|
it "returns a version string with a build number if asked" do
|
29
|
-
Mongrel2.version_string(true).
|
20
|
+
expect( Mongrel2.version_string(true) ).to match( /\w+ [\d.]+ \(build [[:xdigit:]]+\)/ )
|
30
21
|
end
|
31
22
|
end
|
32
23
|
|