class Coppertone::Utils::ValidatedDomainFinder
A class used to find validated domains as defined in section 5.5 of the RFC.
Attributes
subdomain_only[R]
Public Class Methods
new(macro_context, request_context, subdomain_only = true)
click to toggle source
# File lib/coppertone/utils/validated_domain_finder.rb, line 8 def initialize(macro_context, request_context, subdomain_only = true) # rubocop:disable Style/OptionalBooleanParameter @mc = macro_context @request_context = request_context @subdomain_only = subdomain_only end
Public Instance Methods
fetch_ptr_names(ip)
click to toggle source
# File lib/coppertone/utils/validated_domain_finder.rb, line 21 def fetch_ptr_names(ip) dns_client = @request_context.dns_client names = dns_client.fetch_ptr_records(ip.reverse).map do |ptr| ptr[:name] end record_limit = @request_context.dns_lookups_per_ptr_mechanism_limit record_limit ? names.slice(0, record_limit) : names end
find(target_name)
click to toggle source
# File lib/coppertone/utils/validated_domain_finder.rb, line 14 def find(target_name) ip = @mc.original_ipv6? ? @mc.ip_v6 : @mc.ip_v4 ptr_names = fetch_ptr_names(ip) ip_checker = IPInDomainChecker.new(@mc, @request_context) ptr_names.find { |n| ptr_record_matches?(ip_checker, target_name, n) } end
ptr_record_matches?(ip_checker, target_name, ptr_name)
click to toggle source
# File lib/coppertone/utils/validated_domain_finder.rb, line 31 def ptr_record_matches?(ip_checker, target_name, ptr_name) is_candidate = !subdomain_only || DomainUtils.subdomain_or_same?(ptr_name, target_name) is_candidate && ip_checker.check(ptr_name) rescue DNSAdapter::Error # If a DNS error occurs when looking up a domain, treat it # as a non match false end