test/config_test.rb in vines-0.2.1 vs test/config_test.rb in vines-0.3.0
- old
+ new
@@ -18,11 +18,11 @@
host 'wonderland.lit' do
storage 'fs' do
dir '.'
end
end
- host 'wonderland.lit' do
+ host 'WONDERLAND.LIT' do
storage 'fs' do
dir '.'
end
end
end
@@ -39,89 +39,10 @@
end
end
end
end
- def test_missing_storage
- assert_raises(RuntimeError) do
- Vines::Config.new do
- host 'wonderland.lit' do
- # missing storage
- end
- end
- end
- end
-
- def test_bad_storage
- assert_raises(RuntimeError) do
- Vines::Config.new do
- host 'wonderland.lit' do
- storage 'bogus' do
- # no bogus storage implementation
- end
- end
- end
- end
- end
-
- def test_duplicate_storage
- assert_raises(RuntimeError) do
- Vines::Config.new do
- host 'wonderland.lit' do
- storage('fs') { dir '.' }
- storage('fs') { dir '.' }
- end
- end
- end
- end
-
- def test_good_storage_raises_no_errors
- Vines::Config.new do
- host 'wonderland.lit' do
- storage 'fs' do
- dir '.'
- end
- end
- end
- end
-
- def test_ldap_added_to_storage
- config = Vines::Config.new do
- host 'wonderland.lit' do
- storage(:fs) { dir '.' }
- # added after storage
- ldap 'ldap.wonderland.lit', 1636 do
- tls true
- dn 'cn=Directory Manager'
- password 'secr3t'
- basedn 'dc=wonderland,dc=lit'
- object_class 'person'
- user_attr 'uid'
- name_attr 'cn'
- end
- end
-
- host 'verona.lit' do
- ldap 'ldap.verona.lit', 1636 do
- tls true
- dn 'cn=Directory Manager'
- password 'secr3t'
- basedn 'dc=wonderland,dc=lit'
- object_class 'person'
- user_attr 'uid'
- name_attr 'cn'
- end
- # added before storage
- storage(:fs) { dir '.' }
- end
- end
- %w[wonderland.lit verona.lit].each do |domain|
- refute_nil config.vhosts[domain].ldap
- assert config.vhosts[domain].ldap?
- end
- end
-
def test_configure
config = Vines::Config.configure do
host 'wonderland.lit' do
storage :fs do
dir '.'
@@ -138,11 +59,12 @@
storage(:fs) { dir '.' }
end
end
assert_equal ['wonderland.lit'], config.vhosts.keys
assert config.vhost?('wonderland.lit')
- assert !config.vhost?('bogus')
+ refute config.vhost?('tea.wonderland.lit')
+ refute config.vhost?('bogus')
end
def test_port_lookup
config = Vines::Config.new do
host 'wonderland.lit' do
@@ -203,23 +125,21 @@
assert_equal Vines::Config::ClientPort, port.class
assert_equal '0.0.0.0', port.host
assert_equal 5222, port.port
assert_equal 131_072, port.max_stanza_size
assert_equal 5, port.max_resources_per_account
- refute port.private_storage?
assert_equal Vines::Stream::Client, port.stream
- assert_same config, port.config
+ assert_same config, port.config
assert_equal 1, config.ports.size
end
def test_configured_client
config = Vines::Config.new do
host 'wonderland.lit' do
storage(:fs) { dir '.' }
end
client '0.0.0.1', 42 do
- private_storage true
max_stanza_size 60_000
max_resources_per_account 1
end
end
port = config.ports.first
@@ -227,13 +147,12 @@
assert_equal Vines::Config::ClientPort, port.class
assert_equal '0.0.0.1', port.host
assert_equal 42, port.port
assert_equal 60_000, port.max_stanza_size
assert_equal 1, port.max_resources_per_account
- assert port.private_storage?
assert_equal Vines::Stream::Client, port.stream
- assert_same config, port.config
+ assert_same config, port.config
assert_equal 1, config.ports.size
end
def test_max_stanza_size
config = Vines::Config.new do
@@ -260,11 +179,11 @@
assert_equal Vines::Config::ServerPort, port.class
assert_equal '0.0.0.0', port.host
assert_equal 5269, port.port
assert_equal 131_072, port.max_stanza_size
assert_equal Vines::Stream::Server, port.stream
- assert_same config, port.config
+ assert_same config, port.config
assert_equal 1, config.ports.size
end
def test_configured_server
config = Vines::Config.new do
@@ -284,11 +203,11 @@
assert_equal Vines::Config::ServerPort, port.class
assert_equal '0.0.0.1', port.host
assert_equal 42, port.port
assert_equal 60_000, port.max_stanza_size
assert_equal Vines::Stream::Server, port.stream
- assert_same config, port.config
+ assert_same config, port.config
assert_equal 1, config.ports.size
end
def test_default_http
config = Vines::Config.new do
@@ -304,24 +223,22 @@
assert_equal 5280, port.port
assert_equal 131_072, port.max_stanza_size
assert_equal 5, port.max_resources_per_account
assert_equal File.join(Dir.pwd, 'web'), port.root
assert_equal '/xmpp', port.bind
- refute port.private_storage?
assert_equal Vines::Stream::Http, port.stream
- assert_same config, port.config
+ assert_same config, port.config
assert_equal 1, config.ports.size
end
def test_configured_http
config = Vines::Config.new do
host 'wonderland.lit' do
storage(:fs) { dir '.' }
end
http '0.0.0.1', 42 do
bind '/custom'
- private_storage true
max_stanza_size 60_000
max_resources_per_account 1
root '/var/www/html'
end
end
@@ -332,13 +249,12 @@
assert_equal 42, port.port
assert_equal 60_000, port.max_stanza_size
assert_equal 1, port.max_resources_per_account
assert_equal '/var/www/html', port.root
assert_equal '/custom', port.bind
- assert port.private_storage?
assert_equal Vines::Stream::Http, port.stream
- assert_same config, port.config
+ assert_same config, port.config
assert_equal 1, config.ports.size
end
def test_default_component
config = Vines::Config.new do
@@ -347,44 +263,36 @@
end
component
end
port = config.ports.first
refute_nil port
- assert port.components.empty?
- assert_nil port.password('bogus')
assert_equal Vines::Config::ComponentPort, port.class
assert_equal '0.0.0.0', port.host
assert_equal 5347, port.port
assert_equal 131_072, port.max_stanza_size
assert_equal Vines::Stream::Component, port.stream
- assert_same config, port.config
+ assert_same config, port.config
assert_equal 1, config.ports.size
end
def test_configured_component
config = Vines::Config.new do
host 'wonderland.lit' do
storage(:fs) { dir '.' }
end
component '0.0.0.1', 42 do
max_stanza_size 60_000
- components 'tea.wonderland.lit' => 'secr3t',
- 'cake.wonderland.lit' => 'passw0rd'
end
end
port = config.ports.first
refute_nil port
- assert_equal 2, port.components.size
- assert_equal 'secr3t', port.password('tea.wonderland.lit')
- assert_equal 'passw0rd', port.password('cake.wonderland.lit')
- assert_nil port.password('bogus')
assert_equal Vines::Config::ComponentPort, port.class
assert_equal '0.0.0.1', port.host
assert_equal 42, port.port
assert_equal 60_000, port.max_stanza_size
assert_equal Vines::Stream::Component, port.stream
- assert_same config, port.config
+ assert_same config, port.config
assert_equal 1, config.ports.size
end
def test_invalid_log_level
assert_raises(RuntimeError) do
@@ -403,7 +311,240 @@
host 'wonderland.lit' do
storage(:fs) { dir '.' }
end
end
assert_equal Logger::ERROR, Class.new.extend(Vines::Log).log.level
+ end
+
+ def test_cross_domain_messages
+ config = Vines::Config.new do
+ host 'wonderland.lit' do
+ storage(:fs) { dir '.' }
+ end
+ host 'verona.lit' do
+ cross_domain_messages true
+ storage(:fs) { dir '.' }
+ end
+ end
+ refute config.vhosts['wonderland.lit'].cross_domain_messages?
+ assert config.vhosts['verona.lit'].cross_domain_messages?
+ end
+
+ def test_local_jid?
+ config = Vines::Config.new do
+ host 'wonderland.lit', 'verona.lit' do
+ storage(:fs) { dir '.' }
+ end
+ end
+ refute config.local_jid?(nil)
+ refute config.local_jid?('alice@wonderland.lit', nil)
+ assert config.local_jid?('alice@wonderland.lit')
+ assert config.local_jid?('alice@wonderland.lit', 'romeo@verona.lit')
+ refute config.local_jid?('alice@wonderland.lit', 'romeo@bogus.lit')
+ refute config.local_jid?('alice@tea.wonderland.lit')
+ refute config.local_jid?('alice@bogus.lit')
+ end
+
+ def test_missing_addresses_not_allowed
+ config = Vines::Config.new do
+ host 'wonderland.lit', 'verona.lit' do
+ storage(:fs) { dir '.' }
+ end
+ end
+ refute config.allowed?(nil, nil)
+ refute config.allowed?('', '')
+ end
+
+ def test_same_domain_allowed
+ config = Vines::Config.new do
+ host 'wonderland.lit', 'verona.lit' do
+ storage(:fs) { dir '.' }
+ end
+ end
+ alice = Vines::JID.new('alice@wonderland.lit')
+ hatter = Vines::JID.new('hatter@wonderland.lit')
+ assert config.allowed?(alice, hatter)
+ end
+
+ def test_both_vhosts_with_cross_domain_allowed
+ config = Vines::Config.new do
+ host 'wonderland.lit', 'verona.lit' do
+ cross_domain_messages true
+ storage(:fs) { dir '.' }
+ end
+ end
+ alice = Vines::JID.new('alice@wonderland.lit')
+ romeo = Vines::JID.new('romeo@verona.lit')
+ assert config.allowed?(alice, romeo)
+ assert config.allowed?(romeo, alice)
+ end
+
+ def test_one_vhost_with_cross_domain_not_allowed
+ config = Vines::Config.new do
+ host 'wonderland.lit' do
+ cross_domain_messages true
+ storage(:fs) { dir '.' }
+ end
+ host 'verona.lit' do
+ cross_domain_messages false
+ storage(:fs) { dir '.' }
+ end
+ end
+ alice = Vines::JID.new('alice@wonderland.lit')
+ romeo = Vines::JID.new('romeo@verona.lit')
+ refute config.allowed?(alice, romeo)
+ refute config.allowed?(romeo, alice)
+ end
+
+ def test_same_domain_component_to_component_allowed
+ config = Vines::Config.new do
+ host 'wonderland.lit' do
+ cross_domain_messages false
+ storage(:fs) { dir '.' }
+ components 'tea' => 'secr3t', cake: 'passw0rd'
+ end
+ end
+ alice = Vines::JID.new('alice@tea.wonderland.lit')
+ hatter = Vines::JID.new('hatter@cake.wonderland.lit')
+ assert config.allowed?(alice, alice)
+ assert config.allowed?(alice, hatter)
+ assert config.allowed?(hatter, alice)
+ end
+
+ def test_cross_domain_component_to_component_allowed
+ config = Vines::Config.new do
+ host 'wonderland.lit', 'verona.lit' do
+ cross_domain_messages true
+ storage(:fs) { dir '.' }
+ components 'tea' => 'secr3t', cake: 'passw0rd'
+ end
+ end
+ alice = Vines::JID.new('alice@tea.wonderland.lit')
+ romeo = Vines::JID.new('romeo@cake.verona.lit')
+ assert config.allowed?(alice, romeo)
+ assert config.allowed?(romeo, alice)
+ end
+
+ def test_cross_domain_component_to_component_not_allowed
+ config = Vines::Config.new do
+ host 'wonderland.lit' do
+ cross_domain_messages true
+ storage(:fs) { dir '.' }
+ components 'tea' => 'secr3t', cake: 'passw0rd'
+ end
+ end
+ config = Vines::Config.new do
+ host 'verona.lit' do
+ cross_domain_messages false
+ storage(:fs) { dir '.' }
+ components 'party' => 'secr3t'
+ end
+ end
+ alice = Vines::JID.new('alice@tea.wonderland.lit')
+ romeo = Vines::JID.new('romeo@party.verona.lit')
+ refute config.allowed?(alice, romeo)
+ refute config.allowed?(romeo, alice)
+ end
+
+ def test_same_domain_user_to_component_allowed
+ config = Vines::Config.new do
+ host 'wonderland.lit' do
+ cross_domain_messages false
+ storage(:fs) { dir '.' }
+ components 'tea' => 'secr3t', cake: 'passw0rd'
+ end
+ end
+ alice = Vines::JID.new('alice@wonderland.lit')
+ comp = Vines::JID.new('hatter@cake.wonderland.lit')
+ assert config.allowed?(alice, comp)
+ assert config.allowed?(comp, alice)
+ end
+
+ def test_cross_domain_user_to_component_allowed
+ config = Vines::Config.new do
+ host 'wonderland.lit', 'verona.lit' do
+ cross_domain_messages true
+ storage(:fs) { dir '.' }
+ components 'tea' => 'secr3t', cake: 'passw0rd'
+ end
+ end
+ alice = Vines::JID.new('alice@tea.wonderland.lit')
+ romeo = Vines::JID.new('romeo@verona.lit')
+ assert config.allowed?(alice, romeo)
+ assert config.allowed?(romeo, alice)
+ end
+
+ def test_cross_domain_user_to_component_not_allowed
+ config = Vines::Config.new do
+ host 'wonderland.lit' do
+ cross_domain_messages true
+ storage(:fs) { dir '.' }
+ components 'tea' => 'secr3t', cake: 'passw0rd'
+ end
+ end
+ config = Vines::Config.new do
+ host 'verona.lit' do
+ cross_domain_messages false
+ storage(:fs) { dir '.' }
+ end
+ end
+ alice = Vines::JID.new('alice@tea.wonderland.lit')
+ romeo = Vines::JID.new('romeo@verona.lit')
+ refute config.allowed?(alice, romeo)
+ refute config.allowed?(romeo, alice)
+ end
+
+ def test_remote_user_to_component_allowed
+ config = Vines::Config.new do
+ host 'wonderland.lit' do
+ cross_domain_messages true
+ storage(:fs) { dir '.' }
+ components 'tea' => 'secr3t', cake: 'passw0rd'
+ end
+ host 'verona.lit' do
+ cross_domain_messages false
+ storage(:fs) { dir '.' }
+ components 'tea' => 'secr3t', cake: 'passw0rd'
+ end
+ end
+ alice = Vines::JID.new('alice@tea.wonderland.lit')
+ romeo = Vines::JID.new('romeo@tea.verona.lit')
+ hamlet = Vines::JID.new('hamlet@denmark.lit')
+ assert config.allowed?(alice, hamlet)
+ assert config.allowed?(hamlet, alice)
+ refute config.allowed?(romeo, hamlet)
+ refute config.allowed?(hamlet, romeo)
+ end
+
+ def test_remote_user_to_local_user_allowed
+ config = Vines::Config.new do
+ host 'wonderland.lit' do
+ cross_domain_messages true
+ storage(:fs) { dir '.' }
+ end
+ host 'verona.lit' do
+ cross_domain_messages false
+ storage(:fs) { dir '.' }
+ end
+ end
+ alice = Vines::JID.new('alice@wonderland.lit')
+ romeo = Vines::JID.new('romeo@verona.lit')
+ hamlet = Vines::JID.new('hamlet@denmark.lit')
+ assert config.allowed?(alice, hamlet)
+ assert config.allowed?(hamlet, alice)
+ refute config.allowed?(romeo, hamlet)
+ refute config.allowed?(hamlet, romeo)
+ end
+
+ def test_remote_user_to_remote_user_not_allowed
+ config = Vines::Config.new do
+ host 'wonderland.lit' do
+ cross_domain_messages true
+ storage(:fs) { dir '.' }
+ end
+ end
+ romeo = Vines::JID.new('romeo@verona.lit')
+ hamlet = Vines::JID.new('hamlet@denmark.lit')
+ refute config.allowed?(romeo, hamlet)
+ refute config.allowed?(hamlet, romeo)
end
end