vines 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README.md +48 -0
- data/Rakefile +6 -58
- data/bin/vines +12 -2
- data/conf/certs/ca-bundle.crt +568 -39
- data/conf/config.rb +9 -42
- data/lib/vines.rb +1 -8
- data/lib/vines/command/cert.rb +4 -4
- data/lib/vines/command/init.rb +3 -3
- data/lib/vines/config.rb +9 -0
- data/lib/vines/kit.rb +2 -7
- data/lib/vines/storage/local.rb +50 -17
- data/lib/vines/store.rb +6 -4
- data/lib/vines/stream.rb +1 -1
- data/lib/vines/stream/http/session.rb +0 -0
- data/lib/vines/stream/http/sessions.rb +0 -0
- data/lib/vines/stream/parser.rb +3 -2
- data/lib/vines/token_bucket.rb +19 -10
- data/lib/vines/version.rb +1 -1
- data/test/cluster/publisher_test.rb +45 -33
- data/test/cluster/sessions_test.rb +32 -39
- data/test/cluster/subscriber_test.rb +93 -78
- data/test/config/host_test.rb +2 -4
- data/test/config/pubsub_test.rb +132 -126
- data/test/config_test.rb +2 -4
- data/test/contact_test.rb +80 -66
- data/test/error_test.rb +54 -55
- data/test/jid_test.rb +1 -2
- data/test/kit_test.rb +22 -17
- data/test/router_test.rb +187 -146
- data/test/stanza/iq/disco_info_test.rb +59 -59
- data/test/stanza/iq/disco_items_test.rb +36 -34
- data/test/stanza/iq/private_storage_test.rb +138 -143
- data/test/stanza/iq/roster_test.rb +198 -175
- data/test/stanza/iq/session_test.rb +17 -18
- data/test/stanza/iq/vcard_test.rb +117 -116
- data/test/stanza/iq/version_test.rb +47 -46
- data/test/stanza/iq_test.rb +53 -49
- data/test/stanza/message_test.rb +92 -89
- data/test/stanza/presence/probe_test.rb +2 -5
- data/test/stanza/presence/subscribe_test.rb +67 -54
- data/test/stanza/pubsub/create_test.rb +86 -108
- data/test/stanza/pubsub/delete_test.rb +141 -114
- data/test/stanza/pubsub/publish_test.rb +256 -320
- data/test/stanza/pubsub/subscribe_test.rb +169 -150
- data/test/stanza/pubsub/unsubscribe_test.rb +111 -142
- data/test/stanza_test.rb +61 -54
- data/test/storage/ldap_test.rb +1 -2
- data/test/storage/local_test.rb +3 -5
- data/test/storage/null_test.rb +3 -4
- data/test/storage/storage_tests.rb +1 -3
- data/test/storage_test.rb +1 -2
- data/test/store_test.rb +1 -2
- data/test/stream/client/auth_test.rb +61 -63
- data/test/stream/client/ready_test.rb +7 -8
- data/test/stream/client/session_test.rb +19 -18
- data/test/stream/component/handshake_test.rb +40 -37
- data/test/stream/component/ready_test.rb +76 -61
- data/test/stream/component/start_test.rb +7 -8
- data/test/stream/http/auth_test.rb +3 -4
- data/test/stream/http/ready_test.rb +52 -60
- data/test/stream/http/request_test.rb +1 -3
- data/test/stream/http/sessions_test.rb +2 -3
- data/test/stream/http/start_test.rb +3 -4
- data/test/stream/parser_test.rb +3 -4
- data/test/stream/sasl_test.rb +105 -86
- data/test/stream/server/auth_test.rb +40 -36
- data/test/stream/server/outbound/auth_test.rb +3 -4
- data/test/stream/server/ready_test.rb +51 -51
- data/test/test_helper.rb +42 -0
- data/test/token_bucket_test.rb +38 -18
- data/test/user_test.rb +79 -49
- data/vines.gemspec +33 -0
- data/web/chat/javascripts/app.js +1 -1
- data/web/lib/coffeescripts/layout.coffee +1 -1
- data/web/lib/javascripts/base.js +10 -10
- data/web/lib/javascripts/jquery.js +4 -4
- metadata +31 -128
- data/README +0 -35
- data/lib/vines/storage/couchdb.rb +0 -129
- data/lib/vines/storage/mongodb.rb +0 -132
- data/lib/vines/storage/redis.rb +0 -127
- data/lib/vines/storage/sql.rb +0 -220
- data/test/rake_test_loader.rb +0 -17
- data/test/storage/couchdb_test.rb +0 -107
- data/test/storage/mock_mongo.rb +0 -40
- data/test/storage/mongodb_test.rb +0 -81
- data/test/storage/redis_test.rb +0 -51
- data/test/storage/sql_test.rb +0 -62
@@ -1,9 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'minitest/autorun'
|
3
|
+
require 'test_helper'
|
5
4
|
|
6
|
-
|
5
|
+
describe Vines::Stream::Http::Sessions do
|
7
6
|
class MockSessions < Vines::Stream::Http::Sessions
|
8
7
|
def start_timer
|
9
8
|
# do nothing
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'minitest/autorun'
|
3
|
+
require 'test_helper'
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
describe Vines::Stream::Http::Start do
|
6
|
+
before do
|
8
7
|
@stream = MiniTest::Mock.new
|
9
8
|
@state = Vines::Stream::Http::Start.new(@stream)
|
10
9
|
end
|
data/test/stream/parser_test.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'minitest/autorun'
|
3
|
+
require 'test_helper'
|
5
4
|
|
6
|
-
|
5
|
+
describe Vines::Stream::Parser do
|
7
6
|
STREAM_START = '<stream:stream to="wonderland.lit" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams">'.freeze
|
8
7
|
|
9
|
-
|
8
|
+
before do
|
10
9
|
@events = []
|
11
10
|
@parser = Vines::Stream::Parser.new.tap do |p|
|
12
11
|
p.stream_open {|el| @events << el }
|
data/test/stream/sasl_test.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'minitest/autorun'
|
3
|
+
require 'test_helper'
|
5
4
|
|
6
5
|
describe Vines::Stream::SASL do
|
6
|
+
subject { Vines::Stream::SASL.new(stream) }
|
7
|
+
let(:stream) { MiniTest::Mock.new }
|
8
|
+
let(:storage) { MiniTest::Mock.new }
|
9
|
+
let(:romeo) { Vines::User.new(jid: 'romeo@verona.lit') }
|
10
|
+
|
7
11
|
before do
|
8
|
-
|
9
|
-
@sasl = Vines::Stream::SASL.new(@stream)
|
10
|
-
def @sasl.log
|
12
|
+
def subject.log
|
11
13
|
Class.new do
|
12
14
|
def method_missing(*args)
|
13
15
|
# do nothing
|
@@ -17,95 +19,104 @@ describe Vines::Stream::SASL do
|
|
17
19
|
end
|
18
20
|
|
19
21
|
describe '#plain_auth' do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
before do
|
23
|
+
stream.expect :domain, 'verona.lit'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'fails with empty input' do
|
27
|
+
-> { subject.plain_auth(nil) }.must_raise Vines::SaslErrors::IncorrectEncoding
|
28
|
+
-> { subject.plain_auth('') }.must_raise Vines::SaslErrors::NotAuthorized
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'fails with plain text' do
|
32
|
+
-> { subject.plain_auth('bogus') }.must_raise Vines::SaslErrors::IncorrectEncoding
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'fails with incorrectly encoded base64 text' do
|
36
|
+
-> { subject.plain_auth('=dmVyb25hLmxpdA==') }.must_raise Vines::SaslErrors::IncorrectEncoding
|
37
|
+
-> { subject.plain_auth("dmVyb25hLmxpdA==\n") }.must_raise Vines::SaslErrors::IncorrectEncoding
|
26
38
|
end
|
27
39
|
|
28
|
-
it 'fails when authzid does not match authcid' do
|
29
|
-
@stream.expect(:domain, 'verona.lit')
|
40
|
+
it 'fails when authzid does not match authcid username' do
|
30
41
|
encoded = Base64.strict_encode64("juliet@verona.lit\x00romeo\x00secr3t")
|
31
|
-
|
42
|
+
-> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::InvalidAuthzid
|
43
|
+
stream.verify
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'fails when authzid does not match authcid domain' do
|
32
47
|
encoded = Base64.strict_encode64("romeo@wonderland.lit\x00romeo\x00secr3t")
|
33
|
-
|
34
|
-
|
48
|
+
-> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::InvalidAuthzid
|
49
|
+
stream.verify
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'fails when username and password are missing' do
|
53
|
+
encoded = Base64.strict_encode64("\x00\x00")
|
54
|
+
-> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
|
35
55
|
end
|
36
56
|
|
37
57
|
it 'fails when username is missing' do
|
38
58
|
encoded = Base64.strict_encode64("\x00\x00secr3t")
|
39
|
-
|
40
|
-
encoded = Base64.strict_encode64("\x00\x00")
|
41
|
-
proc { @sasl.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
|
59
|
+
-> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
|
42
60
|
end
|
43
61
|
|
44
|
-
it 'fails when password is missing' do
|
62
|
+
it 'fails when password is missing with delimiter' do
|
45
63
|
encoded = Base64.strict_encode64("\x00romeo\x00")
|
46
|
-
|
64
|
+
-> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'fails when password is missing' do
|
47
68
|
encoded = Base64.strict_encode64("\x00romeo")
|
48
|
-
|
69
|
+
-> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
|
49
70
|
end
|
50
71
|
|
51
72
|
it 'fails with invalid jid' do
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
proc { @sasl.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
|
56
|
-
@stream.verify.must_equal true
|
73
|
+
encoded = Base64.strict_encode64("\x00#{'a' * 1024}\x00secr3t")
|
74
|
+
-> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
|
75
|
+
stream.verify
|
57
76
|
end
|
58
77
|
|
59
78
|
it 'fails with invalid password' do
|
60
|
-
|
61
|
-
storage
|
62
|
-
storage.expect(:authenticate, nil, [romeo, 'secr3t'])
|
63
|
-
@stream.expect(:domain, 'verona.lit')
|
64
|
-
@stream.expect(:storage, storage)
|
79
|
+
storage.expect :authenticate, nil, [romeo.jid, 'secr3t']
|
80
|
+
stream.expect :storage, storage
|
65
81
|
|
66
82
|
encoded = Base64.strict_encode64("\x00romeo\x00secr3t")
|
67
|
-
|
68
|
-
|
69
|
-
|
83
|
+
-> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::NotAuthorized
|
84
|
+
|
85
|
+
stream.verify
|
86
|
+
storage.verify
|
70
87
|
end
|
71
88
|
|
72
89
|
it 'passes with valid password' do
|
73
|
-
|
74
|
-
storage
|
75
|
-
storage.expect(:authenticate, Vines::User.new(jid: romeo), [romeo, 'secr3t'])
|
76
|
-
@stream.expect(:domain, 'verona.lit')
|
77
|
-
@stream.expect(:storage, storage)
|
90
|
+
storage.expect :authenticate, romeo, [romeo.jid, 'secr3t']
|
91
|
+
stream.expect :storage, storage
|
78
92
|
|
79
93
|
encoded = Base64.strict_encode64("\x00romeo\x00secr3t")
|
80
|
-
|
81
|
-
|
82
|
-
|
94
|
+
subject.plain_auth(encoded).must_equal romeo
|
95
|
+
|
96
|
+
stream.verify
|
97
|
+
storage.verify
|
83
98
|
end
|
84
99
|
|
85
100
|
it 'passes with valid password and authzid provided by strophe and blather' do
|
86
|
-
|
87
|
-
storage
|
88
|
-
storage.expect(:authenticate, Vines::User.new(jid: romeo), [romeo, 'secr3t'])
|
89
|
-
@stream.expect(:domain, 'verona.lit')
|
90
|
-
@stream.expect(:storage, storage)
|
101
|
+
storage.expect :authenticate, romeo, [romeo.jid, 'secr3t']
|
102
|
+
stream.expect :storage, storage
|
91
103
|
|
92
104
|
encoded = Base64.strict_encode64("romeo@Verona.LIT\x00romeo\x00secr3t")
|
93
|
-
|
94
|
-
|
95
|
-
|
105
|
+
subject.plain_auth(encoded).must_equal romeo
|
106
|
+
|
107
|
+
stream.verify
|
108
|
+
storage.verify
|
96
109
|
end
|
97
110
|
|
98
111
|
it 'passes with valid password and authzid provided by smack' do
|
99
|
-
|
100
|
-
storage
|
101
|
-
storage.expect(:authenticate, Vines::User.new(jid: romeo), [romeo, 'secr3t'])
|
102
|
-
@stream.expect(:domain, 'verona.lit')
|
103
|
-
@stream.expect(:storage, storage)
|
112
|
+
storage.expect :authenticate, romeo, [romeo.jid, 'secr3t']
|
113
|
+
stream.expect :storage, storage
|
104
114
|
|
105
115
|
encoded = Base64.strict_encode64("romeo\x00romeo\x00secr3t")
|
106
|
-
|
107
|
-
|
108
|
-
|
116
|
+
subject.plain_auth(encoded).must_equal romeo
|
117
|
+
|
118
|
+
stream.verify
|
119
|
+
storage.verify
|
109
120
|
end
|
110
121
|
|
111
122
|
it 'raises temporary-auth-failure when storage backend fails' do
|
@@ -114,51 +125,59 @@ describe Vines::Stream::SASL do
|
|
114
125
|
raise 'boom'
|
115
126
|
end
|
116
127
|
end.new
|
117
|
-
@stream.expect(:domain, 'verona.lit')
|
118
|
-
@stream.expect(:storage, storage)
|
119
128
|
|
129
|
+
stream.expect :storage, storage
|
120
130
|
encoded = Base64.strict_encode64("\x00romeo\x00secr3t")
|
121
|
-
|
122
|
-
|
131
|
+
-> { subject.plain_auth(encoded) }.must_raise Vines::SaslErrors::TemporaryAuthFailure
|
132
|
+
stream.verify
|
123
133
|
end
|
124
134
|
end
|
125
135
|
|
126
136
|
describe '#external_auth' do
|
127
|
-
it 'fails with
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
137
|
+
it 'fails with empty input' do
|
138
|
+
stream.expect :remote_domain, 'verona.lit'
|
139
|
+
-> { subject.external_auth(nil) }.must_raise Vines::SaslErrors::IncorrectEncoding
|
140
|
+
-> { subject.external_auth('') }.must_raise Vines::SaslErrors::InvalidAuthzid
|
141
|
+
stream.verify
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'fails with plain text' do
|
145
|
+
-> { subject.external_auth('bogus') }.must_raise Vines::SaslErrors::IncorrectEncoding
|
146
|
+
stream.verify
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'fails with incorrectly encoded base64 text' do
|
150
|
+
-> { subject.external_auth('=dmVyb25hLmxpdA==') }.must_raise Vines::SaslErrors::IncorrectEncoding
|
151
|
+
-> { subject.external_auth("dmVyb25hLmxpdA==\n") }.must_raise Vines::SaslErrors::IncorrectEncoding
|
152
|
+
stream.verify
|
135
153
|
end
|
136
154
|
|
137
155
|
it 'passes with empty authzid and matching cert' do
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
156
|
+
stream.expect :remote_domain, 'verona.lit'
|
157
|
+
stream.expect :cert_domain_matches?, true, ['verona.lit']
|
158
|
+
subject.external_auth('=').must_equal true
|
159
|
+
stream.verify
|
142
160
|
end
|
143
161
|
|
144
162
|
it 'fails with empty authzid and non-matching cert' do
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
163
|
+
stream.expect :remote_domain, 'verona.lit'
|
164
|
+
stream.expect :cert_domain_matches?, false, ['verona.lit']
|
165
|
+
-> { subject.external_auth('=') }.must_raise Vines::SaslErrors::NotAuthorized
|
166
|
+
stream.verify
|
149
167
|
end
|
150
168
|
|
151
169
|
it 'fails when authzid does not match stream from address' do
|
152
|
-
|
153
|
-
|
154
|
-
|
170
|
+
stream.expect :remote_domain, 'not.verona.lit'
|
171
|
+
-> { subject.external_auth('dmVyb25hLmxpdA==') }.must_raise Vines::SaslErrors::InvalidAuthzid
|
172
|
+
stream.verify
|
155
173
|
end
|
156
174
|
|
157
175
|
it 'passes when authzid matches stream from address' do
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
176
|
+
stream.expect :remote_domain, 'verona.lit'
|
177
|
+
stream.expect :remote_domain, 'verona.lit'
|
178
|
+
stream.expect :cert_domain_matches?, true, ['verona.lit']
|
179
|
+
subject.external_auth('dmVyb25hLmxpdA==').must_equal true
|
180
|
+
stream.verify
|
162
181
|
end
|
163
182
|
end
|
164
183
|
end
|
@@ -1,57 +1,61 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'minitest/autorun'
|
3
|
+
require 'test_helper'
|
5
4
|
|
6
5
|
describe Vines::Stream::Server::Auth do
|
7
6
|
# disable logging for tests
|
8
7
|
Class.new.extend(Vines::Log).log.level = Logger::FATAL
|
9
8
|
|
9
|
+
subject { Vines::Stream::Server::Auth.new(stream) }
|
10
|
+
let(:stream) { MiniTest::Mock.new }
|
11
|
+
|
10
12
|
before do
|
11
|
-
|
12
|
-
|
13
|
+
class << stream
|
14
|
+
attr_accessor :remote_domain
|
15
|
+
end
|
16
|
+
stream.remote_domain = 'wonderland.lit'
|
13
17
|
end
|
14
18
|
|
15
|
-
describe '
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
describe 'when given a valid authzid' do
|
20
|
+
before do
|
21
|
+
stream.expect :cert_domain_matches?, true, ['wonderland.lit']
|
22
|
+
stream.expect :write, nil, ['<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>']
|
23
|
+
stream.expect :advance, nil, [Vines::Stream::Server::FinalRestart]
|
24
|
+
stream.expect :reset, nil
|
25
|
+
stream.expect :authentication_mechanisms, ['EXTERNAL']
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'passes external auth with empty authzid' do
|
29
|
+
node = external('=')
|
30
|
+
subject.node(node)
|
31
|
+
stream.verify
|
26
32
|
end
|
27
33
|
|
28
|
-
it 'passes
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
it 'passes external auth with authzid matching from domain' do
|
35
|
+
node = external(Base64.strict_encode64('wonderland.lit'))
|
36
|
+
subject.node(node)
|
37
|
+
stream.verify
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'when given an invalid authzid' do
|
42
|
+
before do
|
43
|
+
stream.expect :write, nil, ['</stream:stream>']
|
44
|
+
stream.expect :close_connection_after_writing, nil
|
45
|
+
stream.expect :error, nil, [Vines::SaslErrors::InvalidAuthzid]
|
46
|
+
stream.expect :authentication_mechanisms, ['EXTERNAL']
|
38
47
|
end
|
39
48
|
|
40
|
-
it 'fails
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
@stream.expect(:error, nil, [Vines::SaslErrors::InvalidAuthzid])
|
45
|
-
@stream.expect(:authentication_mechanisms, ['EXTERNAL'])
|
46
|
-
node = node(%Q{<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="EXTERNAL">#{Base64.strict_encode64('verona.lit')}</auth>})
|
47
|
-
@state.node(node)
|
48
|
-
assert @stream.verify
|
49
|
+
it 'fails external auth with mismatched from domain' do
|
50
|
+
node = external(Base64.strict_encode64('verona.lit'))
|
51
|
+
subject.node(node)
|
52
|
+
stream.verify
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
52
56
|
private
|
53
57
|
|
54
|
-
def
|
55
|
-
|
58
|
+
def external(authzid)
|
59
|
+
node(%Q{<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="EXTERNAL">#{authzid}</auth>})
|
56
60
|
end
|
57
61
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'minitest/autorun'
|
3
|
+
require 'test_helper'
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
describe Vines::Stream::Server::Outbound::Auth do
|
6
|
+
before do
|
8
7
|
@stream = MiniTest::Mock.new
|
9
8
|
@state = Vines::Stream::Server::Outbound::Auth.new(@stream)
|
10
9
|
end
|
@@ -1,93 +1,93 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'minitest/autorun'
|
3
|
+
require 'test_helper'
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
describe Vines::Stream::Server::Ready do
|
6
|
+
subject { Vines::Stream::Server::Ready.new(stream, nil) }
|
7
|
+
let(:stream) { MiniTest::Mock.new }
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def
|
13
|
-
Vines::Stanza.from_node(node,
|
9
|
+
SERVER_STANZAS = []
|
10
|
+
|
11
|
+
before do
|
12
|
+
def subject.to_stanza(node)
|
13
|
+
Vines::Stanza.from_node(node, stream).tap do |stanza|
|
14
14
|
def stanza.process
|
15
|
-
|
15
|
+
SERVER_STANZAS << self
|
16
16
|
end if stanza
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
after do
|
22
|
+
SERVER_STANZAS.clear
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
it 'processes a valid node' do
|
26
26
|
config = MiniTest::Mock.new
|
27
27
|
config.expect(:local_jid?, true, [Vines::JID.new('romeo@verona.lit')])
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
stream.expect(:config, config)
|
30
|
+
stream.expect(:remote_domain, 'wonderland.lit')
|
31
|
+
stream.expect(:domain, 'verona.lit')
|
32
|
+
stream.expect(:user=, nil, [Vines::User.new(jid: 'alice@wonderland.lit')])
|
33
33
|
|
34
34
|
node = node(%Q{<message from="alice@wonderland.lit" to="romeo@verona.lit"/>})
|
35
|
-
|
36
|
-
assert_equal 1,
|
37
|
-
assert
|
35
|
+
subject.node(node)
|
36
|
+
assert_equal 1, SERVER_STANZAS.size
|
37
|
+
assert stream.verify
|
38
38
|
assert config.verify
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
it 'raises unsupported-stanza-type stream error' do
|
42
42
|
node = node('<bogus/>')
|
43
|
-
|
44
|
-
assert
|
45
|
-
assert
|
43
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::UnsupportedStanzaType
|
44
|
+
assert SERVER_STANZAS.empty?
|
45
|
+
assert stream.verify
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
it 'raises improper-addressing stream error when to address is missing' do
|
49
49
|
node = node(%Q{<message from="alice@wonderland.lit"/>})
|
50
|
-
|
51
|
-
assert
|
52
|
-
assert
|
50
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::ImproperAddressing
|
51
|
+
assert SERVER_STANZAS.empty?
|
52
|
+
assert stream.verify
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
it 'raises jid-malformed stanza error when to address is invalid' do
|
56
56
|
node = node(%Q{<message from="alice@wonderland.lit" to=" "/>})
|
57
|
-
|
58
|
-
assert
|
59
|
-
assert
|
57
|
+
-> { subject.node(node) }.must_raise Vines::StanzaErrors::JidMalformed
|
58
|
+
assert SERVER_STANZAS.empty?
|
59
|
+
assert stream.verify
|
60
60
|
end
|
61
61
|
|
62
|
-
|
62
|
+
it 'raises improper-addressing stream error' do
|
63
63
|
node = node(%Q{<message to="romeo@verona.lit"/>})
|
64
|
-
|
65
|
-
assert
|
66
|
-
assert
|
64
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::ImproperAddressing
|
65
|
+
assert SERVER_STANZAS.empty?
|
66
|
+
assert stream.verify
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
it 'raises jid-malformed stanza error for invalid from address' do
|
70
70
|
node = node(%Q{<message from=" " to="romeo@verona.lit"/>})
|
71
|
-
|
72
|
-
assert
|
73
|
-
assert
|
71
|
+
-> { subject.node(node) }.must_raise Vines::StanzaErrors::JidMalformed
|
72
|
+
assert SERVER_STANZAS.empty?
|
73
|
+
assert stream.verify
|
74
74
|
end
|
75
75
|
|
76
|
-
|
77
|
-
|
76
|
+
it 'raises invalid-from stream error' do
|
77
|
+
stream.expect(:remote_domain, 'wonderland.lit')
|
78
78
|
node = node(%Q{<message from="alice@bogus.lit" to="romeo@verona.lit"/>})
|
79
|
-
|
80
|
-
assert
|
81
|
-
assert
|
79
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::InvalidFrom
|
80
|
+
assert SERVER_STANZAS.empty?
|
81
|
+
assert stream.verify
|
82
82
|
end
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
it 'raises host-unknown stream error' do
|
85
|
+
stream.expect(:remote_domain, 'wonderland.lit')
|
86
|
+
stream.expect(:domain, 'verona.lit')
|
87
87
|
node = node(%Q{<message from="alice@wonderland.lit" to="romeo@bogus.lit"/>})
|
88
|
-
|
89
|
-
assert
|
90
|
-
assert
|
88
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::HostUnknown
|
89
|
+
assert SERVER_STANZAS.empty?
|
90
|
+
assert stream.verify
|
91
91
|
end
|
92
92
|
|
93
93
|
private
|