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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b949fe96d3fca6134889e614914fea4253354ea4
4
- data.tar.gz: 65b698fc95dd5c818e2e5438114ffbe732abd489
3
+ metadata.gz: a64256ced89f075deb28a2bbb2732d3e844d9d79
4
+ data.tar.gz: 19a17ea9f031342906b992aef021fa19c171bf9e
5
5
  SHA512:
6
- metadata.gz: e4c64a9e8254f7ae9492ceb4ff29be9c674cacd02a2799a4815b3acf30e21647360247e1494789d383c0d84bbe6159557edd295ba263d2a85a879e3d91e58d5e
7
- data.tar.gz: 4ffc9df0d8e9517f8d2bcc96fc0988ba65c0c487e92e0f9a1ecf4a5927720206cc6d52961ad7a6dd7233abc1752d7420387d0f1158386d756ba42c70c7a03b4b
6
+ metadata.gz: ecaacb012205ff57adae55c414532c651d6b70f74cdb71b567dbceec69497fa17d9e7d2e92b42f459972f0dba547d3578bd9f2e89ae2efe506b7331973f3d46f
7
+ data.tar.gz: a5a48d5b4a09603b8711706e3ade7a3d1c7f2ce1ba7f2ba7aca5b9dadc301180452128e64468def6f58da64d27d4a002ce5c03ad62b87ad8ee7bfe30c714982f
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ gem 'pronto', :git => 'https://github.com/Zauberstuhl/pronto.git'
@@ -39,7 +39,11 @@ module Vines
39
39
  end
40
40
 
41
41
  class Contact < ActiveRecord::Base
42
- scope :chat_enabled, -> { joins(:aspects).where("aspects.chat_enabled = ?", true) }
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.group(:person_id).each do |contact|
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}"
@@ -47,7 +47,7 @@ module Vines
47
47
 
48
48
  def dialback?(node)
49
49
  dialback = node.xpath('ns:dialback', 'ns' => NAMESPACES[:dialback]).any?
50
- features?(node) && dialback
50
+ features?(node) && dialback && !tls_required?(node)
51
51
  end
52
52
 
53
53
  def tls?(node)
data/lib/vines/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Vines
4
4
  # vines forked version 0.4.10
5
- VERSION = '0.2.0.develop.2'
5
+ VERSION = '0.2.0.develop.3'
6
6
  end
@@ -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
@@ -20,6 +20,10 @@ module SqlSchema
20
20
  }.strip).root
21
21
  end
22
22
 
23
+ def db_file
24
+ Rails.application.config.database_configuration["development"]["database"]
25
+ end
26
+
23
27
  def storage
24
28
  Vines::Storage::Sql.new
25
29
  end
@@ -1,15 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'test_helper'
4
- require 'storage/sql_schema'
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
- before do
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
- :name => "test",
33
- :url => "http://remote.host/",
34
- :image_url => "http://path.to/image.png",
35
- :jid => "test@local.host",
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(:force => true)
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
- person_id: 1,
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
- :user_id => 1,
71
- :name => "without_chat",
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
- :aspect_id => 1, # without_chat
77
- :contact_id => 1 # person
72
+ # without_chat
73
+ aspect_id: 1, contact_id: 1
78
74
  ).save
79
75
  end
80
76
 
81
77
  after do
82
- db = Rails.application.config.database_configuration["development"]["database"]
83
- File.delete(db) if File.exist?(db)
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
- :from => @test_user[:jid],
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
- assert_equal "someone@inthe.void", msgs[1][:to]
141
- assert_equal @test_user[:jid], msgs[1][:from]
142
- assert_equal "test", msgs[1][:message]
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
- com = Vines::Storage::Sql::ChatOfflineMessage
150
- com.new(:from => @test_user[:jid],
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
- db.destroy_message(1)
156
-
157
- count = Vines::Storage::Sql::ChatOfflineMessage.count(:id => 1)
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
- jid: 'test2@test.de',
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('test2@test.de')
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(%q{<characters xmlns="urn:wonderland"/>}).root
262
- bad_name = Nokogiri::XML(%q{<not_characters xmlns="urn:wonderland"/>}).root
263
- bad_ns = Nokogiri::XML(%q{<characters xmlns="not:wonderland"/>}).root
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('full@wonderland.lit', bad_name)
258
+ node = db.find_fragment("full@wonderland.lit", bad_name)
269
259
  assert_nil node
270
260
 
271
- node = db.find_fragment('full@wonderland.lit', bad_ns)
261
+ node = db.find_fragment("full@wonderland.lit", bad_ns)
272
262
  assert_nil node
273
263
 
274
- node = db.find_fragment('full@wonderland.lit', root)
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('full@wonderland.lit'), root)
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('full@wonderland.lit/resource'), root)
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(%q{<characters xmlns="urn:wonderland"/>}).root
294
- db.save_fragment('test@test.de/resource1', fragment)
295
- node = db.find_fragment('test@test.de', root)
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 'test_helper'
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
- node = node('<message/>')
24
- assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
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
- node = node(%Q{<message xmlns="#{Vines::NAMESPACES[:tls]}"/>})
29
- assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
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
- node = node(%Q{<message xmlns:db="#{Vines::NAMESPACES[:legacy_dialback]}"/>})
34
- assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
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
- node = node('<starttls/>')
39
- assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
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
- node = node('<db:result/>')
44
- assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
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
- node = node(%Q{<starttls xmlns="#{Vines::NAMESPACES[:legacy_dialback]}"/>})
49
- assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
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
- @stream.expect(:encrypt?, false)
54
- @stream.expect(:close_connection_after_writing, nil)
55
- failure = %Q{<failure xmlns="#{Vines::NAMESPACES[:tls]}"/>}
56
- node = node(%Q{<starttls xmlns="#{Vines::NAMESPACES[:tls]}"/>})
57
- @stream.expect(:write, nil, [failure])
58
- @stream.expect(:write, nil, ['</stream:stream>'])
59
- @state.node(node)
60
- assert @stream.verify
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
- @stream.expect(:encrypt?, true)
65
- @stream.expect(:encrypt, nil)
66
- @stream.expect(:reset, nil)
67
- @stream.expect(:advance, nil, [Vines::Stream::Server::AuthRestart.new(@stream)])
68
- success = %Q{<proceed xmlns="#{Vines::NAMESPACES[:tls]}"/>}
69
- node = node(%Q{<starttls xmlns="#{Vines::NAMESPACES[:tls]}"/>})
70
- @stream.expect(:write, nil, [success])
71
- @state.node(node)
72
- assert @stream.verify
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
- @stream.expect(:config, Vines::Config)
77
- @stream.expect(:router, OperatorWrapper.new)
78
- @stream.expect(:close_connection_after_writing, nil)
79
- node = node(%Q{
80
- <db:result xmlns:db="#{Vines::NAMESPACES[:legacy_dialback]}" from="#{@result[:from]}" to="#{@result[:to]}">
81
- #{@result[:token]}
82
- </db:result>
83
- })
84
- assert_nothing_raised do
85
- @state.node(node)
86
- end.must_equal(true)
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