diaspora-vines 0.2.0.develop.2 → 0.2.0.develop.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/lib/vines/storage/sql.rb +6 -2
- data/lib/vines/stream/server/outbound/auth.rb +1 -1
- data/lib/vines/version.rb +1 -1
- data/test/cluster/subscriber_test.rb +2 -0
- data/test/storage/sql_schema.rb +4 -0
- data/test/storage/sql_test.rb +57 -67
- data/test/stream/server/auth_method_test.rb +68 -46
- data/test/stream/server/auth_test.rb +31 -22
- data/test/stream/server/outbound/auth_dialback_result_test.rb +28 -13
- data/test/stream/server/outbound/auth_external_test.rb +60 -30
- data/test/stream/server/outbound/auth_restart_test.rb +47 -23
- data/test/stream/server/outbound/auth_test.rb +62 -40
- data/test/stream/server/outbound/authoritative_test.rb +53 -33
- data/test/stream/server/outbound/start_test.rb +21 -9
- data/test/stream/server/ready_test.rb +77 -53
- data/test/stream/server/start_test.rb +65 -30
- data/test/test_helper.rb +8 -0
- metadata +34 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a64256ced89f075deb28a2bbb2732d3e844d9d79
|
4
|
+
data.tar.gz: 19a17ea9f031342906b992aef021fa19c171bf9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecaacb012205ff57adae55c414532c651d6b70f74cdb71b567dbceec69497fa17d9e7d2e92b42f459972f0dba547d3578bd9f2e89ae2efe506b7331973f3d46f
|
7
|
+
data.tar.gz: a5a48d5b4a09603b8711706e3ade7a3d1c7f2ce1ba7f2ba7aca5b9dadc301180452128e64468def6f58da64d27d4a002ce5c03ad62b87ad8ee7bfe30c714982f
|
data/Gemfile
CHANGED
data/lib/vines/storage/sql.rb
CHANGED
@@ -39,7 +39,11 @@ module Vines
|
|
39
39
|
end
|
40
40
|
|
41
41
|
class Contact < ActiveRecord::Base
|
42
|
-
scope :chat_enabled, -> {
|
42
|
+
scope :chat_enabled, -> {
|
43
|
+
joins(:aspects)
|
44
|
+
.where("aspects.chat_enabled = ?", true)
|
45
|
+
.group("person_id, contacts.id")
|
46
|
+
}
|
43
47
|
|
44
48
|
belongs_to :users
|
45
49
|
belongs_to :person
|
@@ -110,7 +114,7 @@ module Vines
|
|
110
114
|
xuser.authentication_token
|
111
115
|
|
112
116
|
# add diaspora contacts
|
113
|
-
xuser.contacts.chat_enabled.
|
117
|
+
xuser.contacts.chat_enabled.each do |contact|
|
114
118
|
handle = contact.person.diaspora_handle
|
115
119
|
profile = contact.person.profile
|
116
120
|
name = "#{profile.first_name} #{profile.last_name}"
|
data/lib/vines/version.rb
CHANGED
@@ -77,6 +77,8 @@ describe Vines::Cluster::Subscriber do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'writes the stanza to the connected user streams' do
|
80
|
+
# NOTE https://github.com/diaspora/vines/issues/68
|
81
|
+
skip "This fails randomly! Skipping it for later investigations."
|
80
82
|
msg = {from: 'node-42', type: 'stanza', stanza: stanza}.to_json
|
81
83
|
subject.send(:on_message, 'cluster:nodes:abc', msg)
|
82
84
|
stream.verify
|
data/test/storage/sql_schema.rb
CHANGED
data/test/storage/sql_test.rb
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
module Vines
|
7
|
-
class Config
|
8
|
-
def instance.max_offline_msgs
|
9
|
-
return 1
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
3
|
+
require "test_helper"
|
4
|
+
require "storage/sql_schema"
|
13
5
|
|
14
6
|
module Diaspora
|
15
7
|
class Application < Rails::Application
|
@@ -27,22 +19,30 @@ end
|
|
27
19
|
describe Vines::Storage::Sql do
|
28
20
|
include SqlSchema
|
29
21
|
|
30
|
-
|
22
|
+
def setup
|
23
|
+
_config = Vines::Config.configure do
|
24
|
+
max_offline_msgs 1
|
25
|
+
|
26
|
+
host "wonderland.lit" do
|
27
|
+
storage :fs do
|
28
|
+
dir Dir.tmpdir
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
31
33
|
@test_user = {
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:email => "test@test.de",
|
37
|
-
:password => "$2a$10$c2G6rHjGeamQIOFI0c1/b.4mvFBw4AfOtgVrAkO1QPMuAyporj5e6", # pppppp
|
38
|
-
:token => "1234"
|
34
|
+
name: "test", url: "http://remote.host/",
|
35
|
+
image_url: "http://path.to/image.png", jid: "test@local.host", email: "test@test.de",
|
36
|
+
password: "$2a$10$c2G6rHjGeamQIOFI0c1/b.4mvFBw4AfOtgVrAkO1QPMuAyporj5e6", # pppppp
|
37
|
+
token: "1234"
|
39
38
|
}
|
39
|
+
|
40
|
+
return if File.exist?(db_file)
|
40
41
|
# create sql schema
|
41
|
-
storage && create_schema(:
|
42
|
+
storage && create_schema(force: true)
|
42
43
|
|
43
44
|
Vines::Storage::Sql::User.new(
|
44
|
-
username: @test_user[:name],
|
45
|
-
email: @test_user[:email],
|
45
|
+
username: @test_user[:name], email: @test_user[:email],
|
46
46
|
encrypted_password: @test_user[:password],
|
47
47
|
authentication_token: @test_user[:token]
|
48
48
|
).save
|
@@ -61,26 +61,23 @@ describe Vines::Storage::Sql do
|
|
61
61
|
image_url: @test_user[:image_url]
|
62
62
|
).save
|
63
63
|
Vines::Storage::Sql::Contact.new(
|
64
|
-
user_id: 1,
|
65
|
-
|
66
|
-
sharing: true,
|
67
|
-
receiving: true
|
64
|
+
user_id: 1, person_id: 1,
|
65
|
+
sharing: true, receiving: true
|
68
66
|
).save
|
69
67
|
Vines::Storage::Sql::Aspect.new(
|
70
|
-
:
|
71
|
-
:
|
72
|
-
:contacts_visible => true,
|
73
|
-
:order_id => nil
|
68
|
+
user_id: 1, name: "without_chat",
|
69
|
+
contacts_visible: true, order_id: nil
|
74
70
|
).save
|
75
71
|
Vines::Storage::Sql::AspectMembership.new(
|
76
|
-
|
77
|
-
:
|
72
|
+
# without_chat
|
73
|
+
aspect_id: 1, contact_id: 1
|
78
74
|
).save
|
79
75
|
end
|
80
76
|
|
81
77
|
after do
|
82
|
-
|
83
|
-
|
78
|
+
# since we create the database once we
|
79
|
+
# have to reset it after every test run
|
80
|
+
Vines::Storage::Sql::ChatOfflineMessage.all.each(&:destroy)
|
84
81
|
end
|
85
82
|
|
86
83
|
def test_save_message
|
@@ -130,31 +127,29 @@ describe Vines::Storage::Sql do
|
|
130
127
|
assert_equal 0, db.find_messages("someone@inthe.void").keys.count
|
131
128
|
|
132
129
|
Vines::Storage::Sql::ChatOfflineMessage.new(
|
133
|
-
:
|
134
|
-
:to => "someone@inthe.void",
|
135
|
-
:message => "test"
|
130
|
+
from: @test_user[:jid], to: "someone@inthe.void", message: "test"
|
136
131
|
).save
|
137
132
|
|
138
133
|
msgs = db.find_messages("someone@inthe.void")
|
139
134
|
assert_equal 1, msgs.keys.count
|
140
|
-
|
141
|
-
|
142
|
-
|
135
|
+
msgs.each {|_, msg|
|
136
|
+
assert_equal "someone@inthe.void", msg[:to]
|
137
|
+
assert_equal @test_user[:jid], msg[:from]
|
138
|
+
assert_equal "test", msg[:message]
|
139
|
+
}
|
143
140
|
end
|
144
141
|
end
|
145
142
|
|
146
143
|
def test_destroy_message
|
147
144
|
fibered do
|
148
145
|
db = storage
|
149
|
-
|
150
|
-
|
151
|
-
:to => "someone@inthe.void",
|
152
|
-
:message => "test"
|
146
|
+
Vines::Storage::Sql::ChatOfflineMessage.new(
|
147
|
+
from: @test_user[:jid], to: "someone@inthe.void", message: "test"
|
153
148
|
).save
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
count = Vines::Storage::Sql::ChatOfflineMessage.count(:
|
149
|
+
Vines::Storage::Sql::ChatOfflineMessage.all.each do |com|
|
150
|
+
db.destroy_message(com.id)
|
151
|
+
end
|
152
|
+
count = Vines::Storage::Sql::ChatOfflineMessage.count(id: 1)
|
158
153
|
assert_equal 0, count
|
159
154
|
end
|
160
155
|
end
|
@@ -166,10 +161,7 @@ describe Vines::Storage::Sql do
|
|
166
161
|
assert_equal 0, user.roster.length
|
167
162
|
|
168
163
|
aspect = Vines::Storage::Sql::Aspect.where(:id => 1)
|
169
|
-
aspect.update_all(
|
170
|
-
:name => "with_chat",
|
171
|
-
:chat_enabled => true
|
172
|
-
)
|
164
|
+
aspect.update_all(name: "with_chat", chat_enabled: true)
|
173
165
|
user = db.find_user(@test_user[:jid])
|
174
166
|
assert_equal 1, user.roster.length
|
175
167
|
end
|
@@ -178,12 +170,10 @@ describe Vines::Storage::Sql do
|
|
178
170
|
def test_save_user
|
179
171
|
fibered do
|
180
172
|
db = storage
|
181
|
-
user = Vines::User.new(
|
182
|
-
|
183
|
-
name: 'test2@test.de',
|
184
|
-
password: 'secret')
|
173
|
+
user = Vines::User.new(jid: "test2@test.de",
|
174
|
+
name: "test2@test.de", password: "secret")
|
185
175
|
db.save_user(user)
|
186
|
-
assert_nil db.find_user(
|
176
|
+
assert_nil db.find_user("test2@test.de")
|
187
177
|
end
|
188
178
|
end
|
189
179
|
|
@@ -258,28 +248,28 @@ describe Vines::Storage::Sql do
|
|
258
248
|
|
259
249
|
fibered do
|
260
250
|
db = storage
|
261
|
-
root = Nokogiri::XML(%
|
262
|
-
bad_name = Nokogiri::XML(%
|
263
|
-
bad_ns = Nokogiri::XML(%
|
251
|
+
root = Nokogiri::XML(%(<characters xmlns="urn:wonderland"/>)).root
|
252
|
+
bad_name = Nokogiri::XML(%(<not_characters xmlns="urn:wonderland"/>)).root
|
253
|
+
bad_ns = Nokogiri::XML(%(<characters xmlns="not:wonderland"/>)).root
|
264
254
|
|
265
255
|
node = db.find_fragment(nil, nil)
|
266
256
|
assert_nil node
|
267
257
|
|
268
|
-
node = db.find_fragment(
|
258
|
+
node = db.find_fragment("full@wonderland.lit", bad_name)
|
269
259
|
assert_nil node
|
270
260
|
|
271
|
-
node = db.find_fragment(
|
261
|
+
node = db.find_fragment("full@wonderland.lit", bad_ns)
|
272
262
|
assert_nil node
|
273
263
|
|
274
|
-
node = db.find_fragment(
|
264
|
+
node = db.find_fragment("full@wonderland.lit", root)
|
275
265
|
assert (node != nil), "node should include fragment"
|
276
266
|
assert_equal fragment.to_s, node.to_s
|
277
267
|
|
278
|
-
node = db.find_fragment(Vines::JID.new(
|
268
|
+
node = db.find_fragment(Vines::JID.new("full@wonderland.lit"), root)
|
279
269
|
assert (node != nil), "node should include fragment"
|
280
270
|
assert_equal fragment.to_s, node.to_s
|
281
271
|
|
282
|
-
node = db.find_fragment(Vines::JID.new(
|
272
|
+
node = db.find_fragment(Vines::JID.new("full@wonderland.lit/resource"), root)
|
283
273
|
assert (node != nil), "node should include fragment"
|
284
274
|
assert_equal fragment.to_s, node.to_s
|
285
275
|
end
|
@@ -290,9 +280,9 @@ describe Vines::Storage::Sql do
|
|
290
280
|
|
291
281
|
fibered do
|
292
282
|
db = storage
|
293
|
-
root = Nokogiri::XML(%
|
294
|
-
db.save_fragment(
|
295
|
-
node = db.find_fragment(
|
283
|
+
root = Nokogiri::XML(%(<characters xmlns="urn:wonderland"/>)).root
|
284
|
+
db.save_fragment("test@test.de/resource1", fragment)
|
285
|
+
node = db.find_fragment("test@test.de", root)
|
296
286
|
assert (node != nil), "node should include fragment"
|
297
287
|
assert_equal fragment.to_s, node.to_s
|
298
288
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
3
|
+
require "test_helper"
|
4
4
|
|
5
5
|
class OperatorWrapper
|
6
6
|
def <<(stream)
|
@@ -10,80 +10,102 @@ end
|
|
10
10
|
|
11
11
|
describe Vines::Stream::Server::AuthMethod do
|
12
12
|
before do
|
13
|
-
@result = {
|
14
|
-
from: 'hostA.org',
|
15
|
-
to: 'hostB.org',
|
16
|
-
token: '1234'
|
17
|
-
}
|
13
|
+
@result = {from: "hostA.org", to: "hostB.org", token: "1234"}
|
18
14
|
@stream = MiniTest::Mock.new
|
19
15
|
@state = Vines::Stream::Server::AuthMethod.new(@stream)
|
20
16
|
end
|
21
17
|
|
22
18
|
def test_invalid_element
|
23
|
-
|
24
|
-
|
19
|
+
EM.run {
|
20
|
+
node = node("<message/>")
|
21
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
22
|
+
EM.stop
|
23
|
+
}
|
25
24
|
end
|
26
25
|
|
27
26
|
def test_invalid_tls_element
|
28
|
-
|
29
|
-
|
27
|
+
EM.run {
|
28
|
+
node = node(%(<message xmlns="#{Vines::NAMESPACES[:tls]}"/>))
|
29
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
30
|
+
EM.stop
|
31
|
+
}
|
30
32
|
end
|
31
33
|
|
32
34
|
def test_invalid_dialback_element
|
33
|
-
|
34
|
-
|
35
|
+
EM.run {
|
36
|
+
node = node(%(<message xmlns:db="#{Vines::NAMESPACES[:legacy_dialback]}"/>))
|
37
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
38
|
+
EM.stop
|
39
|
+
}
|
35
40
|
end
|
36
41
|
|
37
42
|
def test_missing_tls_namespace
|
38
|
-
|
39
|
-
|
43
|
+
EM.run {
|
44
|
+
node = node("<starttls/>")
|
45
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
46
|
+
EM.stop
|
47
|
+
}
|
40
48
|
end
|
41
49
|
|
42
50
|
def test_no_dialback_payload
|
43
|
-
|
44
|
-
|
51
|
+
EM.run {
|
52
|
+
node = node("<db:result/>")
|
53
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
54
|
+
EM.stop
|
55
|
+
}
|
45
56
|
end
|
46
57
|
|
47
58
|
def test_invalid_tls_namespace
|
48
|
-
|
49
|
-
|
59
|
+
EM.run {
|
60
|
+
node = node(%(<starttls xmlns="#{Vines::NAMESPACES[:legacy_dialback]}"/>))
|
61
|
+
assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
|
62
|
+
EM.stop
|
63
|
+
}
|
50
64
|
end
|
51
65
|
|
52
66
|
def test_missing_tls_certificate
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
67
|
+
EM.run {
|
68
|
+
@stream.expect(:encrypt?, false)
|
69
|
+
@stream.expect(:close_connection_after_writing, nil)
|
70
|
+
failure = %(<failure xmlns="#{Vines::NAMESPACES[:tls]}"/>)
|
71
|
+
node = node(%(<starttls xmlns="#{Vines::NAMESPACES[:tls]}"/>))
|
72
|
+
@stream.expect(:write, nil, [failure])
|
73
|
+
@stream.expect(:write, nil, ["</stream:stream>"])
|
74
|
+
@state.node(node)
|
75
|
+
assert @stream.verify
|
76
|
+
EM.stop
|
77
|
+
}
|
61
78
|
end
|
62
79
|
|
63
80
|
def test_valid_tls
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
81
|
+
EM.run {
|
82
|
+
@stream.expect(:encrypt?, true)
|
83
|
+
@stream.expect(:encrypt, nil)
|
84
|
+
@stream.expect(:reset, nil)
|
85
|
+
@stream.expect(:advance, nil, [Vines::Stream::Server::AuthRestart.new(@stream)])
|
86
|
+
success = %(<proceed xmlns="#{Vines::NAMESPACES[:tls]}"/>)
|
87
|
+
node = node(%(<starttls xmlns="#{Vines::NAMESPACES[:tls]}"/>))
|
88
|
+
@stream.expect(:write, nil, [success])
|
89
|
+
@state.node(node)
|
90
|
+
assert @stream.verify
|
91
|
+
EM.stop
|
92
|
+
}
|
73
93
|
end
|
74
94
|
|
75
95
|
def test_valid_dialback
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
#{
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
96
|
+
EM.run {
|
97
|
+
@stream.expect(:config, Vines::Config)
|
98
|
+
@stream.expect(:router, OperatorWrapper.new)
|
99
|
+
@stream.expect(:close_connection_after_writing, nil)
|
100
|
+
node = node(
|
101
|
+
%(<db:result xmlns:db="#{Vines::NAMESPACES[:legacy_dialback]}" ) +
|
102
|
+
%(from="#{@result[:from]}" to="#{@result[:to]}">#{@result[:token]}</db:result>)
|
103
|
+
)
|
104
|
+
assert_nothing_raised {
|
105
|
+
@state.node(node)
|
106
|
+
}.must_equal(true)
|
107
|
+
EM.stop
|
108
|
+
}
|
87
109
|
end
|
88
110
|
|
89
111
|
private
|