diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-07-22 16:55:54 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-07-22 16:55:54 +0100 |
commit | 25b32914b72a5f709eca773f3511cc89c2e710c2 (patch) | |
tree | 4dab9e78e4c6b49220a837b38d463328c05e2983 /test/tc_mauve_source_list.rb | |
parent | 3185e5d746abda1b7f42ecdbd74ec14359fda3bc (diff) | |
parent | fd23821950f0562a8995735105cd31fdc6d55933 (diff) |
merge
Diffstat (limited to 'test/tc_mauve_source_list.rb')
-rw-r--r-- | test/tc_mauve_source_list.rb | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/test/tc_mauve_source_list.rb b/test/tc_mauve_source_list.rb new file mode 100644 index 0000000..d07791f --- /dev/null +++ b/test/tc_mauve_source_list.rb @@ -0,0 +1,78 @@ +$:.unshift "../lib/" + +require 'test/unit' +require 'mauve/source_list' +require 'th_mauve_resolv' +require 'pp' + +class TcMauveSourceList < Test::Unit::TestCase + + def test_hostname_match + sl = Mauve::SourceList.new("test") + assert_equal("test", sl.label) + + list = %w(a.example.com b.example.com c.example.com) + assert_nothing_raised{ sl += list } + + assert_equal(list, sl.list) + + assert( sl.includes?("a.example.com") ) + assert( !sl.includes?("d.example.com") ) + end + + def test_regex_match + sl = Mauve::SourceList.new("test") + + assert_nothing_raised{ sl += %w([a-c].example.com *.[d-f].example.com g.example.com) } + + %w(a.example.com www.f.example.com www.a.example.com g.example.com www.other.a.example.com).each do |h| + assert( sl.includes?(h), "#{h} did not match") + end + + %w(d.example.com a.example.com.other d.example.com).each do |h| + assert( !sl.includes?(h), "#{h} matched when it shouldn't have") + end + end + + def test_ip_match + sl = Mauve::SourceList.new("test") + + assert_nothing_raised{ sl += %w(test-1.example.com 1.2.3.5 2001:1:2:3::5 1.2.4.0/24 2001:1:2:4::/64) } + + %w(1.2.3.4 2001:1:2:3::4 1.2.3.5 2001:1:2:3::5 test-2.example.com 1.2.4.23 2001:1:2:4::23 ).each do |h| + assert( sl.includes?(h), "#{h} did not match") + end + + %w(1.2.3.6 2001:1:2:3::6 test-3.example.com 1.2.5.23 2001:1:2:5::23 ).each do |h| + assert( !sl.includes?(h), "#{h} matched when it shouldn't have") + end + + end + + def test_uri_match + sl = Mauve::SourceList.new("test") + + assert_nothing_raised { sl += "test-1.example.com" } + + %w(https://www.example.com ftp://test-1.example.com http://1.2.3.4 https://[2001:1:2:3::4]).each do |uri| + assert( sl.includes?(uri), "#{uri} did not match") + end + + %w(http://www.google.com ftp://www2.example.com).each do |uri| + assert( !sl.includes?(uri), "#{uri} matched when it shouldn't have" ) + end + end + + def test_ip_crossmatch + sl = Mauve::SourceList.new("test") + assert_nothing_raised { sl += "test-1.example.com" } + assert( sl.includes?("www.example.com"), "www.example.com not found in #{sl.list}" ) + + sl = Mauve::SourceList.new("test") + assert_nothing_raised { sl += "2001::/3" } + assert( sl.includes?("www2.example.com"), "www2.example.com not found in #{sl.list}" ) + end + +end + + |