Skip to content

Commit

Permalink
get the domain that points to pages
Browse files Browse the repository at this point in the history
  • Loading branch information
tsusdere committed Apr 9, 2024
1 parent e12ea43 commit d02c892
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions lib/github-pages-health-check/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Domain < Checkable
host uri nameservers dns_resolves? proxied? cloudflare_ip?
fastly_ip? old_ip_address? a_record? aaaa_record? a_record_present? aaaa_record_present?
cname_record? mx_records_present? valid_domain? apex_domain?
should_be_a_record? cname_to_github_user_domain?
should_be_a_record? cname_to_github_user_domain? cname_to_domain_to_pages?
cname_to_pages_dot_github_dot_com? cname_to_fastly?
pointed_to_github_pages_ip? non_github_pages_ip_present? pages_domain?
served_by_pages? valid? reason valid_domain? https?
Expand Down Expand Up @@ -240,12 +240,15 @@ def non_github_pages_ip_present?

# Is the domain's first response a CNAME to a pages domain?
def cname_to_github_user_domain?
# If the domain does not match check if the host value points to a pages
# domain.
#
# e.g 'www.domain.com' -> 'domain.com' -> 'Pages' is valid
binding.pry
cname? && !cname_to_pages_dot_github_dot_com? && (cname.pages_domain?)
cname? && !cname_to_pages_dot_github_dot_com? && cname.pages_domain?
end

# Check if the CNAME points to a Domain that points to pages
# e.g. CNAME -> Domain -> Pages
def cname_to_domain_to_pages?
a_record_to_pages = dns.select { |d| d.type == Dnsruby::Types::A && d.name.to_s == host }.first
return false unless a_record_to_pages && cname? && !cname_to_pages_dot_github_dot_com?
CURRENT_IP_ADDRESSES.include?(a_record_to_pages.address.to_s.downcase)
end

# Is the given domain a CNAME to pages.github.(io|com)
Expand Down Expand Up @@ -309,6 +312,7 @@ def proxied?
return true if cloudflare_ip?
return false if pointed_to_github_pages_ip?
return false if cname_to_github_user_domain?
return false if cname_to_domain_to_pages?
return false if cname_to_pages_dot_github_dot_com?
return false if cname_to_fastly? || fastly_ip?

Expand Down Expand Up @@ -459,8 +463,7 @@ def https_eligible?
return false if host.include?("_")

# Must be a CNAME or point to our IPs.
# Only check the one domain if a CNAME. Don't check the parent domain.
return true if cname_to_github_user_domain?
return true if cname_to_github_user_domain? || cname_to_domain_to_pages?

# Check CAA records for the full domain and its parent domain.
pointed_to_github_pages_ip? && caa.lets_encrypt_allowed?
Expand Down
2 changes: 1 addition & 1 deletion spec/github_pages_health_check/domain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
end

it "knows it's a Pages IP at the end" do
binding.require 'pry'; binding.pry
expect(subject).to be_a_cname_to_domain_to_pages
end
end

Expand Down

0 comments on commit d02c892

Please sign in to comment.