Skip to content

Commit

Permalink
Merge pull request #125 from github/non-200-served-by-pages
Browse files Browse the repository at this point in the history
Allow non-200 responses to satisfy served_by_pages
  • Loading branch information
tcbyrd authored Apr 21, 2021
2 parents b44b088 + 1ef9cb7 commit 982221e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/github-pages-health-check/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ def served_by_pages?
return unless dns_resolves?

@served_by_pages = begin
return false unless response.mock? || response.return_code == :ok
return true if response.headers["Server"] == "GitHub.com"

# Typhoeus mangles the case of the header, compare insensitively
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.1"
VERSION = "1.17.2"
end
end
27 changes: 27 additions & 0 deletions spec/github_pages_health_check/domain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,12 @@
allow(subject).to receive(:dns) { [a_packet] }
stub_request(:head, domain)
.to_return(:status => status, :headers => headers)

stub_request(:head, "https://githubuniverse.com/")
.to_return(:status => 200, :headers => { :server => "GitHub.com" })

stub_request(:head, "https://github.com/login")
.to_return(:status => 200, :headers => { :server => "GitHub.com" })
end

context "with the Pages server header" do
Expand All @@ -507,6 +513,27 @@
expect(subject).to be_served_by_pages
end
end

context "an alternate domain" do
let(:domain) { "http://www.githubuniverse.com" }
let(:status) { 301 }
let(:headers) { { :location => "https://githubuniverse.com" } }
before(:each) { allow(subject).to receive(:dns) { [cname_packet] } }

it "knows about domains that redirect to the primary domain on pages" do
expect(subject).to be_served_by_pages
end
end

context "a private page" do
let(:domain) { "http://private-page.githubapp.com" }
let(:status) { 302 }
let(:headers) { { :location => "https://github.com/login" } }

it "considers it valid if it redirects to github.com/login" do
expect(subject).to be_served_by_pages
end
end
end

context "with a request ID" do
Expand Down

0 comments on commit 982221e

Please sign in to comment.