faye 0.6.4 → 0.6.5

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

Potentially problematic release.


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

@@ -0,0 +1,120 @@
1
+ # encoding=utf-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Faye::WebSocket::Protocol8Parser do
6
+ include EncodingHelper
7
+
8
+ before do
9
+ @web_socket = mock Faye::WebSocket
10
+ @parser = Faye::WebSocket::Protocol8Parser.new(@web_socket)
11
+ end
12
+
13
+ describe :parse do
14
+ let(:mask) { (1..4).map { rand 255 } }
15
+
16
+ def mask_message(*bytes)
17
+ output = []
18
+ bytes.each_with_index do |byte, i|
19
+ output[i] = byte ^ mask[i % 4]
20
+ end
21
+ output
22
+ end
23
+
24
+ it "parses unmasked text frames" do
25
+ @web_socket.should_receive(:receive).with("Hello")
26
+ parse [0x81, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f]
27
+ end
28
+
29
+ it "parses fragmented text frames" do
30
+ @web_socket.should_receive(:receive).with("Hello")
31
+ parse [0x01, 0x03, 0x48, 0x65, 0x6c]
32
+ parse [0x80, 0x02, 0x6c, 0x6f]
33
+ end
34
+
35
+ it "parses masked text frames" do
36
+ @web_socket.should_receive(:receive).with("Hello")
37
+ parse [0x81, 0x85] + mask + mask_message(0x48, 0x65, 0x6c, 0x6c, 0x6f)
38
+ end
39
+
40
+ it "parses masked fragmented text frames" do
41
+ @web_socket.should_receive(:receive).with("Hello")
42
+ parse [0x01, 0x81] + mask + mask_message(0x48)
43
+ parse [0x80, 0x84] + mask + mask_message(0x65, 0x6c, 0x6c, 0x6f)
44
+ end
45
+
46
+ it "closes the socket if the frame has an unrecognized opcode" do
47
+ @web_socket.should_receive(:close).with(:protocol_error)
48
+ parse [0x83, 0x00]
49
+ end
50
+
51
+ it "parses unmasked multibyte text frames" do
52
+ @web_socket.should_receive(:receive).with(encode "Apple = ")
53
+ parse [0x81, 0x0b, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf]
54
+ end
55
+
56
+ it "parses fragmented multibyte text frames" do
57
+ @web_socket.should_receive(:receive).with(encode "Apple = ")
58
+ parse [0x01, 0x0a, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3]
59
+ parse [0x80, 0x01, 0xbf]
60
+ end
61
+
62
+ it "parses masked multibyte text frames" do
63
+ @web_socket.should_receive(:receive).with(encode "Apple = ")
64
+ parse [0x81, 0x8b] + mask + mask_message(0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf)
65
+ end
66
+
67
+ it "parses masked fragmented multibyte text frames" do
68
+ @web_socket.should_receive(:receive).with(encode "Apple = ")
69
+ parse [0x01, 0x8a] + mask + mask_message(0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3)
70
+ parse [0x80, 0x81] + mask + mask_message(0xbf)
71
+ end
72
+
73
+ it "parses unmasked medium-length text frames" do
74
+ @web_socket.should_receive(:receive).with("Hello" * 40)
75
+ parse [0x81, 0x7e, 0x00, 0xc8] + [0x48, 0x65, 0x6c, 0x6c, 0x6f] * 40
76
+ end
77
+
78
+ it "parses masked medium-length text frames" do
79
+ @web_socket.should_receive(:receive).with("Hello" * 40)
80
+ parse [0x81, 0xfe, 0x00, 0xc8] + mask + mask_message(*([0x48, 0x65, 0x6c, 0x6c, 0x6f] * 40))
81
+ end
82
+
83
+ it "replies to pings with a pong" do
84
+ @web_socket.should_receive(:send).with("OHAI", :pong)
85
+ parse [0x89, 0x04, 0x4f, 0x48, 0x41, 0x49]
86
+ end
87
+ end
88
+
89
+ describe :frame do
90
+ it "returns the given string formatted as a WebSocket frame" do
91
+ bytes(@parser.frame "Hello").should == [0x81, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f]
92
+ end
93
+
94
+ it "encodes multibyte characters correctly" do
95
+ message = encode "Apple = "
96
+ bytes(@parser.frame message).should == [0x81, 0x0b, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf]
97
+ end
98
+
99
+ it "encodes medium-length strings using extra length bytes" do
100
+ message = "Hello" * 40
101
+ bytes(@parser.frame message).should == [0x81, 0x7e, 0x00, 0xc8] + [0x48, 0x65, 0x6c, 0x6c, 0x6f] * 40
102
+ end
103
+
104
+ it "encodes long strings using extra length bytes" do
105
+ message = "Hello" * 13108
106
+ bytes(@parser.frame message).should == [0x81, 0x7f] +
107
+ [0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04] +
108
+ [0x48, 0x65, 0x6c, 0x6c, 0x6f] * 13108
109
+ end
110
+
111
+ it "encodes close frames with an error code" do
112
+ frame = @parser.frame "Hello", :close, :protocol_error
113
+ bytes(frame).should == [0x88, 0x07, 0x03, 0xea, 0x48, 0x65, 0x6c, 0x6c, 0x6f]
114
+ end
115
+
116
+ it "encodes pong frames" do
117
+ bytes(@parser.frame '', :pong).should == [0x8a, 0x00]
118
+ end
119
+ end
120
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,3 +3,22 @@ dir = File.expand_path(File.dirname(__FILE__))
3
3
  require dir + '/../lib/faye'
4
4
  require dir + '/../vendor/em-rspec/lib/em-rspec'
5
5
  require 'rack/test'
6
+
7
+ module EncodingHelper
8
+ def encode(message)
9
+ message.respond_to?(:force_encoding) ?
10
+ message.force_encoding("UTF-8") :
11
+ message
12
+ end
13
+
14
+ def bytes(string)
15
+ count = string.respond_to?(:bytes) ? string.bytes.count : string.size
16
+ (0...count).map do |i|
17
+ string.respond_to?(:getbyte) ? string.getbyte(i) : string[i]
18
+ end
19
+ end
20
+
21
+ def parse(bytes)
22
+ @parser.parse(bytes.map { |b| b.chr } * '')
23
+ end
24
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: faye
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.4
5
+ version: 0.6.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Coglan
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-08-17 00:00:00 Z
13
+ date: 2011-08-29 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: eventmachine
@@ -189,6 +189,7 @@ files:
189
189
  - spec/ruby/server/disconnect_spec.rb
190
190
  - spec/ruby/server/unsubscribe_spec.rb
191
191
  - spec/ruby/server/connect_spec.rb
192
+ - spec/ruby/server/integration_spec.rb
192
193
  - spec/ruby/rack_adapter_spec.rb
193
194
  - spec/ruby/client_spec.rb
194
195
  - spec/ruby/server_spec.rb
@@ -196,6 +197,8 @@ files:
196
197
  - spec/ruby/transport_spec.rb
197
198
  - spec/ruby/engine_spec.rb
198
199
  - spec/ruby/faye_spec.rb
200
+ - spec/ruby/web_socket/draft75_parser_spec.rb
201
+ - spec/ruby/web_socket/protocol8_parser_spec.rb
199
202
  - spec/ruby/grammar_spec.rb
200
203
  - spec/node.js
201
204
  - spec/javascript/faye_spec.js
@@ -203,6 +206,7 @@ files:
203
206
  - spec/javascript/server/subscribe_spec.js
204
207
  - spec/javascript/server/extensions_spec.js
205
208
  - spec/javascript/server/unsubscribe_spec.js
209
+ - spec/javascript/server/integration_spec.js
206
210
  - spec/javascript/server/connect_spec.js
207
211
  - spec/javascript/server/handshake_spec.js
208
212
  - spec/javascript/server_spec.js
@@ -211,6 +215,8 @@ files:
211
215
  - spec/javascript/channel_spec.js
212
216
  - spec/javascript/node_adapter_spec.js
213
217
  - spec/javascript/client_spec.js
218
+ - spec/javascript/web_socket/protocol8parser_spec.js
219
+ - spec/javascript/web_socket/draft75parser_spec.js
214
220
  - spec/javascript/grammar_spec.js
215
221
  - spec/testswarm
216
222
  - spec/spec_helper.rb
@@ -223,6 +229,7 @@ files:
223
229
  - lib/faye/mixins/logging.rb
224
230
  - lib/faye/mixins/publisher.rb
225
231
  - lib/faye/mixins/timeouts.rb
232
+ - lib/faye/thin_extensions.rb
226
233
  - lib/faye/transport/http.rb
227
234
  - lib/faye/transport/local.rb
228
235
  - lib/faye/transport/transport.rb
@@ -237,7 +244,6 @@ files:
237
244
  - lib/faye/engines/memory.rb
238
245
  - lib/faye/engines/redis.rb
239
246
  - lib/faye/engines/base.rb
240
- - lib/thin_extensions.rb
241
247
  - lib/faye.rb
242
248
  homepage: http://faye.jcoglan.com
243
249
  licenses: []