faye-websocket 0.4.6 → 0.4.7

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

Potentially problematic release.


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

@@ -50,7 +50,7 @@ module Faye
50
50
  @masking = options[:masking]
51
51
  @protocols = options[:protocols]
52
52
  @protocols = @protocols.split(/\s*,\s*/) if String === @protocols
53
-
53
+
54
54
  @ping_callbacks = {}
55
55
  end
56
56
 
@@ -89,11 +89,11 @@ module Faye
89
89
  def create_handshake
90
90
  Handshake.new(@socket.uri, @protocols)
91
91
  end
92
-
92
+
93
93
  def open?
94
94
  true
95
95
  end
96
-
96
+
97
97
  def parse(data)
98
98
  @reader.put(data.bytes.to_a)
99
99
  buffer = true
@@ -178,7 +178,7 @@ module Faye
178
178
 
179
179
  WebSocket.encode(frame)
180
180
  end
181
-
181
+
182
182
  def ping(message = '', &callback)
183
183
  @ping_callbacks[message] = callback if callback
184
184
  @socket.send(message, :ping)
@@ -1,8 +1,8 @@
1
1
  module Faye
2
2
  class WebSocket
3
-
3
+
4
4
  # http://www.w3.org/International/questions/qa-forms-utf-8.en.php
5
5
  UTF8_MATCH = /^([\x00-\x7F]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/
6
-
6
+
7
7
  end
8
8
  end
@@ -9,15 +9,15 @@ WebSocketSteps = EM::RSpec.async_steps do
9
9
  @port = port
10
10
  EM.add_timer(0.1, &callback)
11
11
  end
12
-
12
+
13
13
  def stop(&callback)
14
14
  @server.stop
15
15
  EM.next_tick(&callback)
16
16
  end
17
-
17
+
18
18
  def open_socket(url, protocols, &callback)
19
19
  done = false
20
-
20
+
21
21
  resume = lambda do |open|
22
22
  unless done
23
23
  done = true
@@ -25,13 +25,13 @@ WebSocketSteps = EM::RSpec.async_steps do
25
25
  callback.call
26
26
  end
27
27
  end
28
-
28
+
29
29
  @ws = Faye::WebSocket::Client.new(url, protocols)
30
-
30
+
31
31
  @ws.onopen = lambda { |e| resume.call(true) }
32
32
  @ws.onclose = lambda { |e| resume.call(false) }
33
33
  end
34
-
34
+
35
35
  def close_socket(&callback)
36
36
  @ws.onclose = lambda do |e|
37
37
  @open = false
@@ -39,37 +39,37 @@ WebSocketSteps = EM::RSpec.async_steps do
39
39
  end
40
40
  @ws.close
41
41
  end
42
-
42
+
43
43
  def check_open(&callback)
44
44
  @open.should == true
45
45
  callback.call
46
46
  end
47
-
47
+
48
48
  def check_closed(&callback)
49
49
  @open.should == false
50
50
  callback.call
51
51
  end
52
-
52
+
53
53
  def check_protocol(protocol, &callback)
54
54
  @ws.protocol.should == protocol
55
55
  callback.call
56
56
  end
57
-
57
+
58
58
  def listen_for_message(&callback)
59
59
  @ws.add_event_listener('message', lambda { |e| @message = e.data })
60
60
  callback.call
61
61
  end
62
-
62
+
63
63
  def send_message(message, &callback)
64
64
  @ws.send(message)
65
65
  EM.add_timer(0.1, &callback)
66
66
  end
67
-
67
+
68
68
  def check_response(message, &callback)
69
69
  @message.should == message
70
70
  callback.call
71
71
  end
72
-
72
+
73
73
  def check_no_response(&callback)
74
74
  @message.should == nil
75
75
  callback.call
@@ -79,61 +79,56 @@ end
79
79
  describe Faye::WebSocket::Client do
80
80
  next if Faye::WebSocket.jruby?
81
81
  include WebSocketSteps
82
-
82
+
83
83
  let(:protocols) { ["foo", "echo"] }
84
84
  let(:plain_text_url) { "ws://0.0.0.0:8000/" }
85
85
  let(:secure_url) { "wss://0.0.0.0:8000/" }
86
-
87
- before do
88
- Thread.new { EM.run }
89
- sleep(0.1) until EM.reactor_running?
90
- end
91
-
86
+
92
87
  shared_examples_for "socket client" do
93
88
  it "can open a connection" do
94
89
  open_socket(socket_url, protocols)
95
90
  check_open
96
91
  check_protocol("echo")
97
92
  end
98
-
93
+
99
94
  it "cannot open a connection to the wrong host" do
100
95
  open_socket(blocked_url, protocols)
101
96
  check_closed
102
97
  end
103
-
98
+
104
99
  it "cannot open a connection with unacceptable protocols" do
105
100
  open_socket(socket_url, ["foo"])
106
101
  check_closed
107
102
  end
108
-
103
+
109
104
  it "can close the connection" do
110
105
  open_socket(socket_url, protocols)
111
106
  close_socket
112
107
  check_closed
113
108
  end
114
-
109
+
115
110
  describe "in the OPEN state" do
116
111
  before { open_socket(socket_url, protocols) }
117
-
112
+
118
113
  it "can send and receive messages" do
119
114
  listen_for_message
120
115
  send_message "I expect this to be echoed"
121
116
  check_response "I expect this to be echoed"
122
117
  end
123
-
118
+
124
119
  it "sends numbers as strings" do
125
120
  listen_for_message
126
121
  send_message 13
127
122
  check_response "13"
128
123
  end
129
124
  end
130
-
125
+
131
126
  describe "in the CLOSED state" do
132
127
  before do
133
128
  open_socket(socket_url, protocols)
134
129
  close_socket
135
130
  end
136
-
131
+
137
132
  it "cannot send and receive messages" do
138
133
  listen_for_message
139
134
  send_message "I expect this to be echoed"
@@ -141,38 +136,26 @@ describe Faye::WebSocket::Client do
141
136
  end
142
137
  end
143
138
  end
144
-
139
+
145
140
  describe "with a plain-text Thin server" do
146
141
  let(:socket_url) { plain_text_url }
147
142
  let(:blocked_url) { secure_url }
148
-
143
+
149
144
  before { server 8000, :thin, false }
150
- after { sync ; stop }
151
-
152
- it_should_behave_like "socket client"
153
- end
154
-
155
- describe "with a plain-text Rainbows server" do
156
- next if Faye::WebSocket.rbx?
157
-
158
- let(:socket_url) { plain_text_url }
159
- let(:blocked_url) { secure_url }
160
-
161
- before { server 8000, :rainbows, false }
162
- after { sync ; stop }
163
-
145
+ after { stop }
146
+
164
147
  it_should_behave_like "socket client"
165
148
  end
166
-
149
+
167
150
  describe "with a secure Thin server" do
168
151
  next if Faye::WebSocket.rbx?
169
-
152
+
170
153
  let(:socket_url) { secure_url }
171
154
  let(:blocked_url) { plain_text_url }
172
-
155
+
173
156
  before { server 8000, :thin, true }
174
- after { sync ; stop }
175
-
157
+ after { stop }
158
+
176
159
  it_should_behave_like "socket client"
177
160
  end
178
161
  end
@@ -7,38 +7,38 @@ shared_examples_for "draft-75 parser" do
7
7
  @web_socket.should_receive(:receive).with("Hello")
8
8
  parse [0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff]
9
9
  end
10
-
10
+
11
11
  it "parses multiple frames from the same packet" do
12
12
  @web_socket.should_receive(:receive).with("Hello").exactly(2)
13
13
  parse [0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff, 0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff]
14
14
  end
15
-
15
+
16
16
  it "parses text frames beginning 0x00-0x7F" do
17
17
  @web_socket.should_receive(:receive).with("Hello")
18
18
  parse [0x66, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff]
19
19
  end
20
-
20
+
21
21
  it "ignores frames with a length header" do
22
22
  @web_socket.should_not_receive(:receive)
23
23
  parse [0x80, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f]
24
24
  end
25
-
25
+
26
26
  it "parses text following an ignored block" do
27
27
  @web_socket.should_receive(:receive).with("Hello")
28
28
  parse [0x80, 0x02, 0x48, 0x65, 0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff]
29
29
  end
30
-
30
+
31
31
  it "parses multibyte text frames" do
32
32
  @web_socket.should_receive(:receive).with(encode "Apple = ")
33
33
  parse [0x00, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf, 0xff]
34
34
  end
35
-
35
+
36
36
  it "parses frames received in several packets" do
37
37
  @web_socket.should_receive(:receive).with(encode "Apple = ")
38
38
  parse [0x00, 0x41, 0x70, 0x70, 0x6c, 0x65]
39
39
  parse [0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf, 0xff]
40
40
  end
41
-
41
+
42
42
  it "parses fragmented frames" do
43
43
  @web_socket.should_receive(:receive).with("Hello")
44
44
  parse [0x00, 0x48, 0x65, 0x6c]
@@ -4,21 +4,21 @@ require "spec_helper"
4
4
 
5
5
  describe Faye::WebSocket::Draft75Parser do
6
6
  include EncodingHelper
7
-
7
+
8
8
  before do
9
9
  @web_socket = mock Faye::WebSocket
10
10
  @parser = Faye::WebSocket::Draft75Parser.new(@web_socket)
11
11
  end
12
-
12
+
13
13
  describe :parse do
14
14
  it_should_behave_like "draft-75 parser"
15
15
  end
16
-
16
+
17
17
  describe :frame do
18
18
  it "returns the given string formatted as a WebSocket frame" do
19
19
  bytes(@parser.frame "Hello").should == [0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff]
20
20
  end
21
-
21
+
22
22
  it "encodes multibyte characters correctly" do
23
23
  message = encode "Apple = "
24
24
  bytes(@parser.frame message).should == [0x00, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf, 0xff]
@@ -4,27 +4,27 @@ require "spec_helper"
4
4
 
5
5
  describe Faye::WebSocket::Draft76Parser do
6
6
  include EncodingHelper
7
-
7
+
8
8
  before do
9
9
  @web_socket = mock Faye::WebSocket
10
10
  @parser = Faye::WebSocket::Draft76Parser.new(@web_socket)
11
11
  @parser.instance_eval { @handshake_complete = true }
12
12
  end
13
-
13
+
14
14
  describe :parse do
15
15
  it_should_behave_like "draft-75 parser"
16
-
16
+
17
17
  it "closes the socket if a close frame is received" do
18
18
  @web_socket.should_receive(:close)
19
19
  parse [0xFF, 0x00]
20
20
  end
21
21
  end
22
-
22
+
23
23
  describe :frame do
24
24
  it "returns the given string formatted as a WebSocket frame" do
25
25
  bytes(@parser.frame "Hello").should == [0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0xff]
26
26
  end
27
-
27
+
28
28
  it "encodes multibyte characters correctly" do
29
29
  message = encode "Apple = "
30
30
  bytes(@parser.frame message).should == [0x00, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0xef, 0xa3, 0xbf, 0xff]
@@ -18,11 +18,11 @@ module EncodingHelper
18
18
  message.force_encoding("UTF-8") :
19
19
  message
20
20
  end
21
-
21
+
22
22
  def bytes(string)
23
23
  string.bytes.to_a
24
24
  end
25
-
25
+
26
26
  def parse(bytes)
27
27
  @parser.parse(bytes.pack('C*'))
28
28
  end
@@ -36,7 +36,7 @@ class EchoServer
36
36
  end
37
37
  socket.rack_response
38
38
  end
39
-
39
+
40
40
  def listen(port, backend, ssl = false)
41
41
  case backend
42
42
  when :rainbows
@@ -60,7 +60,7 @@ class EchoServer
60
60
  end
61
61
  end
62
62
  end
63
-
63
+
64
64
  def stop
65
65
  @server.stop
66
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faye-websocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-09 00:00:00.000000000 Z
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.12.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: progressbar
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rack
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -64,17 +80,17 @@ dependencies:
64
80
  requirement: !ruby/object:Gem::Requirement
65
81
  none: false
66
82
  requirements:
67
- - - ~>
83
+ - - ! '>='
68
84
  - !ruby/object:Gem::Version
69
- version: 2.8.0
85
+ version: '0'
70
86
  type: :development
71
87
  prerelease: false
72
88
  version_requirements: !ruby/object:Gem::Requirement
73
89
  none: false
74
90
  requirements:
75
- - - ~>
91
+ - - ! '>='
76
92
  - !ruby/object:Gem::Version
77
- version: 2.8.0
93
+ version: '0'
78
94
  - !ruby/object:Gem::Dependency
79
95
  name: rainbows
80
96
  requirement: !ruby/object:Gem::Requirement