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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
# $Id: framework.rb,v 1.48 2003/11/07 16:58:39 sdalu Exp $
#
# CONTACT : zonecheck@nic.fr
# AUTHOR : Stephane D'Alu <sdalu@nic.fr>
#
# CREATED : 2002/08/02 13:58:17
# REVISION : $Revision: 1.48 $
# DATE : $Date: 2003/11/07 16:58:39 $
#
# CONTRIBUTORS: (see also CREDITS file)
#
#
# LICENSE : GPL v2 (or MIT/X11-like after agreement)
# COPYRIGHT : AFNIC (c) 2003
#
# This file is part of ZoneCheck.
#
# ZoneCheck is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# ZoneCheck is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ZoneCheck; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
require 'cache'
require 'cachemanager'
require 'msgcat'
##
## Class that should be inherited by every test set
##
class Test
##
## Abstract class for: Succeed, Failed, Error
##
class Result # --> ABSTRACT <--
class Desc
attr_writer :error, :details
attr_reader :error, :details
attr_reader :check
def initialize(check=true)
@check = check
@error = nil # Error message (ie: Exception)
@details = nil
end
def hash
@check ^ @error.hash ^ @msg.details
end
def eql?(other)
(@check == other.instance_eval('@check') &&
@error == other.instance_eval('@error') &&
@details == other.instance_eval('@details'))
end
alias == eql?
end
attr_reader :testname, :desc, :ns, :ip
def initialize(testname, desc, ns=nil, ip=nil)
@testname = testname
@desc = desc
@ns = ns
@ip = ip
end
def eql?(other)
self.instance_of?(Result) && other.instance_of?(Result) &&
self.testname == other.testname &&
self.ns == other.ns &&
self.ip == other.ip
end
alias == eql?
def hash
testname.hash ^ ns.hash ^ ip.hash
end
def source
if ! @ns.nil? # NS
then @ip.nil? ? "#{@ns}" : "#{@ns}/#{ip}" # NS/IP
else nil # generic
end
end
end
##
## Test that has Succeed
##
class Succeed < Result
def ok? ; true ; end
end
##
## Test that has Failed
##
class Failed < Result
def ok? ; false ; end
end
##
## Test that was unable to complete due to Error
##
class Error < Result
def ok? ; false ; end
end
def initialize(network, config, cm, domain)
@network = network
@config = config
@cm = cm
@domain = domain
@cache = Cache::new
end
def dbgmsg(ns=nil, ip=nil)
$dbg.msg(DBG::TESTDBG) {
func = 'caller_unknown'
caller.each { |l|
if l =~ /`((?:chk|tst)_.*)'/ #` <-- emacs
func = $1
break
end
}
header = if ns.nil? && ip.nil?
then func
else func + ' [' + [ ns, ip ].compact.join('/') + ']'
end
case arg = yield
when Array then [ header ] + arg
else [ header, arg ]
end
}
end
# Test if 'name' is a cname
# If 'name' is inside the current domain, the specified 'ip'
# will be used (if 'ip' is nil the first nameserver address
# is used)
# WARN: this is necessary because the query could be in the
# domain being delegated
# IDEA: a better way would be to use the cachemanager to fake
# the nameserver NS, A and AAAA records retrieved by autoconf
# unfortunately we have a NOCACHE option in the debug mode
def is_cname?(name, ip=nil)
if name.in_domain?(@domain.name)
ip = @domain.addresses[0] if ip.nil?
else
ip = nil
end
res = @cm[ip].cname(name)
res.nil? ? nil : res.cname
end
def is_resolvable?(name, ip=nil, domain=@domain.name)
(( name.in_domain?(domain) && !@cm[ip].addresses(name).empty?) ||
( @cm[ip].rec(@domain.name) && !@cm[ip].addresses(name).empty?) ||
(!@cm[ip].rec(@domain.name) && !@cm[nil].addresses(name).empty?))
end
def bestresolverip(name=@domain.name)
if (ips = @domain.get_resolver_ips(name)).nil?
then nil
else ips[0]
end
end
#-- Shortcuts -----------------------------------------------
def const(name)
@config.constants.fetch(name)
end
def rec(ip=nil, dom=@domain.name, force=false)
@cm[ip].rec(dom, force)
end
def soa(ip=nil, dom=@domain.name, force=false)
@cm[ip].soa(dom, force)
end
def ns(ip=nil, dom=@domain.name, force=false)
@cm[ip].ns(dom, force)
end
def mx(ip=nil, dom=@domain.name, force=false)
@cm[ip].mx(dom, force)
end
def any(ip=nil, resource=nil)
@cm[ip].any(@domain.name, resource)
end
def addresses(name, ip=nil)
@cm[ip].addresses(name)
end
def a(ip, name, force=false)
@cm[ip].a(name, force)
end
def aaaa(ip, name, force=false)
@cm[ip].aaaa(name, force)
end
def cname(ip, name, force=false)
@cm[ip].cname(name, force)
end
def ptr(ip, name)
@cm[ip].ptr(name)
end
end
##
## Hold tests that are generic
##
module CheckGeneric
def self.family ; 'generic' ; end
end
##
## Hold tests that are directed to an NS entry
## => take an NS name as argument
##
module CheckNameServer
def self.family ; 'nameserver' ; end
end
##
## Hold tests that are directed to a DNS running on an IP address
## => take an NS name and an IP address as argument
##
module CheckNetworkAddress
def self.family ; 'address' ; end
end
##
## Hold tests that are not directed DNS related
##
module CheckExtra
def self.family ; 'extra' ; end
end
|