faye 0.5.5 → 0.6.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 +14 -0
- data/README.rdoc +98 -0
- data/Rakefile +17 -15
- data/lib/faye-browser-min.js +1 -1
- data/lib/faye.rb +14 -5
- data/lib/faye/adapters/rack_adapter.rb +12 -5
- data/lib/faye/engines/base.rb +62 -0
- data/lib/faye/engines/connection.rb +63 -0
- data/lib/faye/engines/memory.rb +89 -0
- data/lib/faye/engines/redis.rb +141 -0
- data/lib/faye/error.rb +16 -4
- data/lib/faye/mixins/publisher.rb +6 -0
- data/lib/faye/protocol/channel.rb +34 -86
- data/lib/faye/protocol/client.rb +36 -52
- data/lib/faye/protocol/extensible.rb +3 -0
- data/lib/faye/protocol/server.rb +119 -169
- data/lib/faye/transport/http.rb +45 -0
- data/lib/faye/transport/local.rb +15 -0
- data/lib/faye/{network → transport}/transport.rb +36 -49
- data/spec/browser.html +35 -0
- data/spec/install.sh +48 -0
- data/spec/javascript/channel_spec.js +15 -0
- data/spec/javascript/client_spec.js +610 -0
- data/spec/javascript/engine_spec.js +319 -0
- data/spec/javascript/faye_spec.js +15 -0
- data/spec/javascript/grammar_spec.js +66 -0
- data/spec/javascript/node_adapter_spec.js +276 -0
- data/spec/javascript/server/connect_spec.js +168 -0
- data/spec/javascript/server/disconnect_spec.js +121 -0
- data/spec/javascript/server/extensions_spec.js +60 -0
- data/spec/javascript/server/handshake_spec.js +153 -0
- data/spec/javascript/server/subscribe_spec.js +245 -0
- data/spec/javascript/server/unsubscribe_spec.js +245 -0
- data/spec/javascript/server_spec.js +146 -0
- data/spec/javascript/transport_spec.js +130 -0
- data/spec/node.js +34 -0
- data/spec/ruby/channel_spec.rb +17 -0
- data/spec/ruby/client_spec.rb +615 -0
- data/spec/ruby/engine_spec.rb +312 -0
- data/spec/ruby/faye_spec.rb +14 -0
- data/spec/ruby/grammar_spec.rb +68 -0
- data/spec/ruby/rack_adapter_spec.rb +209 -0
- data/spec/ruby/server/connect_spec.rb +170 -0
- data/spec/ruby/server/disconnect_spec.rb +120 -0
- data/spec/ruby/server/extensions_spec.rb +69 -0
- data/spec/ruby/server/handshake_spec.rb +151 -0
- data/spec/ruby/server/subscribe_spec.rb +247 -0
- data/spec/ruby/server/unsubscribe_spec.rb +247 -0
- data/spec/ruby/server_spec.rb +138 -0
- data/spec/ruby/transport_spec.rb +128 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/testswarm.pl +200 -0
- data/spec/thin_proxy.rb +36 -0
- metadata +119 -84
- data/Manifest.txt +0 -27
- data/README.txt +0 -98
- data/lib/faye/protocol/connection.rb +0 -111
- data/test/scenario.rb +0 -172
- data/test/test_channel.rb +0 -54
- data/test/test_clients.rb +0 -381
- data/test/test_grammar.rb +0 -86
- data/test/test_server.rb +0 -488
@@ -0,0 +1,247 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "server subscribe" do
|
4
|
+
let(:engine) { mock "engine" }
|
5
|
+
let(:server) { Faye::Server.new }
|
6
|
+
|
7
|
+
before do
|
8
|
+
Faye::Engine.stub(:get).and_return engine
|
9
|
+
end
|
10
|
+
|
11
|
+
describe :subscribe do
|
12
|
+
let(:client_id) { "fakeclientid" }
|
13
|
+
let(:message) {{"channel" => "/meta/subscribe",
|
14
|
+
"clientId" => "fakeclientid",
|
15
|
+
"subscription" => "/foo"
|
16
|
+
}}
|
17
|
+
|
18
|
+
describe "with valid parameters" do
|
19
|
+
before do
|
20
|
+
engine.should_receive(:client_exists).with(client_id).and_yield true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "subscribes the client to the channel" do
|
24
|
+
engine.should_receive(:subscribe).with(client_id, "/foo")
|
25
|
+
server.subscribe(message) {}
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns a successful response" do
|
29
|
+
engine.stub(:subscribe)
|
30
|
+
server.subscribe(message) do |response|
|
31
|
+
response.should == {
|
32
|
+
"channel" => "/meta/subscribe",
|
33
|
+
"successful" => true,
|
34
|
+
"clientId" => client_id,
|
35
|
+
"subscription" => "/foo"
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "with a list of subscriptions" do
|
41
|
+
before do
|
42
|
+
message["subscription"] = ["/foo", "/bar"]
|
43
|
+
end
|
44
|
+
|
45
|
+
it "creates multiple subscriptions" do
|
46
|
+
engine.should_receive(:subscribe).with(client_id, "/foo")
|
47
|
+
engine.should_receive(:subscribe).with(client_id, "/bar")
|
48
|
+
server.subscribe(message) {}
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns a successful response" do
|
52
|
+
engine.stub(:subscribe)
|
53
|
+
server.subscribe(message) do |response|
|
54
|
+
response.should == {
|
55
|
+
"channel" => "/meta/subscribe",
|
56
|
+
"successful" => true,
|
57
|
+
"clientId" => client_id,
|
58
|
+
"subscription" => ["/foo", "/bar"]
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "with a subscription pattern" do
|
65
|
+
before do
|
66
|
+
message["subscription"] = "/foo/**"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "subscribes the client to the channel pattern" do
|
70
|
+
engine.should_receive(:subscribe).with(client_id, "/foo/**")
|
71
|
+
server.subscribe(message) {}
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns a successful response" do
|
75
|
+
engine.stub(:subscribe)
|
76
|
+
server.subscribe(message) do |response|
|
77
|
+
response.should == {
|
78
|
+
"channel" => "/meta/subscribe",
|
79
|
+
"successful" => true,
|
80
|
+
"clientId" => client_id,
|
81
|
+
"subscription" => "/foo/**"
|
82
|
+
}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "with an unknown client" do
|
89
|
+
before do
|
90
|
+
engine.should_receive(:client_exists).with(client_id).and_yield false
|
91
|
+
end
|
92
|
+
|
93
|
+
it "does not subscribe the client to the channel" do
|
94
|
+
engine.should_not_receive(:subscribe)
|
95
|
+
server.subscribe(message) {}
|
96
|
+
end
|
97
|
+
|
98
|
+
it "returns an unsuccessful response" do
|
99
|
+
server.subscribe(message) do |response|
|
100
|
+
response.should == {
|
101
|
+
"channel" => "/meta/subscribe",
|
102
|
+
"successful" => false,
|
103
|
+
"error" => "401:fakeclientid:Unknown client",
|
104
|
+
"clientId" => client_id,
|
105
|
+
"subscription" => "/foo"
|
106
|
+
}
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "missing clientId" do
|
112
|
+
before do
|
113
|
+
message.delete("clientId")
|
114
|
+
engine.should_receive(:client_exists).with(nil).and_yield false
|
115
|
+
end
|
116
|
+
|
117
|
+
it "does not subscribe the client to the channel" do
|
118
|
+
engine.should_not_receive(:subscribe)
|
119
|
+
server.subscribe(message) {}
|
120
|
+
end
|
121
|
+
|
122
|
+
it "returns an unsuccessful response" do
|
123
|
+
server.subscribe(message) do |response|
|
124
|
+
response.should == {
|
125
|
+
"channel" => "/meta/subscribe",
|
126
|
+
"successful" => false,
|
127
|
+
"error" => "402:clientId:Missing required parameter",
|
128
|
+
"subscription" => "/foo"
|
129
|
+
}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "missing subscription" do
|
135
|
+
before do
|
136
|
+
message.delete("subscription")
|
137
|
+
engine.should_receive(:client_exists).with(client_id).and_yield true
|
138
|
+
end
|
139
|
+
|
140
|
+
it "does not subscribe the client to the channel" do
|
141
|
+
engine.should_not_receive(:subscribe)
|
142
|
+
server.subscribe(message) {}
|
143
|
+
end
|
144
|
+
|
145
|
+
it "returns an unsuccessful response" do
|
146
|
+
server.subscribe(message) do |response|
|
147
|
+
response.should == {
|
148
|
+
"channel" => "/meta/subscribe",
|
149
|
+
"successful" => false,
|
150
|
+
"error" => "402:subscription:Missing required parameter",
|
151
|
+
"clientId" => client_id,
|
152
|
+
"subscription" => []
|
153
|
+
}
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "with an invalid channel" do
|
159
|
+
before do
|
160
|
+
message["subscription"] = "foo"
|
161
|
+
engine.should_receive(:client_exists).with(client_id).and_yield true
|
162
|
+
end
|
163
|
+
|
164
|
+
it "does not subscribe the client to the channel" do
|
165
|
+
engine.should_not_receive(:subscribe)
|
166
|
+
server.subscribe(message) {}
|
167
|
+
end
|
168
|
+
|
169
|
+
it "returns an unsuccessful response" do
|
170
|
+
server.subscribe(message) do |response|
|
171
|
+
response.should == {
|
172
|
+
"channel" => "/meta/subscribe",
|
173
|
+
"successful" => false,
|
174
|
+
"error" => "405:foo:Invalid channel",
|
175
|
+
"clientId" => client_id,
|
176
|
+
"subscription" => "foo"
|
177
|
+
}
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "with a /meta/* channel" do
|
183
|
+
before do
|
184
|
+
message["subscription"] = "/meta/foo"
|
185
|
+
engine.should_receive(:client_exists).with(client_id).and_yield true
|
186
|
+
end
|
187
|
+
|
188
|
+
it "does not subscribe the client to the channel" do
|
189
|
+
engine.should_not_receive(:subscribe)
|
190
|
+
server.subscribe(message) {}
|
191
|
+
end
|
192
|
+
|
193
|
+
it "returns an unsuccessful response" do
|
194
|
+
server.subscribe(message) do |response|
|
195
|
+
response.should == {
|
196
|
+
"channel" => "/meta/subscribe",
|
197
|
+
"successful" => false,
|
198
|
+
"error" => "403:/meta/foo:Forbidden channel",
|
199
|
+
"clientId" => client_id,
|
200
|
+
"subscription" => "/meta/foo"
|
201
|
+
}
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
it "subscribes local clients to the channel" do
|
206
|
+
engine.should_receive(:subscribe).with(client_id, "/meta/foo")
|
207
|
+
server.subscribe(message, true) {}
|
208
|
+
end
|
209
|
+
|
210
|
+
it "returns a successful response for local clients" do
|
211
|
+
engine.stub(:subscribe)
|
212
|
+
server.subscribe(message, true) do |response|
|
213
|
+
response.should == {
|
214
|
+
"channel" => "/meta/subscribe",
|
215
|
+
"successful" => true,
|
216
|
+
"clientId" => client_id,
|
217
|
+
"subscription" => "/meta/foo"
|
218
|
+
}
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "with an error" do
|
224
|
+
before do
|
225
|
+
message["error"] = "invalid"
|
226
|
+
engine.should_receive(:client_exists).with(client_id).and_yield true
|
227
|
+
end
|
228
|
+
|
229
|
+
it "does not subscribe the client to the channel" do
|
230
|
+
engine.should_not_receive(:subscribe)
|
231
|
+
server.subscribe(message) {}
|
232
|
+
end
|
233
|
+
|
234
|
+
it "returns an unsuccessful response" do
|
235
|
+
server.subscribe(message) do |response|
|
236
|
+
response.should == {
|
237
|
+
"channel" => "/meta/subscribe",
|
238
|
+
"successful" => false,
|
239
|
+
"error" => "invalid",
|
240
|
+
"clientId" => client_id,
|
241
|
+
"subscription" => "/foo"
|
242
|
+
}
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
@@ -0,0 +1,247 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "server unsubscribe" do
|
4
|
+
let(:engine) { mock "engine" }
|
5
|
+
let(:server) { Faye::Server.new }
|
6
|
+
|
7
|
+
before do
|
8
|
+
Faye::Engine.stub(:get).and_return engine
|
9
|
+
end
|
10
|
+
|
11
|
+
describe :unsubscribe do
|
12
|
+
let(:client_id) { "fakeclientid" }
|
13
|
+
let(:message) {{"channel" => "/meta/unsubscribe",
|
14
|
+
"clientId" => "fakeclientid",
|
15
|
+
"subscription" => "/foo"
|
16
|
+
}}
|
17
|
+
|
18
|
+
describe "with valid parameters" do
|
19
|
+
before do
|
20
|
+
engine.should_receive(:client_exists).with(client_id).and_yield true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "unsubscribes the client from the channel" do
|
24
|
+
engine.should_receive(:unsubscribe).with(client_id, "/foo")
|
25
|
+
server.unsubscribe(message) {}
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns a successful response" do
|
29
|
+
engine.stub(:unsubscribe)
|
30
|
+
server.unsubscribe(message) do |response|
|
31
|
+
response.should == {
|
32
|
+
"channel" => "/meta/unsubscribe",
|
33
|
+
"successful" => true,
|
34
|
+
"clientId" => client_id,
|
35
|
+
"subscription" => "/foo"
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "with a list of subscriptions" do
|
41
|
+
before do
|
42
|
+
message["subscription"] = ["/foo", "/bar"]
|
43
|
+
end
|
44
|
+
|
45
|
+
it "destroys multiple subscriptions" do
|
46
|
+
engine.should_receive(:unsubscribe).with(client_id, "/foo")
|
47
|
+
engine.should_receive(:unsubscribe).with(client_id, "/bar")
|
48
|
+
server.unsubscribe(message) {}
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns a successful response" do
|
52
|
+
engine.stub(:unsubscribe)
|
53
|
+
server.unsubscribe(message) do |response|
|
54
|
+
response.should == {
|
55
|
+
"channel" => "/meta/unsubscribe",
|
56
|
+
"successful" => true,
|
57
|
+
"clientId" => client_id,
|
58
|
+
"subscription" => ["/foo", "/bar"]
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "with a subscription pattern" do
|
65
|
+
before do
|
66
|
+
message["subscription"] = "/foo/**"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "destroys the subscription to the channel pattern" do
|
70
|
+
engine.should_receive(:unsubscribe).with(client_id, "/foo/**")
|
71
|
+
server.unsubscribe(message) {}
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns a successful response" do
|
75
|
+
engine.stub(:unsubscribe)
|
76
|
+
server.unsubscribe(message) do |response|
|
77
|
+
response.should == {
|
78
|
+
"channel" => "/meta/unsubscribe",
|
79
|
+
"successful" => true,
|
80
|
+
"clientId" => client_id,
|
81
|
+
"subscription" => "/foo/**"
|
82
|
+
}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "with an unknown client" do
|
89
|
+
before do
|
90
|
+
engine.should_receive(:client_exists).with(client_id).and_yield false
|
91
|
+
end
|
92
|
+
|
93
|
+
it "does not unsubscribe the client from the channel" do
|
94
|
+
engine.should_not_receive(:unsubscribe)
|
95
|
+
server.unsubscribe(message) {}
|
96
|
+
end
|
97
|
+
|
98
|
+
it "returns an unsuccessful response" do
|
99
|
+
server.unsubscribe(message) do |response|
|
100
|
+
response.should == {
|
101
|
+
"channel" => "/meta/unsubscribe",
|
102
|
+
"successful" => false,
|
103
|
+
"error" => "401:fakeclientid:Unknown client",
|
104
|
+
"clientId" => client_id,
|
105
|
+
"subscription" => "/foo"
|
106
|
+
}
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "missing clientId" do
|
112
|
+
before do
|
113
|
+
message.delete("clientId")
|
114
|
+
engine.should_receive(:client_exists).with(nil).and_yield false
|
115
|
+
end
|
116
|
+
|
117
|
+
it "does not unsubscribe the client from the channel" do
|
118
|
+
engine.should_not_receive(:unsubscribe)
|
119
|
+
server.unsubscribe(message) {}
|
120
|
+
end
|
121
|
+
|
122
|
+
it "returns an unsuccessful response" do
|
123
|
+
server.unsubscribe(message) do |response|
|
124
|
+
response.should == {
|
125
|
+
"channel" => "/meta/unsubscribe",
|
126
|
+
"successful" => false,
|
127
|
+
"error" => "402:clientId:Missing required parameter",
|
128
|
+
"subscription" => "/foo"
|
129
|
+
}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "missing subscription" do
|
135
|
+
before do
|
136
|
+
message.delete("subscription")
|
137
|
+
engine.should_receive(:client_exists).with(client_id).and_yield true
|
138
|
+
end
|
139
|
+
|
140
|
+
it "does not unsubscribe the client from the channel" do
|
141
|
+
engine.should_not_receive(:unsubscribe)
|
142
|
+
server.unsubscribe(message) {}
|
143
|
+
end
|
144
|
+
|
145
|
+
it "returns an unsuccessful response" do
|
146
|
+
server.unsubscribe(message) do |response|
|
147
|
+
response.should == {
|
148
|
+
"channel" => "/meta/unsubscribe",
|
149
|
+
"successful" => false,
|
150
|
+
"error" => "402:subscription:Missing required parameter",
|
151
|
+
"clientId" => client_id,
|
152
|
+
"subscription" => []
|
153
|
+
}
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "with an invalid channel" do
|
159
|
+
before do
|
160
|
+
message["subscription"] = "foo"
|
161
|
+
engine.should_receive(:client_exists).with(client_id).and_yield true
|
162
|
+
end
|
163
|
+
|
164
|
+
it "does not unsubscribe the client from the channel" do
|
165
|
+
engine.should_not_receive(:unsubscribe)
|
166
|
+
server.unsubscribe(message) {}
|
167
|
+
end
|
168
|
+
|
169
|
+
it "returns an unsuccessful response" do
|
170
|
+
server.unsubscribe(message) do |response|
|
171
|
+
response.should == {
|
172
|
+
"channel" => "/meta/unsubscribe",
|
173
|
+
"successful" => false,
|
174
|
+
"error" => "405:foo:Invalid channel",
|
175
|
+
"clientId" => client_id,
|
176
|
+
"subscription" => "foo"
|
177
|
+
}
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "with a /meta/* channel" do
|
183
|
+
before do
|
184
|
+
message["subscription"] = "/meta/foo"
|
185
|
+
engine.should_receive(:client_exists).with(client_id).and_yield true
|
186
|
+
end
|
187
|
+
|
188
|
+
it "does not unsubscribe the client from the channel" do
|
189
|
+
engine.should_not_receive(:unsubscribe)
|
190
|
+
server.unsubscribe(message) {}
|
191
|
+
end
|
192
|
+
|
193
|
+
it "returns an unsuccessful response" do
|
194
|
+
server.unsubscribe(message) do |response|
|
195
|
+
response.should == {
|
196
|
+
"channel" => "/meta/unsubscribe",
|
197
|
+
"successful" => false,
|
198
|
+
"error" => "403:/meta/foo:Forbidden channel",
|
199
|
+
"clientId" => client_id,
|
200
|
+
"subscription" => "/meta/foo"
|
201
|
+
}
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
it "unsubscribes local clients from the channel" do
|
206
|
+
engine.should_receive(:unsubscribe).with(client_id, "/meta/foo")
|
207
|
+
server.unsubscribe(message, true) {}
|
208
|
+
end
|
209
|
+
|
210
|
+
it "returns a successful response for local clients" do
|
211
|
+
engine.stub(:unsubscribe)
|
212
|
+
server.unsubscribe(message, true) do |response|
|
213
|
+
response.should == {
|
214
|
+
"channel" => "/meta/unsubscribe",
|
215
|
+
"successful" => true,
|
216
|
+
"clientId" => client_id,
|
217
|
+
"subscription" => "/meta/foo"
|
218
|
+
}
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "with an error" do
|
224
|
+
before do
|
225
|
+
message["error"] = "invalid"
|
226
|
+
engine.should_receive(:client_exists).with(client_id).and_yield true
|
227
|
+
end
|
228
|
+
|
229
|
+
it "does not unsubscribe the client from the channel" do
|
230
|
+
engine.should_not_receive(:unsubscribe)
|
231
|
+
server.unsubscribe(message) {}
|
232
|
+
end
|
233
|
+
|
234
|
+
it "returns an unsuccessful response" do
|
235
|
+
server.unsubscribe(message) do |response|
|
236
|
+
response.should == {
|
237
|
+
"channel" => "/meta/unsubscribe",
|
238
|
+
"successful" => false,
|
239
|
+
"error" => "invalid",
|
240
|
+
"clientId" => client_id,
|
241
|
+
"subscription" => "/foo"
|
242
|
+
}
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|