vines 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/README +1 -1
  2. data/Rakefile +10 -10
  3. data/conf/certs/ca-bundle.crt +112 -378
  4. data/conf/config.rb +18 -9
  5. data/lib/vines.rb +8 -1
  6. data/lib/vines/command/cert.rb +2 -1
  7. data/lib/vines/command/init.rb +11 -0
  8. data/lib/vines/command/ldap.rb +6 -3
  9. data/lib/vines/command/schema.rb +1 -1
  10. data/lib/vines/config.rb +57 -146
  11. data/lib/vines/config/host.rb +85 -0
  12. data/lib/vines/config/port.rb +111 -0
  13. data/lib/vines/contact.rb +1 -1
  14. data/lib/vines/jid.rb +26 -4
  15. data/lib/vines/kit.rb +6 -0
  16. data/lib/vines/log.rb +24 -0
  17. data/lib/vines/router.rb +70 -38
  18. data/lib/vines/stanza.rb +45 -8
  19. data/lib/vines/stanza/iq.rb +3 -3
  20. data/lib/vines/stanza/iq/disco_info.rb +5 -1
  21. data/lib/vines/stanza/iq/disco_items.rb +3 -0
  22. data/lib/vines/stanza/iq/private_storage.rb +9 -5
  23. data/lib/vines/stanza/iq/roster.rb +11 -12
  24. data/lib/vines/stanza/iq/vcard.rb +4 -4
  25. data/lib/vines/stanza/iq/version.rb +25 -0
  26. data/lib/vines/stanza/message.rb +4 -5
  27. data/lib/vines/stanza/presence.rb +20 -18
  28. data/lib/vines/stanza/presence/probe.rb +3 -4
  29. data/lib/vines/stanza/presence/subscribe.rb +4 -3
  30. data/lib/vines/stanza/presence/subscribed.rb +6 -5
  31. data/lib/vines/stanza/presence/unsubscribe.rb +4 -4
  32. data/lib/vines/stanza/presence/unsubscribed.rb +4 -3
  33. data/lib/vines/storage/couchdb.rb +3 -3
  34. data/lib/vines/storage/ldap.rb +19 -8
  35. data/lib/vines/storage/local.rb +23 -12
  36. data/lib/vines/storage/redis.rb +3 -3
  37. data/lib/vines/storage/sql.rb +5 -5
  38. data/lib/vines/stream.rb +40 -6
  39. data/lib/vines/stream/client.rb +5 -6
  40. data/lib/vines/stream/client/auth.rb +3 -2
  41. data/lib/vines/stream/client/bind.rb +2 -2
  42. data/lib/vines/stream/client/bind_restart.rb +1 -2
  43. data/lib/vines/stream/client/ready.rb +2 -0
  44. data/lib/vines/stream/client/session.rb +13 -4
  45. data/lib/vines/stream/client/tls.rb +1 -0
  46. data/lib/vines/stream/component.rb +6 -5
  47. data/lib/vines/stream/component/ready.rb +5 -6
  48. data/lib/vines/stream/http.rb +10 -4
  49. data/lib/vines/stream/http/request.rb +23 -2
  50. data/lib/vines/stream/server.rb +13 -11
  51. data/lib/vines/stream/server/outbound/auth_result.rb +1 -0
  52. data/lib/vines/stream/server/outbound/tls_result.rb +1 -0
  53. data/lib/vines/stream/server/ready.rb +2 -2
  54. data/lib/vines/user.rb +2 -1
  55. data/lib/vines/version.rb +1 -1
  56. data/test/config/host_test.rb +292 -0
  57. data/test/config_test.rb +244 -103
  58. data/test/contact_test.rb +7 -1
  59. data/test/jid_test.rb +48 -0
  60. data/test/router_test.rb +16 -47
  61. data/test/stanza/iq/disco_info_test.rb +76 -0
  62. data/test/stanza/iq/disco_items_test.rb +47 -0
  63. data/test/stanza/iq/private_storage_test.rb +33 -10
  64. data/test/stanza/iq/roster_test.rb +15 -5
  65. data/test/stanza/iq/vcard_test.rb +8 -25
  66. data/test/stanza/iq/version_test.rb +62 -0
  67. data/test/stanza/iq_test.rb +13 -10
  68. data/test/stanza/message_test.rb +16 -24
  69. data/test/stanza/presence/probe_test.rb +52 -0
  70. data/test/stanza/presence/subscribe_test.rb +1 -5
  71. data/test/stanza_test.rb +77 -0
  72. data/test/stream/client/auth_test.rb +1 -0
  73. data/test/stream/client/ready_test.rb +2 -0
  74. data/test/stream/client/session_test.rb +7 -2
  75. data/test/stream/component/ready_test.rb +19 -36
  76. data/test/stream/http/request_test.rb +22 -2
  77. data/test/stream/server/ready_test.rb +14 -21
  78. data/web/404.html +9 -3
  79. data/web/chat/index.html +2 -2
  80. data/web/chat/javascripts/app.js +1 -1
  81. data/web/chat/stylesheets/chat.css +4 -9
  82. data/web/lib/coffeescripts/layout.coffee +2 -2
  83. data/web/{chat → lib}/coffeescripts/logout.coffee +0 -0
  84. data/web/lib/coffeescripts/notification.coffee +14 -0
  85. data/web/lib/coffeescripts/session.coffee +28 -24
  86. data/web/lib/coffeescripts/transfer.coffee +37 -34
  87. data/web/lib/javascripts/base.js +8 -8
  88. data/web/lib/javascripts/icons.js +3 -0
  89. data/web/lib/javascripts/jquery.js +4 -18
  90. data/web/lib/javascripts/layout.js +2 -2
  91. data/web/{chat → lib}/javascripts/logout.js +0 -0
  92. data/web/lib/javascripts/notification.js +26 -0
  93. data/web/lib/javascripts/session.js +20 -16
  94. data/web/lib/javascripts/transfer.js +45 -55
  95. data/web/lib/stylesheets/base.css +45 -9
  96. metadata +31 -15
data/test/config_test.rb CHANGED
@@ -20,7 +20,7 @@ class ConfigTest < MiniTest::Unit::TestCase
20
20
  dir '.'
21
21
  end
22
22
  end
23
- host 'wonderland.lit' do
23
+ host 'WONDERLAND.LIT' do
24
24
  storage 'fs' do
25
25
  dir '.'
26
26
  end
@@ -41,85 +41,6 @@ class ConfigTest < MiniTest::Unit::TestCase
41
41
  end
42
42
  end
43
43
 
44
- def test_missing_storage
45
- assert_raises(RuntimeError) do
46
- Vines::Config.new do
47
- host 'wonderland.lit' do
48
- # missing storage
49
- end
50
- end
51
- end
52
- end
53
-
54
- def test_bad_storage
55
- assert_raises(RuntimeError) do
56
- Vines::Config.new do
57
- host 'wonderland.lit' do
58
- storage 'bogus' do
59
- # no bogus storage implementation
60
- end
61
- end
62
- end
63
- end
64
- end
65
-
66
- def test_duplicate_storage
67
- assert_raises(RuntimeError) do
68
- Vines::Config.new do
69
- host 'wonderland.lit' do
70
- storage('fs') { dir '.' }
71
- storage('fs') { dir '.' }
72
- end
73
- end
74
- end
75
- end
76
-
77
- def test_good_storage_raises_no_errors
78
- Vines::Config.new do
79
- host 'wonderland.lit' do
80
- storage 'fs' do
81
- dir '.'
82
- end
83
- end
84
- end
85
- end
86
-
87
- def test_ldap_added_to_storage
88
- config = Vines::Config.new do
89
- host 'wonderland.lit' do
90
- storage(:fs) { dir '.' }
91
- # added after storage
92
- ldap 'ldap.wonderland.lit', 1636 do
93
- tls true
94
- dn 'cn=Directory Manager'
95
- password 'secr3t'
96
- basedn 'dc=wonderland,dc=lit'
97
- object_class 'person'
98
- user_attr 'uid'
99
- name_attr 'cn'
100
- end
101
- end
102
-
103
- host 'verona.lit' do
104
- ldap 'ldap.verona.lit', 1636 do
105
- tls true
106
- dn 'cn=Directory Manager'
107
- password 'secr3t'
108
- basedn 'dc=wonderland,dc=lit'
109
- object_class 'person'
110
- user_attr 'uid'
111
- name_attr 'cn'
112
- end
113
- # added before storage
114
- storage(:fs) { dir '.' }
115
- end
116
- end
117
- %w[wonderland.lit verona.lit].each do |domain|
118
- refute_nil config.vhosts[domain].ldap
119
- assert config.vhosts[domain].ldap?
120
- end
121
- end
122
-
123
44
  def test_configure
124
45
  config = Vines::Config.configure do
125
46
  host 'wonderland.lit' do
@@ -140,7 +61,8 @@ class ConfigTest < MiniTest::Unit::TestCase
140
61
  end
141
62
  assert_equal ['wonderland.lit'], config.vhosts.keys
142
63
  assert config.vhost?('wonderland.lit')
143
- assert !config.vhost?('bogus')
64
+ refute config.vhost?('tea.wonderland.lit')
65
+ refute config.vhost?('bogus')
144
66
  end
145
67
 
146
68
  def test_port_lookup
@@ -205,9 +127,8 @@ class ConfigTest < MiniTest::Unit::TestCase
205
127
  assert_equal 5222, port.port
206
128
  assert_equal 131_072, port.max_stanza_size
207
129
  assert_equal 5, port.max_resources_per_account
208
- refute port.private_storage?
209
130
  assert_equal Vines::Stream::Client, port.stream
210
- assert_same config, port.config
131
+ assert_same config, port.config
211
132
  assert_equal 1, config.ports.size
212
133
  end
213
134
 
@@ -217,7 +138,6 @@ class ConfigTest < MiniTest::Unit::TestCase
217
138
  storage(:fs) { dir '.' }
218
139
  end
219
140
  client '0.0.0.1', 42 do
220
- private_storage true
221
141
  max_stanza_size 60_000
222
142
  max_resources_per_account 1
223
143
  end
@@ -229,9 +149,8 @@ class ConfigTest < MiniTest::Unit::TestCase
229
149
  assert_equal 42, port.port
230
150
  assert_equal 60_000, port.max_stanza_size
231
151
  assert_equal 1, port.max_resources_per_account
232
- assert port.private_storage?
233
152
  assert_equal Vines::Stream::Client, port.stream
234
- assert_same config, port.config
153
+ assert_same config, port.config
235
154
  assert_equal 1, config.ports.size
236
155
  end
237
156
 
@@ -262,7 +181,7 @@ class ConfigTest < MiniTest::Unit::TestCase
262
181
  assert_equal 5269, port.port
263
182
  assert_equal 131_072, port.max_stanza_size
264
183
  assert_equal Vines::Stream::Server, port.stream
265
- assert_same config, port.config
184
+ assert_same config, port.config
266
185
  assert_equal 1, config.ports.size
267
186
  end
268
187
 
@@ -286,7 +205,7 @@ class ConfigTest < MiniTest::Unit::TestCase
286
205
  assert_equal 42, port.port
287
206
  assert_equal 60_000, port.max_stanza_size
288
207
  assert_equal Vines::Stream::Server, port.stream
289
- assert_same config, port.config
208
+ assert_same config, port.config
290
209
  assert_equal 1, config.ports.size
291
210
  end
292
211
 
@@ -306,9 +225,8 @@ class ConfigTest < MiniTest::Unit::TestCase
306
225
  assert_equal 5, port.max_resources_per_account
307
226
  assert_equal File.join(Dir.pwd, 'web'), port.root
308
227
  assert_equal '/xmpp', port.bind
309
- refute port.private_storage?
310
228
  assert_equal Vines::Stream::Http, port.stream
311
- assert_same config, port.config
229
+ assert_same config, port.config
312
230
  assert_equal 1, config.ports.size
313
231
  end
314
232
 
@@ -319,7 +237,6 @@ class ConfigTest < MiniTest::Unit::TestCase
319
237
  end
320
238
  http '0.0.0.1', 42 do
321
239
  bind '/custom'
322
- private_storage true
323
240
  max_stanza_size 60_000
324
241
  max_resources_per_account 1
325
242
  root '/var/www/html'
@@ -334,9 +251,8 @@ class ConfigTest < MiniTest::Unit::TestCase
334
251
  assert_equal 1, port.max_resources_per_account
335
252
  assert_equal '/var/www/html', port.root
336
253
  assert_equal '/custom', port.bind
337
- assert port.private_storage?
338
254
  assert_equal Vines::Stream::Http, port.stream
339
- assert_same config, port.config
255
+ assert_same config, port.config
340
256
  assert_equal 1, config.ports.size
341
257
  end
342
258
 
@@ -349,14 +265,12 @@ class ConfigTest < MiniTest::Unit::TestCase
349
265
  end
350
266
  port = config.ports.first
351
267
  refute_nil port
352
- assert port.components.empty?
353
- assert_nil port.password('bogus')
354
268
  assert_equal Vines::Config::ComponentPort, port.class
355
269
  assert_equal '0.0.0.0', port.host
356
270
  assert_equal 5347, port.port
357
271
  assert_equal 131_072, port.max_stanza_size
358
272
  assert_equal Vines::Stream::Component, port.stream
359
- assert_same config, port.config
273
+ assert_same config, port.config
360
274
  assert_equal 1, config.ports.size
361
275
  end
362
276
 
@@ -367,22 +281,16 @@ class ConfigTest < MiniTest::Unit::TestCase
367
281
  end
368
282
  component '0.0.0.1', 42 do
369
283
  max_stanza_size 60_000
370
- components 'tea.wonderland.lit' => 'secr3t',
371
- 'cake.wonderland.lit' => 'passw0rd'
372
284
  end
373
285
  end
374
286
  port = config.ports.first
375
287
  refute_nil port
376
- assert_equal 2, port.components.size
377
- assert_equal 'secr3t', port.password('tea.wonderland.lit')
378
- assert_equal 'passw0rd', port.password('cake.wonderland.lit')
379
- assert_nil port.password('bogus')
380
288
  assert_equal Vines::Config::ComponentPort, port.class
381
289
  assert_equal '0.0.0.1', port.host
382
290
  assert_equal 42, port.port
383
291
  assert_equal 60_000, port.max_stanza_size
384
292
  assert_equal Vines::Stream::Component, port.stream
385
- assert_same config, port.config
293
+ assert_same config, port.config
386
294
  assert_equal 1, config.ports.size
387
295
  end
388
296
 
@@ -406,4 +314,237 @@ class ConfigTest < MiniTest::Unit::TestCase
406
314
  end
407
315
  assert_equal Logger::ERROR, Class.new.extend(Vines::Log).log.level
408
316
  end
317
+
318
+ def test_cross_domain_messages
319
+ config = Vines::Config.new do
320
+ host 'wonderland.lit' do
321
+ storage(:fs) { dir '.' }
322
+ end
323
+ host 'verona.lit' do
324
+ cross_domain_messages true
325
+ storage(:fs) { dir '.' }
326
+ end
327
+ end
328
+ refute config.vhosts['wonderland.lit'].cross_domain_messages?
329
+ assert config.vhosts['verona.lit'].cross_domain_messages?
330
+ end
331
+
332
+ def test_local_jid?
333
+ config = Vines::Config.new do
334
+ host 'wonderland.lit', 'verona.lit' do
335
+ storage(:fs) { dir '.' }
336
+ end
337
+ end
338
+ refute config.local_jid?(nil)
339
+ refute config.local_jid?('alice@wonderland.lit', nil)
340
+ assert config.local_jid?('alice@wonderland.lit')
341
+ assert config.local_jid?('alice@wonderland.lit', 'romeo@verona.lit')
342
+ refute config.local_jid?('alice@wonderland.lit', 'romeo@bogus.lit')
343
+ refute config.local_jid?('alice@tea.wonderland.lit')
344
+ refute config.local_jid?('alice@bogus.lit')
345
+ end
346
+
347
+ def test_missing_addresses_not_allowed
348
+ config = Vines::Config.new do
349
+ host 'wonderland.lit', 'verona.lit' do
350
+ storage(:fs) { dir '.' }
351
+ end
352
+ end
353
+ refute config.allowed?(nil, nil)
354
+ refute config.allowed?('', '')
355
+ end
356
+
357
+ def test_same_domain_allowed
358
+ config = Vines::Config.new do
359
+ host 'wonderland.lit', 'verona.lit' do
360
+ storage(:fs) { dir '.' }
361
+ end
362
+ end
363
+ alice = Vines::JID.new('alice@wonderland.lit')
364
+ hatter = Vines::JID.new('hatter@wonderland.lit')
365
+ assert config.allowed?(alice, hatter)
366
+ end
367
+
368
+ def test_both_vhosts_with_cross_domain_allowed
369
+ config = Vines::Config.new do
370
+ host 'wonderland.lit', 'verona.lit' do
371
+ cross_domain_messages true
372
+ storage(:fs) { dir '.' }
373
+ end
374
+ end
375
+ alice = Vines::JID.new('alice@wonderland.lit')
376
+ romeo = Vines::JID.new('romeo@verona.lit')
377
+ assert config.allowed?(alice, romeo)
378
+ assert config.allowed?(romeo, alice)
379
+ end
380
+
381
+ def test_one_vhost_with_cross_domain_not_allowed
382
+ config = Vines::Config.new do
383
+ host 'wonderland.lit' do
384
+ cross_domain_messages true
385
+ storage(:fs) { dir '.' }
386
+ end
387
+ host 'verona.lit' do
388
+ cross_domain_messages false
389
+ storage(:fs) { dir '.' }
390
+ end
391
+ end
392
+ alice = Vines::JID.new('alice@wonderland.lit')
393
+ romeo = Vines::JID.new('romeo@verona.lit')
394
+ refute config.allowed?(alice, romeo)
395
+ refute config.allowed?(romeo, alice)
396
+ end
397
+
398
+ def test_same_domain_component_to_component_allowed
399
+ config = Vines::Config.new do
400
+ host 'wonderland.lit' do
401
+ cross_domain_messages false
402
+ storage(:fs) { dir '.' }
403
+ components 'tea' => 'secr3t', cake: 'passw0rd'
404
+ end
405
+ end
406
+ alice = Vines::JID.new('alice@tea.wonderland.lit')
407
+ hatter = Vines::JID.new('hatter@cake.wonderland.lit')
408
+ assert config.allowed?(alice, alice)
409
+ assert config.allowed?(alice, hatter)
410
+ assert config.allowed?(hatter, alice)
411
+ end
412
+
413
+ def test_cross_domain_component_to_component_allowed
414
+ config = Vines::Config.new do
415
+ host 'wonderland.lit', 'verona.lit' do
416
+ cross_domain_messages true
417
+ storage(:fs) { dir '.' }
418
+ components 'tea' => 'secr3t', cake: 'passw0rd'
419
+ end
420
+ end
421
+ alice = Vines::JID.new('alice@tea.wonderland.lit')
422
+ romeo = Vines::JID.new('romeo@cake.verona.lit')
423
+ assert config.allowed?(alice, romeo)
424
+ assert config.allowed?(romeo, alice)
425
+ end
426
+
427
+ def test_cross_domain_component_to_component_not_allowed
428
+ config = Vines::Config.new do
429
+ host 'wonderland.lit' do
430
+ cross_domain_messages true
431
+ storage(:fs) { dir '.' }
432
+ components 'tea' => 'secr3t', cake: 'passw0rd'
433
+ end
434
+ end
435
+ config = Vines::Config.new do
436
+ host 'verona.lit' do
437
+ cross_domain_messages false
438
+ storage(:fs) { dir '.' }
439
+ components 'party' => 'secr3t'
440
+ end
441
+ end
442
+ alice = Vines::JID.new('alice@tea.wonderland.lit')
443
+ romeo = Vines::JID.new('romeo@party.verona.lit')
444
+ refute config.allowed?(alice, romeo)
445
+ refute config.allowed?(romeo, alice)
446
+ end
447
+
448
+ def test_same_domain_user_to_component_allowed
449
+ config = Vines::Config.new do
450
+ host 'wonderland.lit' do
451
+ cross_domain_messages false
452
+ storage(:fs) { dir '.' }
453
+ components 'tea' => 'secr3t', cake: 'passw0rd'
454
+ end
455
+ end
456
+ alice = Vines::JID.new('alice@wonderland.lit')
457
+ comp = Vines::JID.new('hatter@cake.wonderland.lit')
458
+ assert config.allowed?(alice, comp)
459
+ assert config.allowed?(comp, alice)
460
+ end
461
+
462
+ def test_cross_domain_user_to_component_allowed
463
+ config = Vines::Config.new do
464
+ host 'wonderland.lit', 'verona.lit' do
465
+ cross_domain_messages true
466
+ storage(:fs) { dir '.' }
467
+ components 'tea' => 'secr3t', cake: 'passw0rd'
468
+ end
469
+ end
470
+ alice = Vines::JID.new('alice@tea.wonderland.lit')
471
+ romeo = Vines::JID.new('romeo@verona.lit')
472
+ assert config.allowed?(alice, romeo)
473
+ assert config.allowed?(romeo, alice)
474
+ end
475
+
476
+ def test_cross_domain_user_to_component_not_allowed
477
+ config = Vines::Config.new do
478
+ host 'wonderland.lit' do
479
+ cross_domain_messages true
480
+ storage(:fs) { dir '.' }
481
+ components 'tea' => 'secr3t', cake: 'passw0rd'
482
+ end
483
+ end
484
+ config = Vines::Config.new do
485
+ host 'verona.lit' do
486
+ cross_domain_messages false
487
+ storage(:fs) { dir '.' }
488
+ end
489
+ end
490
+ alice = Vines::JID.new('alice@tea.wonderland.lit')
491
+ romeo = Vines::JID.new('romeo@verona.lit')
492
+ refute config.allowed?(alice, romeo)
493
+ refute config.allowed?(romeo, alice)
494
+ end
495
+
496
+ def test_remote_user_to_component_allowed
497
+ config = Vines::Config.new do
498
+ host 'wonderland.lit' do
499
+ cross_domain_messages true
500
+ storage(:fs) { dir '.' }
501
+ components 'tea' => 'secr3t', cake: 'passw0rd'
502
+ end
503
+ host 'verona.lit' do
504
+ cross_domain_messages false
505
+ storage(:fs) { dir '.' }
506
+ components 'tea' => 'secr3t', cake: 'passw0rd'
507
+ end
508
+ end
509
+ alice = Vines::JID.new('alice@tea.wonderland.lit')
510
+ romeo = Vines::JID.new('romeo@tea.verona.lit')
511
+ hamlet = Vines::JID.new('hamlet@denmark.lit')
512
+ assert config.allowed?(alice, hamlet)
513
+ assert config.allowed?(hamlet, alice)
514
+ refute config.allowed?(romeo, hamlet)
515
+ refute config.allowed?(hamlet, romeo)
516
+ end
517
+
518
+ def test_remote_user_to_local_user_allowed
519
+ config = Vines::Config.new do
520
+ host 'wonderland.lit' do
521
+ cross_domain_messages true
522
+ storage(:fs) { dir '.' }
523
+ end
524
+ host 'verona.lit' do
525
+ cross_domain_messages false
526
+ storage(:fs) { dir '.' }
527
+ end
528
+ end
529
+ alice = Vines::JID.new('alice@wonderland.lit')
530
+ romeo = Vines::JID.new('romeo@verona.lit')
531
+ hamlet = Vines::JID.new('hamlet@denmark.lit')
532
+ assert config.allowed?(alice, hamlet)
533
+ assert config.allowed?(hamlet, alice)
534
+ refute config.allowed?(romeo, hamlet)
535
+ refute config.allowed?(hamlet, romeo)
536
+ end
537
+
538
+ def test_remote_user_to_remote_user_not_allowed
539
+ config = Vines::Config.new do
540
+ host 'wonderland.lit' do
541
+ cross_domain_messages true
542
+ storage(:fs) { dir '.' }
543
+ end
544
+ end
545
+ romeo = Vines::JID.new('romeo@verona.lit')
546
+ hamlet = Vines::JID.new('hamlet@denmark.lit')
547
+ refute config.allowed?(romeo, hamlet)
548
+ refute config.allowed?(hamlet, romeo)
549
+ end
409
550
  end