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
data/test/test_grammar.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require File.dirname(__FILE__) + "/../lib/faye"
|
3
|
-
|
4
|
-
class TestGrammar < Test::Unit::TestCase
|
5
|
-
include Faye::Grammar
|
6
|
-
|
7
|
-
def test_single_chars
|
8
|
-
assert LOWALPHA =~ 'a'
|
9
|
-
assert LOWALPHA !~ 'A'
|
10
|
-
assert LOWALPHA !~ 'aa'
|
11
|
-
|
12
|
-
assert UPALPHA !~ 'a'
|
13
|
-
assert UPALPHA =~ 'A'
|
14
|
-
assert UPALPHA !~ 'AA'
|
15
|
-
|
16
|
-
assert ALPHA =~ 'a'
|
17
|
-
assert ALPHA =~ 'A'
|
18
|
-
assert ALPHA !~ '0'
|
19
|
-
assert ALPHA !~ 'aA'
|
20
|
-
|
21
|
-
assert DIGIT =~ '0'
|
22
|
-
assert DIGIT !~ '90'
|
23
|
-
assert DIGIT !~ 'z'
|
24
|
-
|
25
|
-
assert ALPHANUM =~ '6'
|
26
|
-
assert ALPHANUM =~ 'b'
|
27
|
-
assert ALPHANUM !~ '6b'
|
28
|
-
assert ALPHANUM !~ '/'
|
29
|
-
|
30
|
-
assert MARK =~ '-'
|
31
|
-
assert MARK =~ '@'
|
32
|
-
assert MARK !~ '!-'
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_strings
|
36
|
-
assert STRING =~ ''
|
37
|
-
assert STRING =~ ' 4tv4 (($ !/~ ..* /) ___'
|
38
|
-
assert STRING !~ ' 4tv4 (($ !/~ ..* /) _}_'
|
39
|
-
|
40
|
-
assert TOKEN =~ '$a9b'
|
41
|
-
assert TOKEN !~ ''
|
42
|
-
|
43
|
-
assert INTEGER =~ '9'
|
44
|
-
assert INTEGER =~ '09'
|
45
|
-
assert INTEGER !~ '9.0'
|
46
|
-
assert INTEGER !~ '9a'
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_channels
|
50
|
-
assert CHANNEL_NAME =~ '/fo_o/$@()bar'
|
51
|
-
assert CHANNEL_NAME !~ '/foo/$@()bar/'
|
52
|
-
assert CHANNEL_NAME !~ 'foo/$@()bar'
|
53
|
-
assert CHANNEL_NAME !~ '/fo o/$@()bar'
|
54
|
-
|
55
|
-
assert CHANNEL_PATTERN =~ '/!!/$/*'
|
56
|
-
assert CHANNEL_PATTERN =~ '/!!/$/**'
|
57
|
-
assert CHANNEL_PATTERN !~ '/!!/$/**/'
|
58
|
-
assert CHANNEL_PATTERN !~ '!!/$/**'
|
59
|
-
assert CHANNEL_PATTERN !~ '/!!/$/**/*'
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_version
|
63
|
-
assert VERSION =~ '9'
|
64
|
-
assert VERSION =~ '9.a-delta4'
|
65
|
-
assert VERSION !~ '9.a-delta4.'
|
66
|
-
assert VERSION !~ 'K.a-delta4'
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_ids
|
70
|
-
assert CLIENT_ID =~ '9'
|
71
|
-
assert CLIENT_ID =~ 'j'
|
72
|
-
assert CLIENT_ID !~ ''
|
73
|
-
assert CLIENT_ID =~ 'dfghs5r'
|
74
|
-
assert CLIENT_ID !~ 'dfg_hs5r'
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_errors
|
78
|
-
assert ERROR =~ '401::No client ID'
|
79
|
-
assert ERROR !~ '401:No client ID'
|
80
|
-
assert ERROR !~ '40::No client ID'
|
81
|
-
assert ERROR !~ '40k::No client ID'
|
82
|
-
assert ERROR =~ '402:xj3sjdsjdsjad:Unknown Client ID'
|
83
|
-
assert ERROR =~ '403:xj3sjdsjdsjad,/foo/bar:Subscription denied'
|
84
|
-
assert ERROR =~ '404:/foo/bar:Unknown Channel'
|
85
|
-
end
|
86
|
-
end
|
data/test/test_server.rb
DELETED
@@ -1,488 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require File.dirname(__FILE__) + "/../lib/faye"
|
3
|
-
|
4
|
-
class TestServer < Test::Unit::TestCase
|
5
|
-
include Faye
|
6
|
-
|
7
|
-
class ErrorExtension
|
8
|
-
def incoming(message, callback)
|
9
|
-
message['error'] = 'Extension error'
|
10
|
-
callback.call(message)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def setup
|
15
|
-
@server = Server.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def get_client_id
|
19
|
-
handshake( 'version' => '1.0',
|
20
|
-
'supportedConnectionTypes' => %w[long-polling] )
|
21
|
-
@r['clientId']
|
22
|
-
end
|
23
|
-
|
24
|
-
def method_missing(channel, message, *args, &block)
|
25
|
-
message['channel'] = "/meta/#{channel}"
|
26
|
-
@r = @server.__send__(channel, message, *args, &block)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_handshake
|
30
|
-
#================================================================
|
31
|
-
# MUST
|
32
|
-
handshake( 'version' => '1.0',
|
33
|
-
'supportedConnectionTypes' => %w[long-polling] )
|
34
|
-
# MAY include minimumVersion, ext, id
|
35
|
-
# SHOULD NOT send other messages with handshake
|
36
|
-
|
37
|
-
# MUST
|
38
|
-
assert_equal '/meta/handshake', @r['channel']
|
39
|
-
assert_not_equal nil, @r['version']
|
40
|
-
assert_equal %w[long-polling callback-polling websocket], @r['supportedConnectionTypes']
|
41
|
-
assert_match( /[a-z0-9]+/, @r['clientId'] )
|
42
|
-
assert_equal true, @r['successful']
|
43
|
-
# MAY
|
44
|
-
assert_equal nil, @r['id']
|
45
|
-
# MAY include minimumVersion, advice, ext, authSuccessful
|
46
|
-
|
47
|
-
#================================================================
|
48
|
-
# Unique IDs
|
49
|
-
id1 = @r['clientId']
|
50
|
-
assert_equal [id1], @server.client_ids
|
51
|
-
handshake( 'version' => '1.0', 'supportedConnectionTypes' => %w[callback-polling] )
|
52
|
-
id2 = @r['clientId']
|
53
|
-
assert_not_equal id1, id2
|
54
|
-
assert_equal [id1, id2].sort, @server.client_ids.sort
|
55
|
-
|
56
|
-
#================================================================
|
57
|
-
handshake( 'version' => '1.0',
|
58
|
-
'supportedConnectionTypes' => %w[long-polling],
|
59
|
-
'id' => 'foo' )
|
60
|
-
# MAY
|
61
|
-
assert_equal 'foo', @r['id']
|
62
|
-
|
63
|
-
#================================================================
|
64
|
-
# missing version
|
65
|
-
handshake('supportedConnectionTypes' => %w[long-polling])
|
66
|
-
# MUST
|
67
|
-
assert_equal '/meta/handshake', @r['channel']
|
68
|
-
assert_equal false, @r['successful']
|
69
|
-
assert_equal '402:version:Missing required parameter', @r['error']
|
70
|
-
# MAY
|
71
|
-
assert_not_equal nil, @r['version']
|
72
|
-
assert_equal %w[long-polling callback-polling websocket], @r['supportedConnectionTypes']
|
73
|
-
# MAY include advice, minimumVersion, ext, id
|
74
|
-
|
75
|
-
#================================================================
|
76
|
-
# no matching connection type
|
77
|
-
handshake('supportedConnectionTypes' => %w[iframe flash])
|
78
|
-
# MUST
|
79
|
-
assert_equal '/meta/handshake', @r['channel']
|
80
|
-
assert_equal false, @r['successful']
|
81
|
-
assert_equal '301:iframe,flash:Connection types not supported', @r['error']
|
82
|
-
# MAY
|
83
|
-
assert_equal %w[long-polling callback-polling websocket], @r['supportedConnectionTypes']
|
84
|
-
assert_equal nil, @r['id']
|
85
|
-
|
86
|
-
#================================================================
|
87
|
-
# no given connection type
|
88
|
-
handshake('version' => '1.0', 'id' => 'foo')
|
89
|
-
# MUST
|
90
|
-
assert_equal '/meta/handshake', @r['channel']
|
91
|
-
assert_equal false, @r['successful']
|
92
|
-
assert_equal '402:supportedConnectionTypes:Missing required parameter', @r['error']
|
93
|
-
# MAY
|
94
|
-
assert_equal %w[long-polling callback-polling websocket], @r['supportedConnectionTypes']
|
95
|
-
assert_equal 'foo', @r['id']
|
96
|
-
|
97
|
-
#================================================================
|
98
|
-
# local clients don't need to negotiate connection types
|
99
|
-
handshake({'version' => '1.0'}, true)
|
100
|
-
|
101
|
-
assert_equal '/meta/handshake', @r['channel']
|
102
|
-
assert_not_equal nil, @r['version']
|
103
|
-
assert_equal nil, @r['supportedConnectionTypes']
|
104
|
-
assert_match( /[a-z0-9]+/, @r['clientId'] )
|
105
|
-
assert_equal true, @r['successful']
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_connect
|
109
|
-
@id = get_client_id
|
110
|
-
#================================================================
|
111
|
-
# MUST
|
112
|
-
connect( 'clientId' => @id,
|
113
|
-
'connectionType' => 'long-polling' )
|
114
|
-
# MUST
|
115
|
-
assert_equal '/meta/connect', @r['channel']
|
116
|
-
assert_equal true, @r['successful']
|
117
|
-
assert_equal @id, @r['clientId']
|
118
|
-
# MAY
|
119
|
-
assert_equal nil, @r['id']
|
120
|
-
# MAY include error, advice, ext, timestamp
|
121
|
-
|
122
|
-
#================================================================
|
123
|
-
connect( 'clientId' => @id,
|
124
|
-
'connectionType' => 'long-polling',
|
125
|
-
'id' => 'foo' )
|
126
|
-
# MUST
|
127
|
-
assert_equal '/meta/connect', @r['channel']
|
128
|
-
assert_equal true, @r['successful']
|
129
|
-
assert_equal @id, @r['clientId']
|
130
|
-
# MAY
|
131
|
-
assert_equal 'foo', @r['id']
|
132
|
-
|
133
|
-
#================================================================
|
134
|
-
# no client ID
|
135
|
-
connect( 'connectionType' => 'long-polling' )
|
136
|
-
# MUST
|
137
|
-
assert_equal '/meta/connect', @r['channel']
|
138
|
-
assert_equal false, @r['successful']
|
139
|
-
assert_equal nil, @r['clientId']
|
140
|
-
# MAY
|
141
|
-
assert_equal '402:clientId:Missing required parameter', @r['error']
|
142
|
-
assert_equal nil, @r['id']
|
143
|
-
# MAY include advice, ext, timestamp
|
144
|
-
|
145
|
-
#================================================================
|
146
|
-
# no connection type
|
147
|
-
connect( 'clientId' => @id )
|
148
|
-
# MUST
|
149
|
-
assert_equal '/meta/connect', @r['channel']
|
150
|
-
assert_equal false, @r['successful']
|
151
|
-
assert_equal nil, @r['clientId']
|
152
|
-
# MAY
|
153
|
-
assert_equal '402:connectionType:Missing required parameter', @r['error']
|
154
|
-
assert_equal nil, @r['id']
|
155
|
-
# MAY include advice, ext, timestamp
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_disconnect
|
159
|
-
@id = get_client_id
|
160
|
-
assert_equal [@id], @server.client_ids
|
161
|
-
|
162
|
-
#================================================================
|
163
|
-
# MUST
|
164
|
-
disconnect( 'clientId' => @id )
|
165
|
-
# MUST
|
166
|
-
assert_equal '/meta/disconnect', @r['channel']
|
167
|
-
assert_equal @id, @r['clientId']
|
168
|
-
assert_equal true, @r['successful']
|
169
|
-
# MAY
|
170
|
-
assert_equal nil, @r['id']
|
171
|
-
# MAY include error, ext
|
172
|
-
assert_equal [], @server.client_ids
|
173
|
-
|
174
|
-
#================================================================
|
175
|
-
# missing client ID
|
176
|
-
disconnect( 'id' => 'foo' )
|
177
|
-
# MUST
|
178
|
-
assert_equal '/meta/disconnect', @r['channel']
|
179
|
-
assert_equal nil, @r['clientId']
|
180
|
-
assert_equal false, @r['successful']
|
181
|
-
# MAY
|
182
|
-
assert_equal '402:clientId:Missing required parameter', @r['error']
|
183
|
-
assert_equal 'foo', @r['id']
|
184
|
-
# MAY include ext
|
185
|
-
|
186
|
-
#================================================================
|
187
|
-
# unrecognised client ID
|
188
|
-
disconnect( 'clientId' => @id )
|
189
|
-
# MUST
|
190
|
-
assert_equal '/meta/disconnect', @r['channel']
|
191
|
-
assert_equal nil, @r['clientId']
|
192
|
-
assert_equal false, @r['successful']
|
193
|
-
# MAY
|
194
|
-
assert_equal "401:#{@id}:Unknown client", @r['error']
|
195
|
-
assert_equal nil, @r['id']
|
196
|
-
# MAY include ext
|
197
|
-
end
|
198
|
-
|
199
|
-
def test_subscribe
|
200
|
-
@id = get_client_id
|
201
|
-
#================================================================
|
202
|
-
# MUST
|
203
|
-
subscribe( 'clientId' => @id,
|
204
|
-
'subscription' => '/foo' ) # channel name
|
205
|
-
# MAY include ext, id
|
206
|
-
|
207
|
-
# MUST
|
208
|
-
assert_equal '/meta/subscribe', @r['channel']
|
209
|
-
assert_equal true, @r['successful']
|
210
|
-
assert_equal @id, @r['clientId']
|
211
|
-
assert_equal ['/foo'], @r['subscription']
|
212
|
-
# MAY
|
213
|
-
assert_equal nil, @r['id']
|
214
|
-
# MAY include error, advice, ext, timestamp
|
215
|
-
|
216
|
-
#================================================================
|
217
|
-
# MUST
|
218
|
-
subscribe( 'clientId' => @id,
|
219
|
-
'subscription' => '/foo/**' ) # channel pattern
|
220
|
-
# MAY include ext, id
|
221
|
-
|
222
|
-
# MUST
|
223
|
-
assert_equal '/meta/subscribe', @r['channel']
|
224
|
-
assert_equal true, @r['successful']
|
225
|
-
assert_equal @id, @r['clientId']
|
226
|
-
assert_equal ['/foo/**'], @r['subscription']
|
227
|
-
# MAY
|
228
|
-
assert_equal nil, @r['id']
|
229
|
-
# MAY include error, advice, ext, timestamp
|
230
|
-
|
231
|
-
#================================================================
|
232
|
-
# MUST
|
233
|
-
subscribe( 'clientId' => @id,
|
234
|
-
'subscription' => ['/bar/*', '/foo'], # channel list
|
235
|
-
'id' => 'baz' )
|
236
|
-
# MAY include ext
|
237
|
-
|
238
|
-
# MUST
|
239
|
-
assert_equal '/meta/subscribe', @r['channel']
|
240
|
-
assert_equal true, @r['successful']
|
241
|
-
assert_equal @id, @r['clientId']
|
242
|
-
assert_equal ['/bar/*', '/foo'], @r['subscription']
|
243
|
-
# MAY
|
244
|
-
assert_equal 'baz', @r['id']
|
245
|
-
# MAY include error, advice, ext, timestamp
|
246
|
-
|
247
|
-
#================================================================
|
248
|
-
# missing client ID
|
249
|
-
subscribe( 'subscription' => '/foo' )
|
250
|
-
# MAY include ext, id
|
251
|
-
|
252
|
-
# MUST
|
253
|
-
assert_equal '/meta/subscribe', @r['channel']
|
254
|
-
assert_equal false, @r['successful']
|
255
|
-
assert_equal nil, @r['clientId']
|
256
|
-
assert_equal ['/foo'], @r['subscription']
|
257
|
-
# MAY
|
258
|
-
assert_equal '402:clientId:Missing required parameter', @r['error']
|
259
|
-
assert_equal nil, @r['id']
|
260
|
-
# MAY include advice, ext, timestamp
|
261
|
-
|
262
|
-
#================================================================
|
263
|
-
# unknown client
|
264
|
-
subscribe( 'clientId' => 'nonesuch',
|
265
|
-
'subscription' => '/j' )
|
266
|
-
# MAY include ext, id
|
267
|
-
|
268
|
-
# MUST
|
269
|
-
assert_equal '/meta/subscribe', @r['channel']
|
270
|
-
assert_equal false, @r['successful']
|
271
|
-
assert_equal 'nonesuch', @r['clientId']
|
272
|
-
assert_equal ['/j'], @r['subscription']
|
273
|
-
# MAY
|
274
|
-
assert_equal '401:nonesuch:Unknown client', @r['error']
|
275
|
-
assert_equal nil, @r['id']
|
276
|
-
# MAY include advice, ext, timestamp
|
277
|
-
|
278
|
-
#================================================================
|
279
|
-
# missing subscription
|
280
|
-
subscribe( 'clientId' => @id )
|
281
|
-
# MAY include ext, id
|
282
|
-
|
283
|
-
# MUST
|
284
|
-
assert_equal '/meta/subscribe', @r['channel']
|
285
|
-
assert_equal false, @r['successful']
|
286
|
-
assert_equal @id, @r['clientId']
|
287
|
-
assert_equal [], @r['subscription']
|
288
|
-
# MAY
|
289
|
-
assert_equal '402:subscription:Missing required parameter', @r['error']
|
290
|
-
assert_equal nil, @r['id']
|
291
|
-
# MAY include advice, ext, timestamp
|
292
|
-
|
293
|
-
#================================================================
|
294
|
-
# invalid channel
|
295
|
-
subscribe( 'clientId' => @id,
|
296
|
-
'subscription' => '/not/**/valid' )
|
297
|
-
# MAY include ext, id
|
298
|
-
|
299
|
-
# MUST
|
300
|
-
assert_equal '/meta/subscribe', @r['channel']
|
301
|
-
assert_equal false, @r['successful']
|
302
|
-
assert_equal @id, @r['clientId']
|
303
|
-
assert_equal ['/not/**/valid'], @r['subscription']
|
304
|
-
# MAY
|
305
|
-
assert_equal "405:/not/**/valid:Invalid channel", @r['error']
|
306
|
-
assert_equal nil, @r['id']
|
307
|
-
# MAY include advice, ext, timestamp
|
308
|
-
|
309
|
-
#================================================================
|
310
|
-
# cannot subscribe to meta channels
|
311
|
-
subscribe( 'clientId' => @id,
|
312
|
-
'subscription' => '/meta/foo' )
|
313
|
-
# MAY include ext, id
|
314
|
-
|
315
|
-
# MUST
|
316
|
-
assert_equal '/meta/subscribe', @r['channel']
|
317
|
-
assert_equal false, @r['successful']
|
318
|
-
assert_equal @id, @r['clientId']
|
319
|
-
assert_equal ['/meta/foo'], @r['subscription']
|
320
|
-
# MAY
|
321
|
-
assert_equal "403:/meta/foo:Forbidden channel", @r['error']
|
322
|
-
assert_equal nil, @r['id']
|
323
|
-
# MAY include advice, ext, timestamp
|
324
|
-
|
325
|
-
#================================================================
|
326
|
-
# cannot subscribe to service channels
|
327
|
-
subscribe( 'clientId' => @id,
|
328
|
-
'subscription' => '/service/foo' )
|
329
|
-
# MAY include ext, id
|
330
|
-
|
331
|
-
# MUST
|
332
|
-
assert_equal '/meta/subscribe', @r['channel']
|
333
|
-
assert_equal false, @r['successful']
|
334
|
-
assert_equal @id, @r['clientId']
|
335
|
-
assert_equal ['/service/foo'], @r['subscription']
|
336
|
-
# MAY
|
337
|
-
assert_equal "403:/service/foo:Forbidden channel", @r['error']
|
338
|
-
assert_equal nil, @r['id']
|
339
|
-
# MAY include advice, ext, timestamp
|
340
|
-
|
341
|
-
#================================================================
|
342
|
-
# local client may subscribe to meta channels
|
343
|
-
subscribe({ 'clientId' => @id,
|
344
|
-
'subscription' => '/meta/foo' }, true)
|
345
|
-
# MAY include ext, id
|
346
|
-
|
347
|
-
# MUST
|
348
|
-
assert_equal '/meta/subscribe', @r['channel']
|
349
|
-
assert_equal true, @r['successful']
|
350
|
-
assert_equal @id, @r['clientId']
|
351
|
-
assert_equal ['/meta/foo'], @r['subscription']
|
352
|
-
# MAY
|
353
|
-
assert_equal nil, @r['error']
|
354
|
-
assert_equal nil, @r['id']
|
355
|
-
# MAY include advice, ext, timestamp
|
356
|
-
end
|
357
|
-
|
358
|
-
def test_unsubscribe
|
359
|
-
@id = get_client_id
|
360
|
-
subscribe( 'clientId' => @id, 'subscription' => '/foo' )
|
361
|
-
|
362
|
-
#================================================================
|
363
|
-
# MUST
|
364
|
-
unsubscribe( 'clientId' => @id,
|
365
|
-
'subscription' => '/foo' )
|
366
|
-
# MAY include ext, id
|
367
|
-
|
368
|
-
# MUST
|
369
|
-
assert_equal '/meta/unsubscribe', @r['channel']
|
370
|
-
assert_equal true, @r['successful']
|
371
|
-
assert_equal @id, @r['clientId']
|
372
|
-
assert_equal ['/foo'], @r['subscription']
|
373
|
-
# MAY
|
374
|
-
assert_equal nil, @r['id']
|
375
|
-
# MAY include error, advice, ext, timestamp
|
376
|
-
|
377
|
-
#================================================================
|
378
|
-
# missing client ID
|
379
|
-
unsubscribe( 'subscription' => '/foo' )
|
380
|
-
# MAY include ext, id
|
381
|
-
|
382
|
-
# MUST
|
383
|
-
assert_equal '/meta/unsubscribe', @r['channel']
|
384
|
-
assert_equal false, @r['successful']
|
385
|
-
assert_equal nil, @r['clientId']
|
386
|
-
assert_equal ['/foo'], @r['subscription']
|
387
|
-
# MAY
|
388
|
-
assert_equal '402:clientId:Missing required parameter', @r['error']
|
389
|
-
assert_equal nil, @r['id']
|
390
|
-
# MAY include advice, ext, timestamp
|
391
|
-
|
392
|
-
#================================================================
|
393
|
-
# unknown client
|
394
|
-
unsubscribe( 'clientId' => 'matz',
|
395
|
-
'subscription' => '/foo' )
|
396
|
-
# MAY include ext, id
|
397
|
-
|
398
|
-
# MUST
|
399
|
-
assert_equal '/meta/unsubscribe', @r['channel']
|
400
|
-
assert_equal false, @r['successful']
|
401
|
-
assert_equal 'matz', @r['clientId']
|
402
|
-
assert_equal ['/foo'], @r['subscription']
|
403
|
-
# MAY
|
404
|
-
assert_equal '401:matz:Unknown client', @r['error']
|
405
|
-
assert_equal nil, @r['id']
|
406
|
-
# MAY include advice, ext, timestamp
|
407
|
-
|
408
|
-
#================================================================
|
409
|
-
# missing subscription
|
410
|
-
unsubscribe( 'clientId' => @id )
|
411
|
-
# MAY include ext, id
|
412
|
-
|
413
|
-
# MUST
|
414
|
-
assert_equal '/meta/unsubscribe', @r['channel']
|
415
|
-
assert_equal false, @r['successful']
|
416
|
-
assert_equal @id, @r['clientId']
|
417
|
-
assert_equal [], @r['subscription']
|
418
|
-
# MAY
|
419
|
-
assert_equal '402:subscription:Missing required parameter', @r['error']
|
420
|
-
assert_equal nil, @r['id']
|
421
|
-
# MAY include advice, ext, timestamp
|
422
|
-
|
423
|
-
#================================================================
|
424
|
-
# invalid channel
|
425
|
-
unsubscribe( 'clientId' => @id,
|
426
|
-
'subscription' => '/not/**/valid' )
|
427
|
-
# MAY include ext, id
|
428
|
-
|
429
|
-
# MUST
|
430
|
-
assert_equal '/meta/unsubscribe', @r['channel']
|
431
|
-
assert_equal false, @r['successful']
|
432
|
-
assert_equal @id, @r['clientId']
|
433
|
-
assert_equal ['/not/**/valid'], @r['subscription']
|
434
|
-
# MAY
|
435
|
-
assert_equal "405:/not/**/valid:Invalid channel", @r['error']
|
436
|
-
assert_equal nil, @r['id']
|
437
|
-
# MAY include advice, ext, timestamp
|
438
|
-
|
439
|
-
#================================================================
|
440
|
-
# local client may unsubscribe from meta channels
|
441
|
-
unsubscribe({ 'clientId' => @id,
|
442
|
-
'subscription' => '/meta/foo' }, true)
|
443
|
-
# MAY include ext, id
|
444
|
-
|
445
|
-
# MUST
|
446
|
-
assert_equal '/meta/unsubscribe', @r['channel']
|
447
|
-
assert_equal true, @r['successful']
|
448
|
-
assert_equal @id, @r['clientId']
|
449
|
-
assert_equal ['/meta/foo'], @r['subscription']
|
450
|
-
# MAY
|
451
|
-
assert_equal nil, @r['error']
|
452
|
-
assert_equal nil, @r['id']
|
453
|
-
# MAY include error, advice, ext, timestamp
|
454
|
-
end
|
455
|
-
|
456
|
-
def test_advice
|
457
|
-
@server.send :handle, 'channel' => '/meta/subscribe', 'subscription' => '/foo', 'clientId' => 'fake' do |r|
|
458
|
-
assert_equal '401:fake:Unknown client', r.first['error']
|
459
|
-
assert_equal 'handshake', r.first['advice']['reconnect']
|
460
|
-
end
|
461
|
-
|
462
|
-
id = get_client_id
|
463
|
-
@server.send :handle, 'channel' => '/meta/subscribe', 'subscription' => '/foo', 'clientId' => id do |r|
|
464
|
-
assert_equal true, r.first['successful']
|
465
|
-
assert_equal 'retry', r.first['advice']['reconnect']
|
466
|
-
assert_equal 0, r.first['advice']['interval']
|
467
|
-
assert_equal 60000, r.first['advice']['timeout']
|
468
|
-
end
|
469
|
-
end
|
470
|
-
|
471
|
-
def test_errors_from_extensions
|
472
|
-
@server.add_extension(ErrorExtension.new)
|
473
|
-
|
474
|
-
id = get_client_id
|
475
|
-
@server.send :process, ['channel' => '/meta/subscribe', 'subscription' => '/foo', 'clientId' => id], false do |r|
|
476
|
-
# MUST
|
477
|
-
assert_equal '/meta/subscribe', r.first['channel']
|
478
|
-
assert_equal false, r.first['successful']
|
479
|
-
assert_equal id, r.first['clientId']
|
480
|
-
assert_equal ['/foo'], r.first['subscription']
|
481
|
-
# MAY
|
482
|
-
assert_equal 'Extension error', r.first['error']
|
483
|
-
assert_equal nil, r.first['id']
|
484
|
-
# MAY include advice, ext, timestamp
|
485
|
-
end
|
486
|
-
end
|
487
|
-
end
|
488
|
-
|