aboutsummaryrefslogtreecommitdiff
path: root/test/tc_mauve_source_list.rb
blob: d07791fe633a194d2e1273b398bd10852ff0fd51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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