Skip to content

Commit ced3fba

Browse files
authored
Add AAAA Support
1 parent e4d02db commit ced3fba

File tree

2 files changed

+65
-25
lines changed

2 files changed

+65
-25
lines changed

lib/github-pages-health-check/domain.rb

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,30 @@ class Domain < Checkable
7070
"192.30.252.154"
7171
].freeze
7272

73+
# TODO: Should these be added?
74+
# I see them at https://api.github.com/meta, but some of the
75+
# IPs are explictly test against in specs
76+
# 192.30.252.153
77+
# 192.30.252.154
7378
CURRENT_IP_ADDRESSES = %w(
7479
185.199.108.153
7580
185.199.109.153
7681
185.199.110.153
7782
185.199.111.153
7883
).freeze
7984

85+
CURRENT_IPV6_ADDRESSES = %w(
86+
2606:50c0:8000::1538
87+
2606:50c0:8001::1538
88+
2606:50c0:8002::1538
89+
2606:50c0:8003::1538
90+
).map { |a| Dnsruby::IPv6.create(a) }.to_set.freeze
91+
92+
CURRENT_IP_ADDRESSES_ALL =
93+
(CURRENT_IP_ADDRESSES
94+
.map { |a| Dnsruby::IPv4.create(a) }.to_set + CURRENT_IPV6_ADDRESSES)
95+
.freeze
96+
8097
HASH_METHODS = %i[
8198
host uri nameservers dns_resolves? proxied? cloudflare_ip?
8299
fastly_ip? old_ip_address? a_record? cname_record?
@@ -128,8 +145,8 @@ def deprecated_ip?
128145
def invalid_aaaa_record?
129146
return @invalid_aaaa_record if defined? @invalid_aaaa_record
130147

131-
@invalid_aaaa_record = (valid_domain? && should_be_a_record? &&
132-
aaaa_record_present?)
148+
@invalid_aaaa_record =
149+
(valid_domain? && aaaa_record_present? && !should_be_a_record?)
133150
end
134151

135152
def invalid_a_record?
@@ -204,7 +221,7 @@ def dns_zone_ns?
204221
end
205222
end
206223

207-
# Should the domain use an A record?
224+
# Should the domain use an A or AAAA record?
208225
def should_be_a_record?
209226
!pages_io_domain? && (apex_domain? || mx_records_present?)
210227
end
@@ -213,9 +230,11 @@ def should_be_cname_record?
213230
!should_be_a_record?
214231
end
215232

216-
# Is the domain's first response an A record to a valid GitHub Pages IP?
233+
# Is the domain's first response an A or AAAA record to a valid GitHub Pages IP?
217234
def pointed_to_github_pages_ip?
218-
a_record? && CURRENT_IP_ADDRESSES.include?(dns.first.address.to_s)
235+
return false unless a_record?
236+
237+
CURRENT_IP_ADDRESSES_ALL.include?(dns.first.address)
219238
end
220239

221240
# Are any of the domain's A records pointing elsewhere?
@@ -343,11 +362,12 @@ def old_ip_address?
343362
end
344363
end
345364

346-
# Is this domain's first response an A record?
365+
# Is this domain's first response an A or AAAA record?
347366
def a_record?
367+
return @is_a_record if defined?(@is_a_record)
348368
return unless dns?
349369

350-
dns.first.type == Dnsruby::Types::A
370+
@is_a_record = [Dnsruby::Types::A, Dnsruby::Types::AAAA].include?(dns.first.type)
351371
end
352372

353373
def aaaa_record_present?

spec/github_pages_health_check/domain_spec.rb

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
let(:a_packet) do
1717
Dnsruby::RR.create("#{domain}. 1000 IN A #{ip}")
1818
end
19+
let(:ip6) { "::1" }
1920
let(:aaaa_packet) do
2021
Dnsruby::RR.create("#{domain}. 1000 IN AAAA #{ip6}")
2122
end
@@ -161,25 +162,21 @@
161162
expect(subject.should_be_a_record?).to be_falsy
162163
expect(subject).to be_a_invalid_a_record
163164
end
165+
end
164166

165-
context "AAAA records" do
166-
let(:domain) { "parkermoore.de" }
167-
let(:ip) { "185.199.108.153" }
168-
let(:ip6) { "::1" }
169-
before(:each) { allow(subject).to receive(:dns) { [a_packet, aaaa_packet] } }
170-
it "knows that AAAA records are not allowed" do
171-
expect(subject).to be_an_a_record
172-
expect(subject).to be_a_valid_domain
173-
expect(subject.invalid_aaaa_record?).to be_truthy
174-
end
175-
it "raises InvalidAAAARecordError" do
176-
stub_request(:head, "http://#{domain}")
177-
.to_return(:status => 200, :headers => { "Server" => "GitHub.com" })
178-
expect(subject.invalid_aaaa_record?).to be_truthy
179-
expect(-> { subject.check! }).to raise_error(
180-
GitHubPages::HealthCheck::Errors::InvalidAAAARecordError
181-
)
182-
end
167+
context "AAAA records" do
168+
before(:each) { allow(subject).to receive(:dns) { [aaaa_packet] } }
169+
170+
it "knows when a domain is an AAAA record" do
171+
expect(subject).to be_an_aaaa_record_present
172+
expect(subject).to_not be_a_cname_record
173+
end
174+
175+
it "knows when a domain has an invalid AAAA record" do
176+
expect(subject).to be_an_aaaa_record_present
177+
expect(subject).to be_a_valid_domain
178+
expect(subject.should_be_a_record?).to eq(false)
179+
expect(subject).to be_a_invalid_aaaa_record
183180
end
184181
end
185182

@@ -473,6 +470,29 @@
473470
end
474471
end
475472

473+
context "GitHub Pages IPv6s" do
474+
context "apex domains" do
475+
context "pointed to Pages IPv6" do
476+
let(:domain) { "myipv6.io" }
477+
let(:ip6) { "2606:50C0:8000::1538" }
478+
before(:each) { allow(subject).to receive(:dns) { [aaaa_packet] } }
479+
480+
it "Knows it's a Pages IP" do
481+
expect(subject).to be_pointed_to_github_pages_ip
482+
end
483+
end
484+
485+
context "not pointed to a pages IP" do
486+
let(:domain) { "example.com" }
487+
let(:ip6) { "::1" }
488+
489+
it "knows it's not a Pages IP" do
490+
expect(subject).to_not be_pointed_to_github_pages_ip
491+
end
492+
end
493+
end
494+
end
495+
476496
context "Pages domains" do
477497
["pages.github.com",
478498
"pages.github.io",

0 commit comments

Comments
 (0)