Skip to content

Commit

Permalink
Merge pull request #140 from github/ipv6-fix
Browse files Browse the repository at this point in the history
IPv6 fix
  • Loading branch information
yoannchaudet authored Oct 1, 2021
2 parents 06621a8 + fe4a96d commit 209be81
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Style/ClassAndModuleChildren:
Enabled: false # module X<\n>module Y is just as good as module X::Y.

Layout/LineLength:
Max: 90
Max: 120
Severity: warning
Exclude:
- github-pages-health-check.gemspec
Expand Down
17 changes: 12 additions & 5 deletions lib/github-pages-health-check/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Domain < Checkable

HASH_METHODS = %i[
host uri nameservers dns_resolves? proxied? cloudflare_ip?
fastly_ip? old_ip_address? a_record? aaaa_record? aaaa_record_present?
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?
cname_to_pages_dot_github_dot_com? cname_to_fastly?
Expand Down Expand Up @@ -138,14 +138,13 @@ def deprecated_ip?
def invalid_aaaa_record?
return @invalid_aaaa_record if defined? @invalid_aaaa_record

@invalid_aaaa_record =
(valid_domain? && aaaa_record_present? && !should_be_a_record?)
@invalid_aaaa_record = (valid_domain? && aaaa_record_present? && !should_be_a_record?)
end

def invalid_a_record?
return @invalid_a_record if defined? @invalid_a_record

@invalid_a_record = (valid_domain? && a_record? && !should_be_a_record?)
@invalid_a_record = (valid_domain? && a_record_present? && !should_be_a_record?)
end

def invalid_cname?
Expand Down Expand Up @@ -369,10 +368,18 @@ def aaaa_record?
@is_aaaa_record = Dnsruby::Types::AAAA == dns.first.type
end

# Does this domain has an A record setup (not necessarily as the first record)?
def a_record_present?
return unless dns?

dns.any? { |answer| answer.type == Dnsruby::Types::A && answer.name.to_s == host }
end

# Does this domain has an AAAA record setup (not necessarily as the first record)?
def aaaa_record_present?
return unless dns?

dns.any? { |answer| answer.type == Dnsruby::Types::AAAA }
dns.any? { |answer| answer.type == Dnsruby::Types::AAAA && answer.name.to_s == host }
end

# Is this domain's first response a CNAME record?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class InvalidAAAARecordError < GitHubPages::HealthCheck::Error

def message
<<-MSG
Your site's DNS settings are using a custom subdomain, #{domain.host},
that's set up with an AAAA record. GitHub Pages currently does not support
IPv6.
Your site's DNS settings are using a custom subdomain, #{domain.host},
that's set up as an AAAA record. We recommend you change this to a CNAME
record pointing at #{username}.github.io.
MSG
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/github-pages-health-check/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module GitHubPages
module HealthCheck
VERSION = "1.17.8"
VERSION = "1.17.9"
end
end
19 changes: 19 additions & 0 deletions spec/github_pages_health_check/domain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,25 @@
end
end

context "A & AAAA recursive resolutions" do
let(:domain) { "domain.com" }
let(:cname) { "domain.github.io" }
before(:each) do
allow(subject).to receive(:dns) {
[
cname_packet,
Dnsruby::RR.create("#{cname}. 1000 IN A #{ip}"),
Dnsruby::RR.create("#{cname}. 1000 IN AAAA #{ip6}")
]
}
end

it "does not get tricked by recursive resolution" do
expect(subject).to_not be_an_aaaa_record_present
expect(subject).to_not be_an_a_record_present
end
end

context "CNAMEs" do
before(:each) { allow(subject).to receive(:dns) { [cname_packet] } }

Expand Down

0 comments on commit 209be81

Please sign in to comment.