vines 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/Rakefile +12 -2
- data/conf/config.rb +1 -0
- data/lib/vines/config.rb +8 -0
- data/lib/vines/contact.rb +2 -4
- data/lib/vines/error.rb +1 -1
- data/lib/vines/router.rb +26 -18
- data/lib/vines/stanza/presence.rb +3 -1
- data/lib/vines/stanza.rb +8 -1
- data/lib/vines/stream/client/bind.rb +9 -1
- data/lib/vines/stream/client/session.rb +146 -0
- data/lib/vines/stream/client.rb +19 -78
- data/lib/vines/stream/component.rb +6 -2
- data/lib/vines/stream/http/auth.rb +22 -0
- data/lib/vines/stream/http/bind.rb +32 -0
- data/lib/vines/stream/http/bind_restart.rb +36 -0
- data/lib/vines/stream/http/ready.rb +25 -0
- data/lib/vines/stream/http/request.rb +33 -0
- data/lib/vines/stream/http/session.rb +116 -0
- data/lib/vines/stream/http/sessions.rb +65 -0
- data/lib/vines/stream/http/start.rb +23 -0
- data/lib/vines/stream/http.rb +119 -77
- data/lib/vines/stream/server.rb +8 -3
- data/lib/vines/stream/state.rb +6 -1
- data/lib/vines/stream.rb +31 -19
- data/lib/vines/user.rb +2 -4
- data/lib/vines/version.rb +1 -1
- data/lib/vines.rb +10 -4
- data/test/config_test.rb +34 -33
- data/test/contact_test.rb +42 -0
- data/test/error_test.rb +2 -2
- data/test/jid_test.rb +7 -7
- data/test/kit_test.rb +10 -10
- data/test/rake_test_loader.rb +9 -0
- data/test/router_test.rb +4 -3
- data/test/stanza/iq/roster_test.rb +8 -10
- data/test/stanza/iq/session_test.rb +2 -3
- data/test/stanza/iq/vcard_test.rb +4 -5
- data/test/stanza/message_test.rb +17 -11
- data/test/stanza/presence/subscribe_test.rb +3 -4
- data/test/storage/couchdb_test.rb +9 -10
- data/test/storage/ldap_test.rb +30 -37
- data/test/storage/local_test.rb +6 -6
- data/test/storage/redis_test.rb +6 -6
- data/test/storage/sql_test.rb +5 -5
- data/test/storage/storage_tests.rb +11 -11
- data/test/storage_test.rb +4 -5
- data/test/stream/client/auth_test.rb +15 -16
- data/test/stream/client/ready_test.rb +4 -5
- data/test/stream/client/session_test.rb +21 -0
- data/test/stream/component/handshake_test.rb +6 -7
- data/test/stream/component/ready_test.rb +9 -10
- data/test/stream/component/start_test.rb +6 -7
- data/test/stream/http/auth_test.rb +68 -0
- data/test/stream/http/ready_test.rb +56 -0
- data/test/stream/http/sessions_test.rb +50 -0
- data/test/stream/http/start_test.rb +51 -0
- data/test/stream/parser_test.rb +5 -5
- data/test/stream/server/outbound/auth_test.rb +12 -13
- data/test/stream/server/ready_test.rb +10 -11
- data/test/token_bucket_test.rb +7 -7
- data/test/user_test.rb +8 -6
- metadata +45 -14
- data/lib/vines/stream/http/http_request.rb +0 -22
- data/lib/vines/stream/http/http_state.rb +0 -139
- data/lib/vines/stream/http/http_states.rb +0 -53
data/test/storage/ldap_test.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require 'vines'
|
4
|
-
require 'minitest/
|
5
|
-
require 'test/unit'
|
4
|
+
require 'minitest/autorun'
|
6
5
|
|
7
|
-
class LdapTest <
|
6
|
+
class LdapTest < MiniTest::Unit::TestCase
|
8
7
|
ALICE_DN = 'uid=alice@wondlerand.lit,ou=People,dc=wonderland,dc=lit'
|
9
8
|
CONTEXT = {}
|
10
9
|
|
@@ -29,31 +28,27 @@ class LdapTest < Test::Unit::TestCase
|
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
name_attr 'cn'
|
42
|
-
end
|
31
|
+
def test_default_host_and_port_raises_no_errors
|
32
|
+
Vines::Storage::Ldap.new do
|
33
|
+
tls true
|
34
|
+
dn 'cn=Directory Manager'
|
35
|
+
password 'secr3t'
|
36
|
+
basedn 'dc=wonderland,dc=lit'
|
37
|
+
object_class 'person'
|
38
|
+
user_attr 'uid'
|
39
|
+
name_attr 'cn'
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
name_attr 'cn'
|
56
|
-
end
|
43
|
+
def test_configured_host_and_port_raises_no_errors
|
44
|
+
Vines::Storage::Ldap.new('0.0.0.1', 42) do
|
45
|
+
tls true
|
46
|
+
dn 'cn=Directory Manager'
|
47
|
+
password 'secr3t'
|
48
|
+
basedn 'dc=wonderland,dc=lit'
|
49
|
+
object_class 'person'
|
50
|
+
user_attr 'uid'
|
51
|
+
name_attr 'cn'
|
57
52
|
end
|
58
53
|
end
|
59
54
|
|
@@ -78,17 +73,15 @@ class LdapTest < Test::Unit::TestCase
|
|
78
73
|
end
|
79
74
|
|
80
75
|
# Make sure we properly handle boolean false values.
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
name_attr 'cn'
|
91
|
-
end
|
76
|
+
def test_false_tls_raises_no_errors
|
77
|
+
Vines::Storage::Ldap.new do
|
78
|
+
tls false
|
79
|
+
dn 'cn=Directory Manager'
|
80
|
+
password 'secr3t'
|
81
|
+
basedn 'dc=wonderland,dc=lit'
|
82
|
+
object_class 'person'
|
83
|
+
user_attr 'uid'
|
84
|
+
name_attr 'cn'
|
92
85
|
end
|
93
86
|
end
|
94
87
|
|
@@ -181,7 +174,7 @@ class LdapTest < Test::Unit::TestCase
|
|
181
174
|
mock.expect(:bind, true)
|
182
175
|
end
|
183
176
|
user = ldap.authenticate('alice@wonderland.lit', 'passw0rd')
|
184
|
-
|
177
|
+
refute_nil user
|
185
178
|
assert_equal 'alice@wonderland.lit', user.jid.to_s
|
186
179
|
assert_equal 'Alice Liddell', user.name
|
187
180
|
assert_equal [], user.roster
|
data/test/storage/local_test.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'storage_tests'
|
4
4
|
require 'vines'
|
5
|
-
require '
|
5
|
+
require 'minitest/autorun'
|
6
6
|
|
7
|
-
class LocalTest <
|
7
|
+
class LocalTest < MiniTest::Unit::TestCase
|
8
8
|
include StorageTests
|
9
9
|
|
10
10
|
def setup
|
@@ -46,9 +46,9 @@ class LocalTest < Test::Unit::TestCase
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_init
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
assert_raises(RuntimeError) { Vines::Storage::Local.new {} }
|
50
|
+
assert_raises(RuntimeError) { Vines::Storage::Local.new { dir 'bogus' } }
|
51
|
+
assert_raises(RuntimeError) { Vines::Storage::Local.new { dir '/sbin' } }
|
52
|
+
Vines::Storage::Local.new { dir '.' } # shouldn't raise an error
|
53
53
|
end
|
54
54
|
end
|
data/test/storage/redis_test.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'storage_tests'
|
4
4
|
require 'vines'
|
5
|
-
require '
|
5
|
+
require 'minitest/autorun'
|
6
6
|
|
7
|
-
class RedisTest <
|
7
|
+
class RedisTest < MiniTest::Unit::TestCase
|
8
8
|
include StorageTests
|
9
9
|
|
10
10
|
MOCK_REDIS = Class.new do
|
@@ -65,11 +65,11 @@ class RedisTest < Test::Unit::TestCase
|
|
65
65
|
storage
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
68
|
+
def test_init_raises_no_errors
|
69
69
|
EMLoop.new do
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
Vines::Storage::Redis.new {}
|
71
|
+
Vines::Storage::Redis.new { host 'localhost' }
|
72
|
+
Vines::Storage::Redis.new { host'localhost'; port '6379' }
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
data/test/storage/sql_test.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'storage_tests'
|
4
4
|
require 'vines'
|
5
|
-
require '
|
5
|
+
require 'minitest/autorun'
|
6
6
|
|
7
|
-
class SqlTest <
|
7
|
+
class SqlTest < MiniTest::Unit::TestCase
|
8
8
|
include StorageTests
|
9
9
|
|
10
10
|
DB_FILE = "./xmpp_testcase.db"
|
@@ -48,8 +48,8 @@ class SqlTest < Test::Unit::TestCase
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_init
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
assert_raises(RuntimeError) { Vines::Storage::Sql.new {} }
|
52
|
+
assert_raises(RuntimeError) { Vines::Storage::Sql.new { adapter 'postgresql' } }
|
53
|
+
Vines::Storage::Sql.new { adapter 'sqlite3'; database ':memory:' } # shouldn't raise an error
|
54
54
|
end
|
55
55
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'vines'
|
4
4
|
require 'ext/nokogiri'
|
5
|
-
require '
|
5
|
+
require 'minitest/autorun'
|
6
6
|
|
7
7
|
# Mixin methods for storage implementation test classes. The behavioral
|
8
8
|
# tests are the same regardless of implementation so share those methods
|
@@ -37,11 +37,11 @@ module StorageTests
|
|
37
37
|
assert_nil db.authenticate('clear_password@wonderland.lit', 'secret')
|
38
38
|
|
39
39
|
user = db.authenticate('bcrypt_password@wonderland.lit', 'secret')
|
40
|
-
|
40
|
+
refute_nil user
|
41
41
|
assert_equal('bcrypt_password@wonderland.lit', user.jid.to_s)
|
42
42
|
|
43
43
|
user = db.authenticate('full@wonderland.lit', 'secret')
|
44
|
-
|
44
|
+
refute_nil user
|
45
45
|
assert_equal 'Tester', user.name
|
46
46
|
assert_equal 'full@wonderland.lit', user.jid.to_s
|
47
47
|
|
@@ -67,15 +67,15 @@ module StorageTests
|
|
67
67
|
assert_nil user
|
68
68
|
|
69
69
|
user = db.find_user('full@wonderland.lit')
|
70
|
-
|
70
|
+
refute_nil user
|
71
71
|
assert_equal 'full@wonderland.lit', user.jid.to_s
|
72
72
|
|
73
73
|
user = db.find_user(Vines::JID.new('full@wonderland.lit'))
|
74
|
-
|
74
|
+
refute_nil user
|
75
75
|
assert_equal 'full@wonderland.lit', user.jid.to_s
|
76
76
|
|
77
77
|
user = db.find_user(Vines::JID.new('full@wonderland.lit/resource'))
|
78
|
-
|
78
|
+
refute_nil user
|
79
79
|
assert_equal 'full@wonderland.lit', user.jid.to_s
|
80
80
|
end
|
81
81
|
end
|
@@ -92,7 +92,7 @@ module StorageTests
|
|
92
92
|
:name => 'Contact 1')
|
93
93
|
db.save_user(user)
|
94
94
|
user = db.find_user('save_user@domain.tld')
|
95
|
-
|
95
|
+
refute_nil user
|
96
96
|
assert_equal 'save_user@domain.tld', user.jid.to_s
|
97
97
|
assert_equal 'Save User', user.name
|
98
98
|
assert_equal 1, user.roster.length
|
@@ -108,15 +108,15 @@ module StorageTests
|
|
108
108
|
assert_nil card
|
109
109
|
|
110
110
|
card = db.find_vcard('full@wonderland.lit')
|
111
|
-
|
111
|
+
refute_nil card
|
112
112
|
assert_equal VCARD, card
|
113
113
|
|
114
114
|
card = db.find_vcard(Vines::JID.new('full@wonderland.lit'))
|
115
|
-
|
115
|
+
refute_nil card
|
116
116
|
assert_equal VCARD, card
|
117
117
|
|
118
118
|
card = db.find_vcard(Vines::JID.new('full@wonderland.lit/resource'))
|
119
|
-
|
119
|
+
refute_nil card
|
120
120
|
assert_equal VCARD, card
|
121
121
|
end
|
122
122
|
end
|
@@ -127,7 +127,7 @@ module StorageTests
|
|
127
127
|
db.save_user(Vines::User.new(:jid => 'save_user@domain.tld'))
|
128
128
|
db.save_vcard('save_user@domain.tld/resource1', VCARD)
|
129
129
|
card = db.find_vcard('save_user@domain.tld')
|
130
|
-
|
130
|
+
refute_nil card
|
131
131
|
assert_equal VCARD, card
|
132
132
|
end
|
133
133
|
end
|
data/test/storage_test.rb
CHANGED
@@ -2,10 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'storage_tests'
|
4
4
|
require 'vines'
|
5
|
-
require 'minitest/
|
6
|
-
require 'test/unit'
|
5
|
+
require 'minitest/autorun'
|
7
6
|
|
8
|
-
class StorageTest <
|
7
|
+
class StorageTest < MiniTest::Unit::TestCase
|
9
8
|
ALICE = 'alice@wonderland.lit'.freeze
|
10
9
|
|
11
10
|
class MockLdapStorage < Vines::Storage
|
@@ -64,7 +63,7 @@ class StorageTest < Test::Unit::TestCase
|
|
64
63
|
storage = MockLdapStorage.new(alice)
|
65
64
|
storage.ldap.expect(:authenticate, alice, [ALICE, 'secr3t'])
|
66
65
|
user = storage.authenticate(ALICE, 'secr3t')
|
67
|
-
|
66
|
+
refute_nil user
|
68
67
|
assert_equal ALICE, user.jid.to_s
|
69
68
|
assert_equal 0, storage.authenticate_calls
|
70
69
|
assert_equal 1, storage.find_user_calls
|
@@ -79,7 +78,7 @@ class StorageTest < Test::Unit::TestCase
|
|
79
78
|
storage = MockLdapStorage.new
|
80
79
|
storage.ldap.expect(:authenticate, alice, [ALICE, 'secr3t'])
|
81
80
|
user = storage.authenticate(ALICE, 'secr3t')
|
82
|
-
|
81
|
+
refute_nil user
|
83
82
|
assert_equal ALICE, user.jid.to_s
|
84
83
|
assert_equal 0, storage.authenticate_calls
|
85
84
|
assert_equal 1, storage.find_user_calls
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require 'vines'
|
4
|
-
require 'minitest/
|
5
|
-
require 'test/unit'
|
4
|
+
require 'minitest/autorun'
|
6
5
|
|
7
|
-
class ClientAuthTest <
|
6
|
+
class ClientAuthTest < MiniTest::Unit::TestCase
|
8
7
|
# disable logging for tests
|
9
8
|
Class.new.extend(Vines::Log).log.level = Logger::FATAL
|
10
9
|
|
@@ -34,42 +33,42 @@ class ClientAuthTest < Test::Unit::TestCase
|
|
34
33
|
|
35
34
|
def test_invalid_element
|
36
35
|
node = node('<bogus/>')
|
37
|
-
|
36
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
38
37
|
end
|
39
38
|
|
40
39
|
def test_invalid_sasl_element
|
41
40
|
node = node(%Q{<bogus xmlns="#{Vines::NAMESPACES[:sasl]}"/>})
|
42
|
-
|
41
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
43
42
|
end
|
44
43
|
|
45
44
|
def test_missing_namespace
|
46
45
|
node = node('<auth/>')
|
47
|
-
|
46
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
48
47
|
end
|
49
48
|
|
50
49
|
def test_invalid_namespace
|
51
50
|
node = node('<auth xmlns="bogus"/>')
|
52
|
-
|
51
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
53
52
|
end
|
54
53
|
|
55
54
|
def test_missing_mechanism
|
56
55
|
@stream.expect(:error, nil, [Vines::SaslErrors::InvalidMechanism.new])
|
57
56
|
node = node(%Q{<auth xmlns="#{Vines::NAMESPACES[:sasl]}">tokens</auth>})
|
58
|
-
|
57
|
+
@state.node(node)
|
59
58
|
assert @stream.verify
|
60
59
|
end
|
61
60
|
|
62
61
|
def test_invalid_mechanism
|
63
62
|
@stream.expect(:error, nil, [Vines::SaslErrors::InvalidMechanism.new])
|
64
63
|
node = node(%Q{<auth xmlns="#{Vines::NAMESPACES[:sasl]}" mechanism="bogus">tokens</auth>})
|
65
|
-
|
64
|
+
@state.node(node)
|
66
65
|
assert @stream.verify
|
67
66
|
end
|
68
67
|
|
69
68
|
def test_missing_text
|
70
69
|
@stream.expect(:error, nil, [Vines::SaslErrors::MalformedRequest.new])
|
71
70
|
node = node(%Q{<auth xmlns="#{Vines::NAMESPACES[:sasl]}" mechanism="PLAIN"></auth>})
|
72
|
-
|
71
|
+
@state.node(node)
|
73
72
|
assert @stream.verify
|
74
73
|
end
|
75
74
|
|
@@ -77,7 +76,7 @@ class ClientAuthTest < Test::Unit::TestCase
|
|
77
76
|
@stream.expect(:storage, MockStorage.new(true))
|
78
77
|
@stream.expect(:error, nil, [Vines::SaslErrors::TemporaryAuthFailure.new])
|
79
78
|
node = node(%Q{<auth xmlns="#{Vines::NAMESPACES[:sasl]}" mechanism="PLAIN">tokens</auth>})
|
80
|
-
|
79
|
+
@state.node(node)
|
81
80
|
assert @stream.verify
|
82
81
|
end
|
83
82
|
|
@@ -85,7 +84,7 @@ class ClientAuthTest < Test::Unit::TestCase
|
|
85
84
|
@stream.expect(:storage, MockStorage.new)
|
86
85
|
@stream.expect(:error, nil, [Vines::SaslErrors::NotAuthorized.new])
|
87
86
|
node = node(%Q{<auth xmlns="#{Vines::NAMESPACES[:sasl]}" mechanism="PLAIN">#{Base64.encode64("alice@wonderland.lit\000\000bogus")}</auth>})
|
88
|
-
|
87
|
+
@state.node(node)
|
89
88
|
assert @stream.verify
|
90
89
|
end
|
91
90
|
|
@@ -97,7 +96,7 @@ class ClientAuthTest < Test::Unit::TestCase
|
|
97
96
|
@stream.expect(:write, nil, [%Q{<success xmlns="#{Vines::NAMESPACES[:sasl]}"/>}])
|
98
97
|
@stream.expect(:advance, nil, [Vines::Stream::Client::BindRestart.new(@stream)])
|
99
98
|
node = node(%Q{<auth xmlns="#{Vines::NAMESPACES[:sasl]}" mechanism="PLAIN">#{Base64.encode64("alice@wonderland.lit\000\000secr3t")}</auth>})
|
100
|
-
|
99
|
+
@state.node(node)
|
101
100
|
assert @stream.verify
|
102
101
|
end
|
103
102
|
|
@@ -108,14 +107,14 @@ class ClientAuthTest < Test::Unit::TestCase
|
|
108
107
|
end
|
109
108
|
|
110
109
|
@stream.expect(:error, nil, [Vines::SaslErrors::NotAuthorized.new])
|
111
|
-
|
110
|
+
@state.node(node.call)
|
112
111
|
assert @stream.verify
|
113
112
|
|
114
|
-
|
113
|
+
@state.node(node.call)
|
115
114
|
assert @stream.verify
|
116
115
|
|
117
116
|
@stream.expect(:error, nil, [Vines::StreamErrors::PolicyViolation.new])
|
118
|
-
|
117
|
+
@state.node(node.call)
|
119
118
|
assert @stream.verify
|
120
119
|
end
|
121
120
|
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require 'vines'
|
4
|
-
require 'minitest/
|
5
|
-
require 'test/unit'
|
4
|
+
require 'minitest/autorun'
|
6
5
|
|
7
|
-
class ClientReadyTest <
|
6
|
+
class ClientReadyTest < MiniTest::Unit::TestCase
|
8
7
|
STANZAS = []
|
9
8
|
|
10
9
|
def setup
|
@@ -28,14 +27,14 @@ class ClientReadyTest < Test::Unit::TestCase
|
|
28
27
|
|
29
28
|
def test_good_node_processes
|
30
29
|
node = node('<message/>')
|
31
|
-
|
30
|
+
@state.node(node)
|
32
31
|
assert_equal 1, STANZAS.size
|
33
32
|
assert STANZAS.map {|s| s.verify }.all?
|
34
33
|
end
|
35
34
|
|
36
35
|
def test_unsupported_stanza_type
|
37
36
|
node = node('<bogus/>')
|
38
|
-
|
37
|
+
assert_raises(Vines::StreamErrors::UnsupportedStanzaType) { @state.node(node) }
|
39
38
|
assert STANZAS.empty?
|
40
39
|
end
|
41
40
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'vines'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
class ClientSessionTest < MiniTest::Unit::TestCase
|
7
|
+
def test_equality
|
8
|
+
one = Vines::Stream::Client::Session.new(nil)
|
9
|
+
two = Vines::Stream::Client::Session.new(nil)
|
10
|
+
|
11
|
+
assert_nil one <=> 42
|
12
|
+
|
13
|
+
assert one == one
|
14
|
+
assert one.eql?(one)
|
15
|
+
assert one.hash == one.hash
|
16
|
+
|
17
|
+
refute one == two
|
18
|
+
refute one.eql?(two)
|
19
|
+
refute one.hash == two.hash
|
20
|
+
end
|
21
|
+
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require 'vines'
|
4
|
-
require 'minitest/
|
5
|
-
require 'test/unit'
|
4
|
+
require 'minitest/autorun'
|
6
5
|
|
7
|
-
class HandshakeTest <
|
6
|
+
class HandshakeTest < MiniTest::Unit::TestCase
|
8
7
|
def setup
|
9
8
|
@stream = MiniTest::Mock.new
|
10
9
|
@state = Vines::Stream::Component::Handshake.new(@stream)
|
@@ -12,20 +11,20 @@ class HandshakeTest < Test::Unit::TestCase
|
|
12
11
|
|
13
12
|
def test_invalid_element
|
14
13
|
node = node('<message/>')
|
15
|
-
|
14
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
16
15
|
end
|
17
16
|
|
18
17
|
def test_missing_text
|
19
18
|
@stream.expect(:secret, 'secr3t')
|
20
19
|
node = node('<handshake/>')
|
21
|
-
|
20
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
22
21
|
assert @stream.verify
|
23
22
|
end
|
24
23
|
|
25
24
|
def test_invalid_secret
|
26
25
|
@stream.expect(:secret, 'secr3t')
|
27
26
|
node = node('<handshake>bogus</handshake>')
|
28
|
-
|
27
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
29
28
|
assert @stream.verify
|
30
29
|
end
|
31
30
|
|
@@ -34,7 +33,7 @@ class HandshakeTest < Test::Unit::TestCase
|
|
34
33
|
@stream.expect(:write, nil, ['<handshake/>'])
|
35
34
|
@stream.expect(:advance, nil, [Vines::Stream::Component::Ready.new(@stream)])
|
36
35
|
node = node('<handshake>secr3t</handshake>')
|
37
|
-
|
36
|
+
@state.node(node)
|
38
37
|
assert @stream.verify
|
39
38
|
end
|
40
39
|
|
@@ -2,10 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'vines'
|
4
4
|
require 'ext/nokogiri'
|
5
|
-
require 'minitest/
|
6
|
-
require 'test/unit'
|
5
|
+
require 'minitest/autorun'
|
7
6
|
|
8
|
-
class ComponentReadyTest <
|
7
|
+
class ComponentReadyTest < MiniTest::Unit::TestCase
|
9
8
|
STANZAS = []
|
10
9
|
|
11
10
|
def setup
|
@@ -34,7 +33,7 @@ class ComponentReadyTest < Test::Unit::TestCase
|
|
34
33
|
|
35
34
|
def test_missing_to_and_from_addresses
|
36
35
|
node = node('<message/>')
|
37
|
-
|
36
|
+
assert_raises(Vines::StreamErrors::ImproperAddressing) { @state.node(node) }
|
38
37
|
assert_equal 1, STANZAS.size
|
39
38
|
assert @stream.verify
|
40
39
|
end
|
@@ -42,14 +41,14 @@ class ComponentReadyTest < Test::Unit::TestCase
|
|
42
41
|
def test_missing_from_address
|
43
42
|
@stream.expect(:remote_domain, 'tea.wonderland.lit')
|
44
43
|
node = node(%q{<message to="hatter@wonderland.lit"/>})
|
45
|
-
|
44
|
+
assert_raises(Vines::StreamErrors::ImproperAddressing) { @state.node(node) }
|
46
45
|
assert_equal 1, STANZAS.size
|
47
46
|
assert @stream.verify
|
48
47
|
end
|
49
48
|
|
50
49
|
def test_missing_to_address
|
51
50
|
node = node(%q{<message from="alice@tea.wonderland.lit"/>})
|
52
|
-
|
51
|
+
assert_raises(Vines::StreamErrors::ImproperAddressing) { @state.node(node) }
|
53
52
|
assert_equal 1, STANZAS.size
|
54
53
|
assert @stream.verify
|
55
54
|
end
|
@@ -57,14 +56,14 @@ class ComponentReadyTest < Test::Unit::TestCase
|
|
57
56
|
def test_invalid_from_address
|
58
57
|
@stream.expect(:remote_domain, 'tea.wonderland.lit')
|
59
58
|
node = node(%q{<message from="alice@bogus.wonderland.lit" to="hatter@wonderland.lit"/>})
|
60
|
-
|
59
|
+
assert_raises(Vines::StreamErrors::ImproperAddressing) { @state.node(node) }
|
61
60
|
assert_equal 1, STANZAS.size
|
62
61
|
assert @stream.verify
|
63
62
|
end
|
64
63
|
|
65
64
|
def test_unsupported_stanza_type
|
66
65
|
node = node('<bogus/>')
|
67
|
-
|
66
|
+
assert_raises(Vines::StreamErrors::UnsupportedStanzaType) { @state.node(node) }
|
68
67
|
assert STANZAS.empty?
|
69
68
|
assert @stream.verify
|
70
69
|
end
|
@@ -72,7 +71,7 @@ class ComponentReadyTest < Test::Unit::TestCase
|
|
72
71
|
def test_remote_message_routes
|
73
72
|
@stream.expect(:remote_domain, 'tea.wonderland.lit')
|
74
73
|
node = node(%q{<message from="alice@tea.wonderland.lit" to="romeo@verona.lit"/>})
|
75
|
-
|
74
|
+
@state.node(node)
|
76
75
|
assert_equal 1, STANZAS.size
|
77
76
|
assert STANZAS.map {|s| s.verify }.all?
|
78
77
|
assert @stream.verify
|
@@ -89,7 +88,7 @@ class ComponentReadyTest < Test::Unit::TestCase
|
|
89
88
|
@router.expect(:connected_resources, [@recipient], ['hatter@wonderland.lit'])
|
90
89
|
@stream.expect(:router, @router)
|
91
90
|
|
92
|
-
|
91
|
+
@state.node(node)
|
93
92
|
assert_equal 1, STANZAS.size
|
94
93
|
assert STANZAS.map {|s| s.verify }.all?
|
95
94
|
assert @stream.verify
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require 'vines'
|
4
|
-
require 'minitest/
|
5
|
-
require 'test/unit'
|
4
|
+
require 'minitest/autorun'
|
6
5
|
|
7
|
-
class ComponentStartTest <
|
6
|
+
class ComponentStartTest < MiniTest::Unit::TestCase
|
8
7
|
def setup
|
9
8
|
@stream = MiniTest::Mock.new
|
10
9
|
@state = Vines::Stream::Component::Start.new(@stream)
|
@@ -12,24 +11,24 @@ class ComponentStartTest < Test::Unit::TestCase
|
|
12
11
|
|
13
12
|
def test_invalid_element
|
14
13
|
node = node('<message/>')
|
15
|
-
|
14
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
16
15
|
end
|
17
16
|
|
18
17
|
def test_missing_stream_namespace
|
19
18
|
node = node('<stream:stream/>')
|
20
|
-
|
19
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
21
20
|
end
|
22
21
|
|
23
22
|
def test_invalid_stream_namespace
|
24
23
|
node = node('<stream:stream xmlns="bogus"/>')
|
25
|
-
|
24
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
26
25
|
end
|
27
26
|
|
28
27
|
def test_valid_stream_header
|
29
28
|
node = node(%q{<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:component:accept" to="tea.wonderland.lit"/>})
|
30
29
|
@stream.expect(:start, nil, [node])
|
31
30
|
@stream.expect(:advance, nil, [Vines::Stream::Component::Handshake.new(@stream)])
|
32
|
-
|
31
|
+
@state.node(node)
|
33
32
|
assert @stream.verify
|
34
33
|
end
|
35
34
|
|