1 # acltest.rb - ACL unit test
2 # Copyright (c) 2000 Masatoshi SEKI
4 # acltest.rb is copyrighted free software by Masatoshi SEKI.
5 # You can redistribute it and/or modify it under the same terms as Ruby.
12 list = %w(127.0.0.1 localhost
13 192.168.1.1 x68k.linux.or.jp
14 192.168.1.2 lc630.macos.or.jp
15 192.168.1.3 lib30.win32.or.jp
16 192.168.1.4 ns00.linux.or.jp
17 192.168.1.5 yum.macos.or.jp
18 ::ffff:192.168.1.5 ipv6.macos.or.jp
19 ::192.168.1.5 too.yumipv6.macos.or.jp
20 192.168.1.254 comstarz.foo.or.jp)
22 @hostlist = Array.new(list.size / 2)
23 @hostlist.each_index do |idx|
24 @hostlist[idx] = ["AF_INET", 10000, list[idx * 2 + 1], list[idx * 2]]
29 @hosts[h[2].split('.')[0]] = h
32 attr_reader(:hostlist, :hosts)
36 class ACLEntryTest < Test::Unit::TestCase
37 HOSTS = SampleHosts.new
40 @hostlist = HOSTS.hostlist
45 a = ACL::ACLEntry.new("*")
46 b = ACL::ACLEntry.new("all")
54 a = ACL::ACLEntry.new('::ffff:192.0.0.0/104')
55 assert(! a.match(@hosts['localhost']))
56 assert(a.match(@hosts['yum']))
57 assert(a.match(@hosts['ipv6']))
58 assert(! a.match(@hosts['too']))
62 a = ACL::ACLEntry.new('192.0.0.0/8')
63 assert(! a.match(@hosts['localhost']))
64 assert(a.match(@hosts['yum']))
66 a = ACL::ACLEntry.new('192.168.0.1/255.255.0.255')
67 assert(! a.match(@hosts['localhost']))
68 assert(! a.match(@hosts['yum']))
69 assert(a.match(@hosts['x68k']))
71 a = ACL::ACLEntry.new('192.168.1.0/24')
72 assert(! a.match(@hosts['localhost']))
73 assert(a.match(@hosts['yum']))
74 assert(a.match(@hosts['x68k']))
76 a = ACL::ACLEntry.new('92.0.0.0/8')
77 assert(! a.match(@hosts['localhost']))
78 assert(! a.match(@hosts['yum']))
79 assert(! a.match(@hosts['x68k']))
81 a = ACL::ACLEntry.new('127.0.0.1/255.0.0.255')
82 assert(a.match(@hosts['localhost']))
83 assert(! a.match(@hosts['yum']))
84 assert(! a.match(@hosts['x68k']))
88 a = ACL::ACLEntry.new('*.jp')
89 assert(! a.match(@hosts['localhost']))
90 assert(a.match(@hosts['yum']))
92 a = ACL::ACLEntry.new('yum.*.jp')
93 assert(a.match(@hosts['yum']))
94 assert(! a.match(@hosts['lc630']))
96 a = ACL::ACLEntry.new('*.macos.or.jp')
97 assert(a.match(@hosts['yum']))
98 assert(a.match(@hosts['lc630']))
99 assert(! a.match(@hosts['lib30']))
103 class ACLListTest < Test::Unit::TestCase
104 HOSTS = SampleHosts.new
107 @hostlist = HOSTS.hostlist
113 acl= ACL::ACLList.new
123 @hostlist.each do |h|
129 a = build(%w(localhost 127.0.0.0/8 yum.* *))
130 @hostlist.each do |h|
136 a = build(%w(192.0.0.1/255.0.0.255 yum.*.jp))
137 assert(a.match(@hosts['yum']))
138 assert(a.match(@hosts['x68k']))
139 assert(! a.match(@hosts['lc630']))
143 a = build(%w(*.linux.or.jp))
144 assert(!a.match(@hosts['yum']))
145 assert(a.match(@hosts['x68k']))
146 assert(!a.match(@hosts['lc630']))
150 class ACLTest < Test::Unit::TestCase
151 HOSTS = SampleHosts.new
154 @hostlist = HOSTS.hostlist
160 @hostlist.each do |h|
161 assert(a.allow_addr?(h))
166 a = ACL.new([], ACL::ALLOW_DENY)
167 @hostlist.each do |h|
168 assert(! a.allow_addr?(h))
178 assert(a.allow_addr?(@hosts['x68k']))
179 assert(a.allow_addr?(@hosts['localhost']))
180 assert(! a.allow_addr?(@hosts['lc630']))
184 data = %w(deny 192.0.0.0/8
188 a = ACL.new(data, ACL::ALLOW_DENY)
189 assert(!a.allow_addr?(@hosts['x68k']))
190 assert(a.allow_addr?(@hosts['localhost']))
191 assert(! a.allow_addr?(@hosts['lc630']))