diaspora-vines 0.1.22 → 0.1.24

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.
@@ -73,6 +73,10 @@ module Vines
73
73
 
74
74
  # Send an HTTP 200 OK response wrapping the XMPP node content back
75
75
  # to the client.
76
+ #
77
+ # node - The XML::Node to send to the client.
78
+ #
79
+ # Returns nothing.
76
80
  def reply(node)
77
81
  if request = @requests.shift
78
82
  request.reply(node, @content_type)
@@ -83,6 +87,10 @@ module Vines
83
87
  # Write the XMPP node to the client stream after wrapping it in a BOSH
84
88
  # body tag. If there's a waiting request, the node is written
85
89
  # immediately. If not, it's queued until the next request arrives.
90
+ #
91
+ # data - The XML String or XML::Node to send in the next HTTP response.
92
+ #
93
+ # Returns nothing.
86
94
  def write(node)
87
95
  if request = @requests.shift
88
96
  request.reply(wrap_body(node), @content_type)
@@ -125,23 +125,29 @@ module Vines
125
125
 
126
126
  private
127
127
 
128
- # The +to+ and +from+ domain addresses set on the initial stream header
128
+ # The `to` and `from` domain addresses set on the initial stream header
129
129
  # must not change during stream restarts. This prevents a server from
130
130
  # authenticating as one domain, then sending stanzas from users in a
131
131
  # different domain.
132
+ #
133
+ # to - The String domain the other server thinks we are.
134
+ # from - The String domain the other server is asserting as its identity.
135
+ #
136
+ # Returns true if the other server is misbehaving and its connection
137
+ # should be closed.
132
138
  def domain_change?(to, from)
133
139
  to != @domain || from != @remote_domain
134
140
  end
135
141
 
136
142
  def send_stream_header
137
143
  attrs = {
138
- 'xmlns' => NAMESPACES[:server],
144
+ 'xmlns' => NAMESPACES[:server],
139
145
  'xmlns:stream' => NAMESPACES[:stream],
140
- 'xml:lang' => 'en',
141
- 'id' => Kit.uuid,
142
- 'from' => @domain,
143
- 'to' => @remote_domain,
144
- 'version' => '1.0'
146
+ 'xml:lang' => 'en',
147
+ 'id' => Kit.uuid,
148
+ 'from' => @domain,
149
+ 'to' => @remote_domain,
150
+ 'version' => '1.0'
145
151
  }
146
152
  write "<stream:stream %s>" % attrs.to_a.map{|k,v| "#{k}='#{v}'"}.join(' ')
147
153
  end
data/lib/vines/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Vines
4
- # vines forked version 0.4.9
5
- VERSION = '0.1.22'
4
+ # vines forked version 0.4.10
5
+ VERSION = '0.1.24'
6
6
  end
@@ -47,43 +47,6 @@ describe Vines::Config::Host do
47
47
  refute_nil config.vhost('wonderland.lit').storage
48
48
  end
49
49
 
50
- def test_ldap_added_to_storage
51
- config = Vines::Config.new do
52
- host 'wonderland.lit' do
53
- storage(:fs) { dir Dir.tmpdir }
54
- # added after storage
55
- ldap 'ldap.wonderland.lit', 1636 do
56
- tls true
57
- dn 'cn=Directory Manager'
58
- password 'secr3t'
59
- basedn 'dc=wonderland,dc=lit'
60
- groupdn 'cn=chatters,dc=wonderland,dc=lit'
61
- object_class 'person'
62
- user_attr 'uid'
63
- name_attr 'cn'
64
- end
65
- end
66
-
67
- host 'verona.lit' do
68
- ldap 'ldap.verona.lit', 1636 do
69
- tls true
70
- dn 'cn=Directory Manager'
71
- password 'secr3t'
72
- basedn 'dc=wonderland,dc=lit'
73
- object_class 'person'
74
- user_attr 'uid'
75
- name_attr 'cn'
76
- end
77
- # added before storage
78
- storage(:fs) { dir Dir.tmpdir }
79
- end
80
- end
81
- %w[wonderland.lit verona.lit].each do |domain|
82
- refute_nil config.vhost(domain).storage.ldap
83
- assert config.vhost(domain).storage.ldap?
84
- end
85
- end
86
-
87
50
  def test_empty_component_name_raises
88
51
  assert_raises(RuntimeError) do
89
52
  Vines::Config.new do
@@ -366,4 +329,30 @@ describe Vines::Config::Host do
366
329
  refute config.private_storage?(Vines::JID.new('alice@wonderland.lit'))
367
330
  refute config.private_storage?(nil)
368
331
  end
332
+
333
+ def test_enabled_blacklisting
334
+ config = Vines::Config.new do
335
+ host 'wonderland.lit' do
336
+ storage(:fs) { dir Dir.tmpdir }
337
+ end
338
+ server '0.0.0.0', 5269 do
339
+ max_stanza_size 131072
340
+ blacklist ['wonderland.lit']
341
+ end
342
+ end
343
+ refute config.s2s?('wonderland.lit')
344
+ end
345
+
346
+ def test_disabled_blacklisting
347
+ config = Vines::Config.new do
348
+ host 'wonderland.lit' do
349
+ storage(:fs) { dir Dir.tmpdir }
350
+ end
351
+ server '0.0.0.0', 5269 do
352
+ max_stanza_size 131072
353
+ blacklist []
354
+ end
355
+ end
356
+ assert config.s2s?('wonderland.lit')
357
+ end
369
358
  end
data/test/config_test.rb CHANGED
@@ -405,6 +405,20 @@ describe Vines::Config do
405
405
  assert config.vhost('verona.lit').cross_domain_messages?
406
406
  end
407
407
 
408
+ def test_accept_self_signed
409
+ config = Vines::Config.new do
410
+ host 'wonderland.lit' do
411
+ storage(:fs) { dir Dir.tmpdir }
412
+ end
413
+ host 'verona.lit' do
414
+ accept_self_signed true
415
+ storage(:fs) { dir Dir.tmpdir }
416
+ end
417
+ end
418
+ refute config.vhost('wonderland.lit').accept_self_signed?
419
+ assert config.vhost('verona.lit').accept_self_signed?
420
+ end
421
+
408
422
  def test_local_jid?
409
423
  config = Vines::Config.new do
410
424
  host 'wonderland.lit', 'verona.lit' do
@@ -11,7 +11,7 @@ module SqlSchema
11
11
  def fragment_id
12
12
  Digest::SHA1.hexdigest("characters:urn:wonderland")
13
13
  end
14
-
14
+
15
15
  def fragment
16
16
  Nokogiri::XML(%q{
17
17
  <characters xmlns="urn:wonderland">
@@ -26,7 +26,9 @@ module SqlSchema
26
26
 
27
27
  def create_schema(args={})
28
28
  args[:force] ||= false
29
-
29
+
30
+ # disable stdout logging
31
+ ActiveRecord::Migration.verbose = false
30
32
  ActiveRecord::Schema.define do
31
33
  create_table "people", :force => true do |t|
32
34
  t.string "guid", :null => false
@@ -51,6 +53,7 @@ module SqlSchema
51
53
  t.datetime "updated_at", :null => false
52
54
  t.boolean "contacts_visible", :default => true, :null => false
53
55
  t.integer "order_id"
56
+ t.boolean "chat_enabled", default: false
54
57
  end
55
58
 
56
59
  add_index "aspects", ["user_id", "contacts_visible"], :name => "index_aspects_on_user_id_and_contacts_visible"
@@ -20,13 +20,43 @@ describe Vines::Storage::Sql do
20
20
  include SqlSchema
21
21
 
22
22
  before do
23
+ @test_user = {
24
+ :name => "test",
25
+ :jid => "test@local.host",
26
+ :email => "test@test.de",
27
+ :password => "$2a$10$c2G6rHjGeamQIOFI0c1/b.4mvFBw4AfOtgVrAkO1QPMuAyporj5e6", # pppppp
28
+ :token => "1234"
29
+ }
30
+ # create sql schema
23
31
  storage && create_schema(:force => true)
24
-
32
+
25
33
  Vines::Storage::Sql::User.new(
26
- username: "test",
27
- email: "test@test.de",
28
- encrypted_password: "$2a$10$c2G6rHjGeamQIOFI0c1/b.4mvFBw4AfOtgVrAkO1QPMuAyporj5e6", # pppppp
29
- authentication_token: "1234"
34
+ username: @test_user[:name],
35
+ email: @test_user[:email],
36
+ encrypted_password: @test_user[:password],
37
+ authentication_token: @test_user[:token]
38
+ ).save
39
+ Vines::Storage::Sql::Person.new(
40
+ guid: "1697a4b0198901321e9b10e6ba921ce9",
41
+ url: "http://remote.host/",
42
+ serialized_public_key: "some pub key",
43
+ diaspora_handle: "test2@remote.host"
44
+ ).save
45
+ Vines::Storage::Sql::Contact.new(
46
+ user_id: 1,
47
+ person_id: 1,
48
+ sharing: true,
49
+ receiving: true
50
+ ).save
51
+ Vines::Storage::Sql::Aspect.new(
52
+ :user_id => 1,
53
+ :name => "without_chat",
54
+ :contacts_visible => true,
55
+ :order_id => nil
56
+ ).save
57
+ Vines::Storage::Sql::AspectMembership.new(
58
+ :aspect_id => 1, # without_chat
59
+ :contact_id => 1 # person
30
60
  ).save
31
61
  end
32
62
 
@@ -34,26 +64,32 @@ describe Vines::Storage::Sql do
34
64
  db = Rails.application.config.database_configuration["development"]["database"]
35
65
  File.delete(db) if File.exist?(db)
36
66
  end
37
-
67
+
68
+ def test_aspect_chat_enabled
69
+ fibered do
70
+ db = storage
71
+ user = db.find_user(@test_user[:jid])
72
+ assert_equal 0, user.roster.length
73
+
74
+ aspect = Vines::Storage::Sql::Aspect.where(:id => 1)
75
+ aspect.update_all(
76
+ :name => "with_chat",
77
+ :chat_enabled => true
78
+ )
79
+ user = db.find_user(@test_user[:jid])
80
+ assert_equal 1, user.roster.length
81
+ end
82
+ end
83
+
38
84
  def test_save_user
39
85
  fibered do
40
86
  db = storage
41
87
  user = Vines::User.new(
42
- jid: 'test@test.de',
43
- name: 'test@test.de',
88
+ jid: 'test2@test.de',
89
+ name: 'test2@test.de',
44
90
  password: 'secret')
45
- user.roster << Vines::Contact.new(
46
- jid: 'contact1@domain.tld/resource2',
47
- name: 'Contact 1')
48
91
  db.save_user(user)
49
- user = db.find_user('test@test.de')
50
-
51
- assert (user != nil), "no user found"
52
- assert_equal "test@test.de", user.jid.to_s
53
-
54
- assert_equal 1, user.roster.length
55
- assert_equal "contact1@domain.tld", user.roster[0].jid.to_s
56
- assert_equal "Contact 1", user.roster[0].name
92
+ assert_nil db.find_user('test2@test.de')
57
93
  end
58
94
  end
59
95
 
@@ -63,17 +99,17 @@ describe Vines::Storage::Sql do
63
99
  user = db.find_user(nil)
64
100
  assert_nil user
65
101
 
66
- user = db.find_user("test@local.host")
102
+ user = db.find_user(@test_user[:jid])
67
103
  assert (user != nil), "no user found"
68
- assert_equal "test", user.name
104
+ assert_equal @test_user[:name], user.name
69
105
 
70
- user = db.find_user(Vines::JID.new("test@local.host"))
106
+ user = db.find_user(Vines::JID.new(@test_user[:jid]))
71
107
  assert (user != nil), "no user found"
72
- assert_equal "test", user.name
108
+ assert_equal @test_user[:name], user.name
73
109
 
74
- user = db.find_user(Vines::JID.new("test@local.host/resource"))
110
+ user = db.find_user(Vines::JID.new("#{@test_user[:jid]}/resource"))
75
111
  assert (user != nil), "no user found"
76
- assert_equal "test", user.name
112
+ assert_equal @test_user[:name], user.name
77
113
  end
78
114
  end
79
115
 
@@ -87,14 +123,14 @@ describe Vines::Storage::Sql do
87
123
 
88
124
  # user credential auth
89
125
  pepper = "065eb8798b181ff0ea2c5c16aee0ff8b70e04e2ee6bd6e08b49da46924223e39127d5335e466207d42bf2a045c12be5f90e92012a4f05f7fc6d9f3c875f4c95b"
90
- user = db.authenticate("test@test.de", "pppppp#{pepper}")
126
+ user = db.authenticate(@test_user[:jid], "pppppp#{pepper}")
91
127
  assert (user != nil), "no user found"
92
- assert_equal "test", user.name
128
+ assert_equal @test_user[:name], user.name
93
129
 
94
130
  # user token auth
95
- user = db.authenticate("test@test.de", "1234")
131
+ user = db.authenticate(@test_user[:jid], @test_user[:token])
96
132
  assert (user != nil), "no user found"
97
- assert_equal "test", user.name
133
+ assert_equal @test_user[:name], user.name
98
134
  end
99
135
  end
100
136
 
@@ -106,30 +142,30 @@ describe Vines::Storage::Sql do
106
142
  root = Nokogiri::XML(%q{<characters xmlns="urn:wonderland"/>}).root
107
143
  bad_name = Nokogiri::XML(%q{<not_characters xmlns="urn:wonderland"/>}).root
108
144
  bad_ns = Nokogiri::XML(%q{<characters xmlns="not:wonderland"/>}).root
109
-
145
+
110
146
  node = db.find_fragment(nil, nil)
111
147
  assert_nil node
112
-
148
+
113
149
  node = db.find_fragment('full@wonderland.lit', bad_name)
114
150
  assert_nil node
115
-
151
+
116
152
  node = db.find_fragment('full@wonderland.lit', bad_ns)
117
153
  assert_nil node
118
-
154
+
119
155
  node = db.find_fragment('full@wonderland.lit', root)
120
156
  assert (node != nil), "node should include fragment"
121
157
  assert_equal fragment.to_s, node.to_s
122
-
158
+
123
159
  node = db.find_fragment(Vines::JID.new('full@wonderland.lit'), root)
124
160
  assert (node != nil), "node should include fragment"
125
161
  assert_equal fragment.to_s, node.to_s
126
-
162
+
127
163
  node = db.find_fragment(Vines::JID.new('full@wonderland.lit/resource'), root)
128
164
  assert (node != nil), "node should include fragment"
129
165
  assert_equal fragment.to_s, node.to_s
130
166
  end
131
167
  end
132
-
168
+
133
169
  def test_save_fragment
134
170
  skip("not working probably")
135
171
 
@@ -3,20 +3,13 @@
3
3
  require 'test_helper'
4
4
 
5
5
  describe Vines::Stream::Http::Request do
6
- PASSWORD = File.expand_path('../passwords')
7
- INDEX = File.expand_path('index.html')
6
+ PASSWORD = File.expand_path('../passwords').freeze
7
+ INDEX = File.expand_path('index.html').freeze
8
8
 
9
9
  before do
10
10
  File.open(PASSWORD, 'w') {|f| f.puts '/etc/passwd contents' }
11
11
  File.open(INDEX, 'w') {|f| f.puts 'index.html contents' }
12
-
13
12
  @stream = MiniTest::Mock.new
14
- @parser = MiniTest::Mock.new
15
- @parser.expect(:headers, {'Content-Type' => 'text/html', 'Host' => 'wonderland.lit'})
16
- @parser.expect(:http_method, 'GET')
17
- @parser.expect(:request_path, '/blogs/12')
18
- @parser.expect(:request_url, '/blogs/12?ok=true')
19
- @parser.expect(:query_string, 'ok=true')
20
13
  end
21
14
 
22
15
  after do
@@ -26,21 +19,26 @@ describe Vines::Stream::Http::Request do
26
19
 
27
20
  describe 'initialize' do
28
21
  it 'copies request info from parser' do
29
- request = Vines::Stream::Http::Request.new(@stream, @parser, '<html></html>')
30
- assert_equal request.headers, {'Content-Type' => 'text/html', 'Host' => 'wonderland.lit'}
22
+ headers = ['Host: wonderland.lit', 'Content-Type: text/html']
23
+ parser = parser('GET', '/blogs/12?ok=true', headers)
24
+ request = Vines::Stream::Http::Request.new(@stream, parser, '<html></html>')
25
+
26
+ assert_equal request.headers, {'Host' => 'wonderland.lit', 'Content-Type' => 'text/html'}
31
27
  assert_equal request.method, 'GET'
32
28
  assert_equal request.path, '/blogs/12'
33
29
  assert_equal request.url, '/blogs/12?ok=true'
34
30
  assert_equal request.query, 'ok=true'
35
31
  assert_equal request.body, '<html></html>'
36
32
  assert @stream.verify
37
- assert @parser.verify
38
33
  end
39
34
  end
40
35
 
41
36
  describe 'reply_with_file' do
42
37
  it 'returns 404 file not found' do
43
- request = Vines::Stream::Http::Request.new(@stream, @parser, '<html></html>')
38
+ headers = ['Host: wonderland.lit', 'Content-Type: text/html']
39
+ parser = parser('GET', '/blogs/12?ok=true', headers)
40
+ request = Vines::Stream::Http::Request.new(@stream, parser, '<html></html>')
41
+
44
42
  headers = [
45
43
  "HTTP/1.1 404 Not Found",
46
44
  "Content-Length: 0"
@@ -50,17 +48,11 @@ describe Vines::Stream::Http::Request do
50
48
 
51
49
  request.reply_with_file(Dir.pwd)
52
50
  assert @stream.verify
53
- assert @parser.verify
54
51
  end
55
52
 
56
53
  it 'prevents directory traversal with 404 response' do
57
- parser = MiniTest::Mock.new
58
- parser.expect(:headers, {'Content-Type' => 'text/html', 'Host' => 'wonderland.lit'})
59
- parser.expect(:http_method, 'GET')
60
- parser.expect(:request_path, '/../passwords')
61
- parser.expect(:request_url, '/../passwords')
62
- parser.expect(:query_string, '')
63
-
54
+ headers = ['Host: wonderland.lit', 'Content-Type: text/html']
55
+ parser = parser('GET', '/../passwords', headers)
64
56
  request = Vines::Stream::Http::Request.new(@stream, parser, '<html></html>')
65
57
 
66
58
  headers = [
@@ -72,17 +64,11 @@ describe Vines::Stream::Http::Request do
72
64
 
73
65
  request.reply_with_file(Dir.pwd)
74
66
  assert @stream.verify
75
- assert parser.verify
76
67
  end
77
68
 
78
69
  it 'serves index.html for directory request' do
79
- parser = MiniTest::Mock.new
80
- parser.expect(:headers, {'Content-Type' => 'text/html', 'Host' => 'wonderland.lit'})
81
- parser.expect(:http_method, 'GET')
82
- parser.expect(:request_path, '/')
83
- parser.expect(:request_url, '/?ok=true')
84
- parser.expect(:query_string, 'ok=true')
85
-
70
+ headers = ['Host: wonderland.lit', 'Content-Type: text/html']
71
+ parser = parser('GET', '/?ok=true', headers)
86
72
  request = Vines::Stream::Http::Request.new(@stream, parser, '<html></html>')
87
73
 
88
74
  mtime = File.mtime(INDEX).utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
@@ -98,17 +84,11 @@ describe Vines::Stream::Http::Request do
98
84
 
99
85
  request.reply_with_file(Dir.pwd)
100
86
  assert @stream.verify
101
- assert parser.verify
102
87
  end
103
88
 
104
89
  it 'redirects for missing trailing slash' do
105
- parser = MiniTest::Mock.new
106
- parser.expect(:headers, {'Content-Type' => 'text/html', 'Host' => 'wonderland.lit'})
107
- parser.expect(:http_method, 'GET')
108
- parser.expect(:request_path, '/http')
109
- parser.expect(:request_url, '/http?ok=true')
110
- parser.expect(:query_string, 'ok=true')
111
-
90
+ headers = ['Host: wonderland.lit', 'Content-Type: text/html']
91
+ parser = parser('GET', '/http?ok=true', headers)
112
92
  request = Vines::Stream::Http::Request.new(@stream, parser, '<html></html>')
113
93
 
114
94
  headers = [
@@ -121,23 +101,18 @@ describe Vines::Stream::Http::Request do
121
101
  # so the /http url above will work
122
102
  request.reply_with_file(File.expand_path('../../', __FILE__))
123
103
  assert @stream.verify
124
- assert parser.verify
125
104
  end
126
105
  end
127
106
 
128
107
  describe 'reply_to_options' do
129
108
  it 'returns cors headers' do
130
- parser = MiniTest::Mock.new
131
- parser.expect(:headers, {
132
- 'Content-Type' => 'text/xml',
133
- 'Host' => 'wonderland.lit',
134
- 'Origin' => 'remote.wonderland.lit',
135
- 'Access-Control-Request-Headers' => 'Content-Type, Origin'})
136
- parser.expect(:http_method, 'OPTIONS')
137
- parser.expect(:request_path, '/xmpp')
138
- parser.expect(:request_url, '/xmpp')
139
- parser.expect(:query_string, '')
140
-
109
+ headers = [
110
+ 'Content-Type: text/xml',
111
+ 'Host: wonderland.lit',
112
+ 'Origin: remote.wonderland.lit',
113
+ 'Access-Control-Request-Headers: Content-Type, Origin'
114
+ ]
115
+ parser = parser('OPTIONS', '/xmpp', headers)
141
116
  request = Vines::Stream::Http::Request.new(@stream, parser, '')
142
117
 
143
118
  headers = [
@@ -152,7 +127,6 @@ describe Vines::Stream::Http::Request do
152
127
  @stream.expect(:stream_write, nil, ["#{headers}\r\n\r\n"])
153
128
  request.reply_to_options
154
129
  assert @stream.verify
155
- assert parser.verify
156
130
  end
157
131
  end
158
132
 
@@ -168,6 +142,21 @@ describe Vines::Stream::Http::Request do
168
142
 
169
143
  private
170
144
 
145
+ # Create a parser that has completed one valid HTTP request.
146
+ #
147
+ # method - The HTTP method String (e.g. 'GET', 'POST').
148
+ # url - The request URL String (e.g. '/blogs/12?ok=true').
149
+ # headers - The optional Array of request headers.
150
+ #
151
+ # Returns an Http::Parser.
152
+ def parser(method, url, headers = [])
153
+ head = ["#{method} #{url} HTTP/1.1"].concat(headers).join("\r\n")
154
+ body = '<html></html>'
155
+ Http::Parser.new.tap do |parser|
156
+ parser << "%s\r\n\r\n%s" % [head, body]
157
+ end
158
+ end
159
+
171
160
  def reply_with_cookie(cookie)
172
161
  config = Vines::Config.new do
173
162
  host 'wonderland.lit' do
@@ -178,15 +167,12 @@ describe Vines::Stream::Http::Request do
178
167
  end
179
168
  end
180
169
 
181
- parser = MiniTest::Mock.new
182
- parser.expect(:headers, {
183
- 'Content-Type' => 'text/xml',
184
- 'Host' => 'wonderland.lit',
185
- 'Origin' => 'remote.wonderland.lit'})
186
- parser.expect(:http_method, 'POST')
187
- parser.expect(:request_path, '/xmpp')
188
- parser.expect(:request_url, '/xmpp')
189
- parser.expect(:query_string, '')
170
+ headers = [
171
+ 'Content-Type: text/xml',
172
+ 'Host: wonderland.lit',
173
+ 'Origin: remote.wonderland.lit'
174
+ ]
175
+ parser = parser('POST', '/xmpp', headers)
190
176
 
191
177
  request = Vines::Stream::Http::Request.new(@stream, parser, '')
192
178
  message = '<message>hello</message>'
@@ -204,6 +190,5 @@ describe Vines::Stream::Http::Request do
204
190
  @stream.expect(:config, config)
205
191
  request.reply(message, 'application/xml')
206
192
  assert @stream.verify
207
- assert parser.verify
208
193
  end
209
194
  end