faye 0.7.2 → 0.8.0
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.
- data/History.txt +15 -3
- data/README.rdoc +2 -6
- data/lib/faye-browser-min.js +1 -1
- data/lib/faye.rb +25 -36
- data/lib/faye/adapters/rack_adapter.rb +43 -22
- data/lib/faye/engines/connection.rb +7 -10
- data/lib/faye/engines/memory.rb +28 -28
- data/lib/faye/engines/proxy.rb +109 -0
- data/lib/faye/mixins/logging.rb +1 -8
- data/lib/faye/mixins/timeouts.rb +1 -1
- data/lib/faye/protocol/channel.rb +3 -3
- data/lib/faye/protocol/client.rb +50 -45
- data/lib/faye/protocol/extensible.rb +11 -18
- data/lib/faye/protocol/server.rb +53 -38
- data/lib/faye/transport/http.rb +49 -27
- data/lib/faye/transport/transport.rb +3 -1
- data/lib/faye/transport/web_socket.rb +6 -10
- data/lib/faye/util/namespace.rb +2 -2
- data/spec/browser.html +3 -1
- data/spec/encoding_helper.rb +7 -0
- data/spec/javascript/client_spec.js +0 -5
- data/spec/javascript/engine/memory_spec.js +7 -0
- data/spec/javascript/engine_spec.js +22 -57
- data/spec/javascript/server/handshake_spec.js +10 -6
- data/spec/javascript/server/integration_spec.js +11 -10
- data/spec/javascript/server/publish_spec.js +85 -0
- data/spec/javascript/server_spec.js +5 -51
- data/spec/node.js +6 -6
- data/spec/ruby/client_spec.rb +1 -1
- data/spec/ruby/engine/memory_spec.rb +7 -0
- data/spec/ruby/{engine_spec.rb → engine_examples.rb} +28 -34
- data/spec/ruby/rack_adapter_spec.rb +1 -1
- data/spec/ruby/server/handshake_spec.rb +10 -6
- data/spec/ruby/server/publish_spec.rb +81 -0
- data/spec/ruby/server_spec.rb +6 -44
- data/spec/spec_helper.rb +5 -18
- data/spec/testswarm +1 -5
- metadata +105 -180
- data/lib/faye/engines/base.rb +0 -66
- data/lib/faye/engines/redis.rb +0 -225
- data/lib/faye/thin_extensions.rb +0 -75
- data/lib/faye/util/web_socket.rb +0 -89
- data/lib/faye/util/web_socket/api.rb +0 -103
- data/lib/faye/util/web_socket/client.rb +0 -82
- data/lib/faye/util/web_socket/draft75_parser.rb +0 -53
- data/lib/faye/util/web_socket/draft76_parser.rb +0 -53
- data/lib/faye/util/web_socket/protocol8_parser.rb +0 -324
- data/spec/javascript/web_socket/client_spec.js +0 -121
- data/spec/javascript/web_socket/draft75parser_spec.js +0 -39
- data/spec/javascript/web_socket/protocol8parser_spec.js +0 -153
- data/spec/redis.conf +0 -42
- data/spec/ruby/web_socket/client_spec.rb +0 -126
- data/spec/ruby/web_socket/draft75_parser_spec.rb +0 -41
- data/spec/ruby/web_socket/protocol8_parser_spec.rb +0 -145
@@ -27,16 +27,13 @@ JS.ENV.ServerSpec = JS.Test.describe("Server", function() { with(this) {
|
|
27
27
|
it("ignores invalid messages", function() { with(this) {
|
28
28
|
var response = null
|
29
29
|
server.process([{}, {channel: "invalid"}], false, function(r) { response = r})
|
30
|
-
assertEqual( [], response )
|
31
|
-
}})
|
32
|
-
|
33
|
-
it("rejects unknown meta channels", function() { with(this) {
|
34
|
-
var response = null
|
35
|
-
server.process([{channel: "/meta/p"}], false, function(r) { response = r })
|
36
30
|
assertEqual([
|
37
|
-
{
|
31
|
+
{ successful: false,
|
32
|
+
error: "405::Invalid channel"
|
33
|
+
},
|
34
|
+
{ channel: "invalid",
|
38
35
|
successful: false,
|
39
|
-
error: "
|
36
|
+
error: "405:invalid:Invalid channel"
|
40
37
|
}
|
41
38
|
], response)
|
42
39
|
}})
|
@@ -64,49 +61,6 @@ JS.ENV.ServerSpec = JS.Test.describe("Server", function() { with(this) {
|
|
64
61
|
server.process([handshake, connect, disconnect, subscribe, unsubscribe, publish], false, function() {})
|
65
62
|
}})
|
66
63
|
|
67
|
-
describe("publishing a message", function() { with(this) {
|
68
|
-
it("tells the engine to publish the message", function() { with(this) {
|
69
|
-
expect(engine, "publish").given(publish)
|
70
|
-
server.process(publish, false, function() {})
|
71
|
-
}})
|
72
|
-
|
73
|
-
it("returns no response", function() { with(this) {
|
74
|
-
stub(engine, "publish")
|
75
|
-
server.process(publish, false, function(response) {
|
76
|
-
assertEqual( [], response)
|
77
|
-
})
|
78
|
-
}})
|
79
|
-
|
80
|
-
describe("with an error", function() { with(this) {
|
81
|
-
before(function() { with(this) {
|
82
|
-
publish.error = "invalid"
|
83
|
-
}})
|
84
|
-
|
85
|
-
it("does not tell the engine to publish the message", function() { with(this) {
|
86
|
-
expect(engine, "publish").exactly(0)
|
87
|
-
server.process(publish, false, function() {})
|
88
|
-
}})
|
89
|
-
|
90
|
-
it("returns no response", function() { with(this) {
|
91
|
-
stub(engine, "publish")
|
92
|
-
server.process(publish, false, function(response) {
|
93
|
-
assertEqual( [], response)
|
94
|
-
})
|
95
|
-
}})
|
96
|
-
}})
|
97
|
-
|
98
|
-
describe("to an invalid channel", function() { with(this) {
|
99
|
-
before(function() { with(this) {
|
100
|
-
publish.channel = "/invalid/*"
|
101
|
-
}})
|
102
|
-
|
103
|
-
it("does not tell the engine to publish the message", function() { with(this) {
|
104
|
-
expect(engine, "publish").exactly(0)
|
105
|
-
server.process(publish, false, function() {})
|
106
|
-
}})
|
107
|
-
}})
|
108
|
-
}})
|
109
|
-
|
110
64
|
describe("handshaking", function() { with(this) {
|
111
65
|
before(function() { with(this) {
|
112
66
|
expect(server, "handshake").given(handshake, false).yielding([{channel: "/meta/handshake", successful: true}])
|
data/spec/node.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
2
|
-
require('../
|
1
|
+
require('jsclass')
|
2
|
+
Faye = require('../build/faye-node')
|
3
|
+
Faye.logger = function() {}
|
3
4
|
|
4
5
|
JS.Packages(function() { with(this) {
|
5
|
-
file('build/faye-node.js').provides('Faye')
|
6
6
|
autoload(/.*Spec/, {from: 'spec/javascript'})
|
7
7
|
}})
|
8
8
|
|
@@ -30,23 +30,23 @@ JS.require('Faye', 'JS.Test', 'JS.Range', function() {
|
|
30
30
|
}
|
31
31
|
})
|
32
32
|
|
33
|
+
JS.ENV.Engine = {}
|
33
34
|
JS.ENV.Server = {}
|
34
35
|
|
35
36
|
JS.require( 'FayeSpec',
|
36
37
|
'GrammarSpec',
|
37
38
|
'ChannelSpec',
|
38
39
|
'EngineSpec',
|
40
|
+
'Engine.MemorySpec',
|
39
41
|
'ServerSpec',
|
40
42
|
'Server.HandshakeSpec',
|
41
43
|
'Server.ConnectSpec',
|
42
44
|
'Server.DisconnectSpec',
|
43
45
|
'Server.SubscribeSpec',
|
44
46
|
'Server.UnsubscribeSpec',
|
47
|
+
'Server.PublishSpec',
|
45
48
|
'Server.ExtensionsSpec',
|
46
49
|
'Server.IntegrationSpec',
|
47
|
-
'WebSocket.ClientSpec',
|
48
|
-
'WebSocket.Draft75ParserSpec',
|
49
|
-
'WebSocket.Protocol8ParserSpec',
|
50
50
|
'NodeAdapterSpec',
|
51
51
|
'ClientSpec',
|
52
52
|
'TransportSpec',
|
data/spec/ruby/client_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Faye::Client do
|
4
4
|
let :transport do
|
5
|
-
transport = mock("transport")
|
5
|
+
transport = mock("transport", :cookies= => nil, :headers= => nil)
|
6
6
|
transport.stub(:connection_type).and_return "fake"
|
7
7
|
transport.stub(:send)
|
8
8
|
transport.extend(Faye::Publisher)
|
@@ -1,6 +1,17 @@
|
|
1
1
|
# encoding=utf-8
|
2
2
|
|
3
|
-
|
3
|
+
root = File.expand_path('../../..', __FILE__)
|
4
|
+
|
5
|
+
require root + '/vendor/em-rspec/lib/em-rspec'
|
6
|
+
require root + '/spec/encoding_helper'
|
7
|
+
|
8
|
+
require root + '/lib/faye/mixins/logging'
|
9
|
+
require root + '/lib/faye/mixins/publisher'
|
10
|
+
require root + '/lib/faye/mixins/timeouts'
|
11
|
+
|
12
|
+
require root + '/lib/faye/protocol/channel'
|
13
|
+
require root + '/lib/faye/protocol/grammar'
|
14
|
+
require root + '/lib/faye/engines/proxy'
|
4
15
|
|
5
16
|
EngineSteps = EM::RSpec.async_steps do
|
6
17
|
def create_client(name, &resume)
|
@@ -57,14 +68,14 @@ EngineSteps = EM::RSpec.async_steps do
|
|
57
68
|
def publish(messages, &resume)
|
58
69
|
messages = [messages].flatten
|
59
70
|
messages.each do |message|
|
60
|
-
message = {"id" => Faye.random}.merge(message)
|
71
|
+
message = {"id" => Faye::Engine.random}.merge(message)
|
61
72
|
engine.publish(message)
|
62
73
|
end
|
63
74
|
EM.add_timer(0.01, &resume)
|
64
75
|
end
|
65
76
|
|
66
77
|
def publish_by(name, message, &resume)
|
67
|
-
message = {"clientId" => @clients[name], "id" => Faye.random}.merge(message)
|
78
|
+
message = {"clientId" => @clients[name], "id" => Faye::Engine.random}.merge(message)
|
68
79
|
engine.publish(message)
|
69
80
|
EM.add_timer(0.01, &resume)
|
70
81
|
end
|
@@ -109,28 +120,24 @@ EngineSteps = EM::RSpec.async_steps do
|
|
109
120
|
@inboxes[a].first.should_not be_equal(@inboxes[b].first)
|
110
121
|
resume.call
|
111
122
|
end
|
112
|
-
|
113
|
-
def clean_redis_db(&resume)
|
114
|
-
engine.disconnect
|
115
|
-
redis = EM::Hiredis::Client.connect
|
116
|
-
redis.flushall(&resume)
|
117
|
-
end
|
118
123
|
end
|
119
124
|
|
120
125
|
describe "Pub/sub engines" do
|
121
|
-
def create_engine
|
122
|
-
engine_klass.new(options.merge(engine_opts))
|
123
|
-
end
|
124
|
-
|
125
126
|
shared_examples_for "faye engine" do
|
126
127
|
include EncodingHelper
|
127
128
|
include EngineSteps
|
128
129
|
|
130
|
+
def create_engine
|
131
|
+
opts = options.merge(engine_opts)
|
132
|
+
Faye::Engine::Proxy.new(opts)
|
133
|
+
end
|
134
|
+
|
129
135
|
let(:options) { {:timeout => 1} }
|
130
136
|
let(:engine) { create_engine }
|
131
137
|
|
132
138
|
before do
|
133
|
-
Faye.
|
139
|
+
Faye.stub(:logger)
|
140
|
+
Faye::Engine.ensure_reactor_running!
|
134
141
|
create_client :alice
|
135
142
|
create_client :bob
|
136
143
|
create_client :carol
|
@@ -382,6 +389,11 @@ describe "Pub/sub engines" do
|
|
382
389
|
shared_examples_for "distributed engine" do
|
383
390
|
include EngineSteps
|
384
391
|
|
392
|
+
def create_engine
|
393
|
+
opts = options.merge(engine_opts)
|
394
|
+
Faye::Engine::Proxy.new(opts)
|
395
|
+
end
|
396
|
+
|
385
397
|
let(:options) { {} }
|
386
398
|
let(:left) { create_engine }
|
387
399
|
let(:right) { create_engine }
|
@@ -389,7 +401,8 @@ describe "Pub/sub engines" do
|
|
389
401
|
alias :engine :left
|
390
402
|
|
391
403
|
before do
|
392
|
-
Faye.
|
404
|
+
Faye.stub(:logger)
|
405
|
+
Faye::Engine.ensure_reactor_running!
|
393
406
|
create_client :alice
|
394
407
|
create_client :bob
|
395
408
|
|
@@ -410,24 +423,5 @@ describe "Pub/sub engines" do
|
|
410
423
|
end
|
411
424
|
end
|
412
425
|
end
|
413
|
-
|
414
|
-
describe Faye::Engine::Memory do
|
415
|
-
let(:engine_klass) { Faye::Engine::Memory }
|
416
|
-
let(:engine_opts) { {} }
|
417
|
-
it_should_behave_like "faye engine"
|
418
|
-
end
|
419
|
-
|
420
|
-
describe Faye::Engine::Redis do
|
421
|
-
let(:engine_klass) { Faye::Engine::Redis }
|
422
|
-
let(:engine_opts) { {:password => "foobared", :namespace => Time.now.to_i.to_s} }
|
423
|
-
after { clean_redis_db }
|
424
|
-
it_should_behave_like "faye engine"
|
425
|
-
it_should_behave_like "distributed engine"
|
426
|
-
|
427
|
-
describe "using a Unix socket" do
|
428
|
-
before { engine_opts[:socket] = "/tmp/redis.sock" }
|
429
|
-
it_should_behave_like "faye engine"
|
430
|
-
end
|
431
|
-
end
|
432
426
|
end
|
433
427
|
|
@@ -13,7 +13,7 @@ describe Faye::RackAdapter do
|
|
13
13
|
let(:content_type) { last_response["Content-Type"] }
|
14
14
|
let(:cache_control) { last_response["Cache-Control"] }
|
15
15
|
let(:access_control_origin) { last_response["Access-Control-Allow-Origin"] }
|
16
|
-
let(:json) {
|
16
|
+
let(:json) { Yajl::Parser.parse(body) }
|
17
17
|
let(:body) { last_response.body }
|
18
18
|
let(:status) { last_response.status.to_i }
|
19
19
|
|
@@ -4,6 +4,10 @@ describe "server handshake" do
|
|
4
4
|
let(:engine) { mock "engine" }
|
5
5
|
let(:server) { Faye::Server.new }
|
6
6
|
|
7
|
+
let :connection_types do
|
8
|
+
["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"]
|
9
|
+
end
|
10
|
+
|
7
11
|
before do
|
8
12
|
Faye::Engine.stub(:get).and_return engine
|
9
13
|
end
|
@@ -27,7 +31,7 @@ describe "server handshake" do
|
|
27
31
|
"channel" => "/meta/handshake",
|
28
32
|
"successful" => true,
|
29
33
|
"version" => "1.0",
|
30
|
-
"supportedConnectionTypes" =>
|
34
|
+
"supportedConnectionTypes" => connection_types,
|
31
35
|
"clientId" => "clientid"
|
32
36
|
}
|
33
37
|
end
|
@@ -43,7 +47,7 @@ describe "server handshake" do
|
|
43
47
|
"channel" => "/meta/handshake",
|
44
48
|
"successful" => true,
|
45
49
|
"version" => "1.0",
|
46
|
-
"supportedConnectionTypes" =>
|
50
|
+
"supportedConnectionTypes" => connection_types,
|
47
51
|
"clientId" => "clientid",
|
48
52
|
"id" => "foo"
|
49
53
|
}
|
@@ -67,7 +71,7 @@ describe "server handshake" do
|
|
67
71
|
"successful" => false,
|
68
72
|
"error" => "402:version:Missing required parameter",
|
69
73
|
"version" => "1.0",
|
70
|
-
"supportedConnectionTypes" =>
|
74
|
+
"supportedConnectionTypes" => connection_types
|
71
75
|
}
|
72
76
|
end
|
73
77
|
end
|
@@ -88,7 +92,7 @@ describe "server handshake" do
|
|
88
92
|
"successful" => false,
|
89
93
|
"error" => "402:supportedConnectionTypes:Missing required parameter",
|
90
94
|
"version" => "1.0",
|
91
|
-
"supportedConnectionTypes" =>
|
95
|
+
"supportedConnectionTypes" => connection_types
|
92
96
|
}
|
93
97
|
end
|
94
98
|
end
|
@@ -109,7 +113,7 @@ describe "server handshake" do
|
|
109
113
|
"successful" => false,
|
110
114
|
"error" => "301:iframe,flash:Connection types not supported",
|
111
115
|
"version" => "1.0",
|
112
|
-
"supportedConnectionTypes" =>
|
116
|
+
"supportedConnectionTypes" => connection_types
|
113
117
|
}
|
114
118
|
end
|
115
119
|
end
|
@@ -130,7 +134,7 @@ describe "server handshake" do
|
|
130
134
|
"successful" => false,
|
131
135
|
"error" => "invalid",
|
132
136
|
"version" => "1.0",
|
133
|
-
"supportedConnectionTypes" =>
|
137
|
+
"supportedConnectionTypes" => connection_types
|
134
138
|
}
|
135
139
|
end
|
136
140
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "server publish" do
|
4
|
+
let(:engine) { mock "engine" }
|
5
|
+
let(:server) { Faye::Server.new }
|
6
|
+
let(:message) {{ "channel" => "/some/channel", "data" => "publish" }}
|
7
|
+
|
8
|
+
before do
|
9
|
+
Faye::Engine.stub(:get).and_return engine
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "publishing a message" do
|
13
|
+
it "tells the engine to publish the message" do
|
14
|
+
engine.should_receive(:publish).with(message)
|
15
|
+
server.process(message, false) {}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns a successful response" do
|
19
|
+
engine.stub(:publish)
|
20
|
+
server.process(message, false) do |response|
|
21
|
+
response.should == [
|
22
|
+
{ "channel" => "/some/channel",
|
23
|
+
"successful" => true
|
24
|
+
}
|
25
|
+
]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "with an invalid channel" do
|
30
|
+
before { message["channel"] = "channel" }
|
31
|
+
|
32
|
+
it "does not tell the engine to publish the message" do
|
33
|
+
engine.should_not_receive(:publish)
|
34
|
+
server.process(message, false) {}
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns an unsuccessful response" do
|
38
|
+
engine.stub(:publish)
|
39
|
+
server.process(message, false) do |response|
|
40
|
+
response.should == [
|
41
|
+
{ "channel" => "channel",
|
42
|
+
"successful" => false,
|
43
|
+
"error" => "405:channel:Invalid channel"
|
44
|
+
}
|
45
|
+
]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "with an error" do
|
51
|
+
before { message["error"] = "invalid" }
|
52
|
+
|
53
|
+
it "does not tell the engine to publish the message" do
|
54
|
+
engine.should_not_receive(:publish)
|
55
|
+
server.process(message, false) {}
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns an unsuccessful response" do
|
59
|
+
engine.stub(:publish)
|
60
|
+
server.process(message, false) do |response|
|
61
|
+
response.should == [
|
62
|
+
{ "channel" => "/some/channel",
|
63
|
+
"successful" => false,
|
64
|
+
"error" => "invalid"
|
65
|
+
}
|
66
|
+
]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "to an invalid channel" do
|
72
|
+
before { message["channel"] = "/invalid/*" }
|
73
|
+
|
74
|
+
it "does not tell the engine to publish the message" do
|
75
|
+
engine.should_not_receive(:publish)
|
76
|
+
server.process(message, false) {}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
data/spec/ruby/server_spec.rb
CHANGED
@@ -30,23 +30,20 @@ describe Faye::Server do
|
|
30
30
|
it "ignores invalid messages" do
|
31
31
|
response = nil
|
32
32
|
server.process([{}, {"channel" => "invalid"}], false) { |r| response = r }
|
33
|
-
response.should == []
|
34
|
-
end
|
35
|
-
|
36
|
-
it "rejects unknown meta channels" do
|
37
|
-
response = nil
|
38
|
-
server.process([{"channel" => "/meta/p"}], false) { |r| response = r }
|
39
33
|
response.should == [
|
40
|
-
{ "
|
34
|
+
{ "successful" => false,
|
35
|
+
"error" => "405::Invalid channel"
|
36
|
+
},
|
37
|
+
{ "channel" => "invalid",
|
41
38
|
"successful" => false,
|
42
|
-
"error" =>
|
39
|
+
"error" =>"405:invalid:Invalid channel"
|
43
40
|
}
|
44
41
|
]
|
45
42
|
end
|
46
43
|
|
47
44
|
it "routes single messages to appropriate handlers" do
|
48
45
|
server.should_receive(:handshake).with(handshake, false)
|
49
|
-
server.process(handshake, false)
|
46
|
+
server.process(handshake, false)
|
50
47
|
end
|
51
48
|
|
52
49
|
it "routes a list of messages to appropriate handlers" do
|
@@ -66,41 +63,6 @@ describe Faye::Server do
|
|
66
63
|
server.process([handshake, connect, disconnect, subscribe, unsubscribe, publish], false)
|
67
64
|
end
|
68
65
|
|
69
|
-
describe "publishing a message" do
|
70
|
-
it "tells the engine to publish the message" do
|
71
|
-
engine.should_receive(:publish).with(publish)
|
72
|
-
server.process(publish, false) {}
|
73
|
-
end
|
74
|
-
|
75
|
-
it "returns no response" do
|
76
|
-
engine.stub(:publish)
|
77
|
-
server.process(publish, false) { |r| r.should == [] }
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "with an error" do
|
81
|
-
before { publish["error"] = "invalid" }
|
82
|
-
|
83
|
-
it "does not tell the engine to publish the message" do
|
84
|
-
engine.should_not_receive(:publish)
|
85
|
-
server.process(publish, false) {}
|
86
|
-
end
|
87
|
-
|
88
|
-
it "returns no response" do
|
89
|
-
engine.stub(:publish)
|
90
|
-
server.process(publish, false) { |r| r.should == [] }
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "to an invalid channel" do
|
95
|
-
before { publish["channel"] = "/invalid/*" }
|
96
|
-
|
97
|
-
it "does not tell the engine to publish the message" do
|
98
|
-
engine.should_not_receive(:publish)
|
99
|
-
server.process(publish, false) {}
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
66
|
describe "handshaking" do
|
105
67
|
before do
|
106
68
|
response = {"channel" => "/meta/handshake", "successful" => true}
|