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,49 +1,52 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'minitest/autorun'
|
3
|
+
require 'test_helper'
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@state = Vines::Stream::Component::Handshake.new(@stream)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_invalid_element
|
13
|
-
node = node('<message/>')
|
14
|
-
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
15
|
-
end
|
5
|
+
describe Vines::Stream::Component::Handshake do
|
6
|
+
subject { Vines::Stream::Component::Handshake.new(stream) }
|
7
|
+
let(:stream) { MiniTest::Mock.new }
|
16
8
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
describe 'when invalid element is received' do
|
10
|
+
it 'raises a not-authorized stream error' do
|
11
|
+
node = node('<message/>')
|
12
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::NotAuthorized
|
13
|
+
end
|
22
14
|
end
|
23
15
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
describe 'when handshake with no text is received' do
|
17
|
+
it 'raises a not-authorized stream error' do
|
18
|
+
stream.expect :secret, 'secr3t'
|
19
|
+
node = node('<handshake/>')
|
20
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::NotAuthorized
|
21
|
+
stream.verify
|
22
|
+
end
|
29
23
|
end
|
30
24
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
node = node('<handshake>secr3t</handshake>')
|
39
|
-
@state.node(node)
|
40
|
-
assert @stream.verify
|
41
|
-
assert router.verify
|
25
|
+
describe 'when handshake with invalid secret is received' do
|
26
|
+
it 'raises a not-authorized stream error' do
|
27
|
+
stream.expect :secret, 'secr3t'
|
28
|
+
node = node('<handshake>bogus</handshake>')
|
29
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::NotAuthorized
|
30
|
+
stream.verify
|
31
|
+
end
|
42
32
|
end
|
43
33
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
34
|
+
describe 'when good handshake is received' do
|
35
|
+
let(:router) { MiniTest::Mock.new }
|
36
|
+
|
37
|
+
before do
|
38
|
+
router.expect :<<, nil, [stream]
|
39
|
+
stream.expect :router, router
|
40
|
+
stream.expect :secret, 'secr3t'
|
41
|
+
stream.expect :write, nil, ['<handshake/>']
|
42
|
+
stream.expect :advance, nil, [Vines::Stream::Component::Ready.new(stream)]
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'completes the handshake and advances the stream into the ready state' do
|
46
|
+
node = node('<handshake>secr3t</handshake>')
|
47
|
+
subject.node(node)
|
48
|
+
stream.verify
|
49
|
+
router.verify
|
50
|
+
end
|
48
51
|
end
|
49
52
|
end
|
@@ -1,88 +1,103 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@config = Vines::Config.new do
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe Vines::Stream::Component::Ready do
|
6
|
+
subject { Vines::Stream::Component::Ready.new(stream, nil) }
|
7
|
+
let(:alice) { Vines::User.new(jid: 'alice@tea.wonderland.lit') }
|
8
|
+
let(:hatter) { Vines::User.new(jid: 'hatter@wonderland.lit') }
|
9
|
+
let(:stream) { MiniTest::Mock.new }
|
10
|
+
let(:config) do
|
11
|
+
Vines::Config.new do
|
13
12
|
host 'wonderland.lit' do
|
14
13
|
storage(:fs) { dir Dir.tmpdir }
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
before do
|
19
|
+
class << stream
|
20
|
+
attr_accessor :config
|
21
|
+
end
|
22
|
+
stream.config = config
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
describe 'when missing to and from addresses' do
|
26
|
+
it 'raises an improper-addressing stream error' do
|
27
|
+
node = node('<message/>')
|
28
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::ImproperAddressing
|
29
|
+
stream.verify
|
30
|
+
end
|
29
31
|
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
describe 'when missing from address' do
|
34
|
+
it 'raises an improper-addressing stream error' do
|
35
|
+
node = node(%q{<message to="hatter@wonderland.lit"/>})
|
36
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::ImproperAddressing
|
37
|
+
stream.verify
|
38
|
+
end
|
35
39
|
end
|
36
40
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
describe 'when missing to address' do
|
42
|
+
it 'raises an improper-addressing stream error' do
|
43
|
+
node = node(%q{<message from="alice@tea.wonderland.lit"/>})
|
44
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::ImproperAddressing
|
45
|
+
stream.verify
|
46
|
+
end
|
42
47
|
end
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
describe 'when from address domain does not match component domain' do
|
50
|
+
it 'raises and invalid-from stream error' do
|
51
|
+
stream.expect :remote_domain, 'tea.wonderland.lit'
|
52
|
+
node = node(%q{<message from="alice@bogus.wonderland.lit" to="hatter@wonderland.lit"/>})
|
53
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::InvalidFrom
|
54
|
+
stream.verify
|
55
|
+
end
|
48
56
|
end
|
49
57
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
@router = MiniTest::Mock.new
|
57
|
-
@router.expect(:route, nil, [node])
|
58
|
-
@stream.expect(:router, @router)
|
59
|
-
|
60
|
-
@state.node(node)
|
61
|
-
assert @stream.verify
|
62
|
-
assert @router.verify
|
58
|
+
describe 'when unrecognized element is received' do
|
59
|
+
it 'raises an unsupported-stanza-type stream error' do
|
60
|
+
node = node('<bogus/>')
|
61
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::UnsupportedStanzaType
|
62
|
+
stream.verify
|
63
|
+
end
|
63
64
|
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
@stream.expect(:config, @config)
|
69
|
-
@stream.expect(:user=, nil, [Vines::User.new(:jid => 'alice@tea.wonderland.lit')])
|
70
|
-
@stream.expect(:user, Vines::User.new(:jid => 'alice@tea.wonderland.lit'))
|
66
|
+
describe 'when addressed to a remote jid' do
|
67
|
+
let(:router) { MiniTest::Mock.new }
|
68
|
+
let(:xml) { node(%q{<message from="alice@tea.wonderland.lit" to="romeo@verona.lit"/>}) }
|
71
69
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
before do
|
71
|
+
router.expect :route, nil, [xml]
|
72
|
+
stream.expect :remote_domain, 'tea.wonderland.lit'
|
73
|
+
stream.expect :user=, nil, [alice]
|
74
|
+
stream.expect :router, router
|
75
|
+
end
|
77
76
|
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
it 'routes rather than handle locally' do
|
78
|
+
subject.node(xml)
|
79
|
+
stream.verify
|
80
|
+
router.verify
|
81
|
+
end
|
81
82
|
end
|
82
83
|
|
83
|
-
|
84
|
+
describe 'when addressed to a local jid' do
|
85
|
+
let(:recipient) { MiniTest::Mock.new }
|
86
|
+
let(:xml) { node(%q{<message from="alice@tea.wonderland.lit" to="hatter@wonderland.lit"/>}) }
|
87
|
+
|
88
|
+
before do
|
89
|
+
recipient.expect :user, hatter
|
90
|
+
recipient.expect :write, nil, [xml]
|
91
|
+
stream.expect :remote_domain, 'tea.wonderland.lit'
|
92
|
+
stream.expect :user=, nil, [alice]
|
93
|
+
stream.expect :user, alice
|
94
|
+
stream.expect :connected_resources, [recipient], [hatter.jid]
|
95
|
+
end
|
84
96
|
|
85
|
-
|
86
|
-
|
97
|
+
it 'sends the message to the connected stream' do
|
98
|
+
subject.node(xml)
|
99
|
+
stream.verify
|
100
|
+
recipient.verify
|
101
|
+
end
|
87
102
|
end
|
88
103
|
end
|
@@ -1,30 +1,29 @@
|
|
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::Component::Start do
|
6
|
+
before do
|
8
7
|
@stream = MiniTest::Mock.new
|
9
8
|
@state = Vines::Stream::Component::Start.new(@stream)
|
10
9
|
end
|
11
10
|
|
12
|
-
|
11
|
+
it 'raises not-authorized stream error for invalid element' do
|
13
12
|
node = node('<message/>')
|
14
13
|
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
15
14
|
end
|
16
15
|
|
17
|
-
|
16
|
+
it 'raises not-authorized stream error for missing stream namespace' do
|
18
17
|
node = node('<stream:stream/>')
|
19
18
|
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
20
19
|
end
|
21
20
|
|
22
|
-
|
21
|
+
it 'raises not-authorized stream error for invalid stream namespace' do
|
23
22
|
node = node('<stream:stream xmlns="bogus"/>')
|
24
23
|
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
25
24
|
end
|
26
25
|
|
27
|
-
|
26
|
+
it 'advances the state machine for valid stream header' do
|
28
27
|
node = node(%q{<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:component:accept" to="tea.wonderland.lit"/>})
|
29
28
|
@stream.expect(:start, nil, [node])
|
30
29
|
@stream.expect(:advance, nil, [Vines::Stream::Component::Handshake.new(@stream)])
|
@@ -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::Auth do
|
6
|
+
before do
|
8
7
|
@stream = MiniTest::Mock.new
|
9
8
|
@state = Vines::Stream::Http::Auth.new(@stream, nil)
|
10
9
|
end
|
@@ -1,94 +1,86 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'vines'
|
5
|
-
require 'minitest/autorun'
|
3
|
+
require 'test_helper'
|
6
4
|
|
7
5
|
describe Vines::Stream::Http::Ready do
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
subject { Vines::Stream::Http::Ready.new(stream, nil) }
|
7
|
+
let(:stream) { MiniTest::Mock.new }
|
8
|
+
let(:alice) { Vines::User.new(jid: 'alice@wonderland.lit') }
|
9
|
+
let(:hatter) { Vines::User.new(jid: 'hatter@wonderland.lit') }
|
10
|
+
let(:config) do
|
11
|
+
Vines::Config.new do
|
12
|
+
host 'wonderland.lit' do
|
13
|
+
storage(:fs) { dir Dir.tmpdir }
|
14
|
+
end
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
18
|
it "raises when body element is missing" do
|
14
19
|
node = node('<presence type="unavailable"/>')
|
15
|
-
|
16
|
-
-> {
|
20
|
+
stream.expect :valid_session?, true, [nil]
|
21
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::NotAuthorized
|
17
22
|
end
|
18
23
|
|
19
24
|
it "raises when namespace is missing" do
|
20
25
|
node = node('<body rid="42" sid="12"/>')
|
21
|
-
|
22
|
-
|
23
|
-
-> { @state.node(node) }.must_raise Vines::StreamErrors::NotAuthorized
|
26
|
+
stream.expect :valid_session?, true, ['12']
|
27
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::NotAuthorized
|
24
28
|
end
|
25
29
|
|
26
30
|
it "raises when rid attribute is missing" do
|
27
31
|
node = node('<body xmlns="http://jabber.org/protocol/httpbind" sid="12"/>')
|
28
|
-
|
29
|
-
-> {
|
32
|
+
stream.expect :valid_session?, true, ['12']
|
33
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::NotAuthorized
|
30
34
|
end
|
31
35
|
|
32
36
|
it "raises when session id is invalid" do
|
33
|
-
|
37
|
+
stream.expect :valid_session?, false, ['12']
|
34
38
|
node = node('<body xmlns="http://jabber.org/protocol/httpbind" rid="42" sid="12"/>')
|
35
|
-
-> {
|
36
|
-
|
39
|
+
-> { subject.node(node) }.must_raise Vines::StreamErrors::NotAuthorized
|
40
|
+
stream.verify
|
37
41
|
end
|
38
42
|
|
39
43
|
it "processes when body element is empty" do
|
40
44
|
node = node('<body xmlns="http://jabber.org/protocol/httpbind" rid="42" sid="12"/>')
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
+
stream.expect :valid_session?, true, ['12']
|
46
|
+
stream.expect :parse_body, [], [node]
|
47
|
+
subject.node(node)
|
48
|
+
stream.verify
|
45
49
|
end
|
46
50
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
describe 'when receiving multiple stanzas in one body element' do
|
52
|
+
let(:recipient) { MiniTest::Mock.new }
|
53
|
+
let(:bogus) { node('<message type="bogus">raises stanza error</message>') }
|
54
|
+
let(:ok) { node('<message to="hatter@wonderland.lit">but processes this message</message>') }
|
55
|
+
let(:xml) { node(%Q{<body xmlns="http://jabber.org/protocol/httpbind" rid="42" sid="12">#{bogus}#{ok}</body>}) }
|
56
|
+
let(:raises) { Vines::Stanza.from_node(bogus, stream) }
|
57
|
+
let(:processes) { Vines::Stanza.from_node(ok, stream) }
|
58
|
+
|
59
|
+
before do
|
60
|
+
recipient.expect :user, hatter
|
61
|
+
recipient.expect :write, nil, [Vines::Stanza::Message]
|
62
|
+
|
63
|
+
stream.expect :valid_session?, true, ['12']
|
64
|
+
stream.expect :parse_body, [raises, processes], [xml]
|
65
|
+
stream.expect :error, nil, [Vines::StanzaErrors::BadRequest]
|
66
|
+
stream.expect :config, config
|
67
|
+
stream.expect :user, alice
|
68
|
+
stream.expect :connected_resources, [recipient], [hatter.jid]
|
55
69
|
end
|
56
70
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
processes = Vines::Stanza.from_node(ok, @stream)
|
63
|
-
|
64
|
-
recipient = MiniTest::Mock.new
|
65
|
-
recipient.expect(:user, hatter)
|
66
|
-
recipient.expect(:write, nil, [Vines::Stanza::Message])
|
67
|
-
|
68
|
-
@stream.expect(:valid_session?, true, ['12'])
|
69
|
-
@stream.expect(:parse_body, [raises, processes], [node])
|
70
|
-
@stream.expect(:error, nil, [Vines::StanzaErrors::BadRequest])
|
71
|
-
@stream.expect(:config, config)
|
72
|
-
@stream.expect(:user, alice)
|
73
|
-
@stream.expect(:connected_resources, [recipient], [hatter.jid])
|
74
|
-
|
75
|
-
@state.node(node)
|
76
|
-
assert @stream.verify
|
77
|
-
assert recipient.verify
|
71
|
+
it 'processes all stanzas' do
|
72
|
+
subject.node(xml)
|
73
|
+
stream.verify
|
74
|
+
recipient.verify
|
75
|
+
end
|
78
76
|
end
|
79
77
|
|
80
78
|
it "terminates the session" do
|
81
79
|
node = node('<body xmlns="http://jabber.org/protocol/httpbind" rid="42" sid="12" type="terminate"/>')
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
private
|
90
|
-
|
91
|
-
def node(xml)
|
92
|
-
Nokogiri::XML(xml).root
|
80
|
+
stream.expect :valid_session?, true, ['12']
|
81
|
+
stream.expect :parse_body, [], [node]
|
82
|
+
stream.expect :terminate, nil
|
83
|
+
subject.node(node)
|
84
|
+
stream.verify
|
93
85
|
end
|
94
86
|
end
|