Skip to content

Support checking whether a domain points at a GitHub Pages IP address #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -52,12 +52,13 @@
:apex_domain?=>true,
:should_be_a_record?=>true,
:pointed_to_github_user_domain?=>false,
:pointed_to_github_pages_ip?=>false,
:pages_domain?=>false,
:valid?=>true
}
> require 'json'
> require "json"
> check.to_json
=> "{\"cloudflare_ip?\":false,\"old_ip_address?\":false,\"a_record?\":true,\"cname_record?\":false,\"valid_domain?\":true,\"apex_domain?\":true,\"should_be_a_record?\":true,\"pointed_to_github_user_domain?\":false,\"pages_domain?\":false,\"valid?\":true}"
=> "{\"cloudflare_ip?\":false,\"old_ip_address?\":false,\"a_record?\":true,\"cname_record?\":false,\"valid_domain?\":true,\"apex_domain?\":true,\"should_be_a_record?\":true,\"pointed_to_github_user_domain?\":false,\"pointed_to_github_pages_ip?\":false,\"pages_domain?\":false,\"valid?\":true}"
```

### Getting the reason a domain is invalid
2 changes: 1 addition & 1 deletion github-pages-health-check.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('../lib/github-pages-health-check/version', __FILE__)
require File.expand_path("../lib/github-pages-health-check/version", __FILE__)

Gem::Specification.new do |s|
s.required_ruby_version = ">= 1.9.3"
37 changes: 24 additions & 13 deletions lib/github-pages-health-check.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require 'net/dns'
require 'net/dns/resolver'
require 'ipaddr'
require 'public_suffix'
require 'singleton'
require 'net/http'
require_relative 'github-pages-health-check/version'
require_relative 'github-pages-health-check/cloudflare'
require_relative 'github-pages-health-check/error'
require_relative 'github-pages-health-check/errors/deprecated_ip'
require_relative 'github-pages-health-check/errors/invalid_a_record'
require_relative 'github-pages-health-check/errors/invalid_cname'
require_relative 'github-pages-health-check/errors/not_served_by_pages'
require "net/dns"
require "net/dns/resolver"
require "ipaddr"
require "public_suffix"
require "singleton"
require "net/http"
require_relative "github-pages-health-check/version"
require_relative "github-pages-health-check/cloudflare"
require_relative "github-pages-health-check/error"
require_relative "github-pages-health-check/errors/deprecated_ip"
require_relative "github-pages-health-check/errors/invalid_a_record"
require_relative "github-pages-health-check/errors/invalid_cname"
require_relative "github-pages-health-check/errors/not_served_by_pages"

class GitHubPages
class HealthCheck
@@ -23,6 +23,11 @@ class HealthCheck
199.27.73.133
]

CURRENT_IP_ADDRESSES = %w[
192.30.252.153
192.30.252.154
]

def initialize(domain)
@domain = domain
end
@@ -76,6 +81,11 @@ def pointed_to_github_user_domain?
dns.first.class == Net::DNS::RR::CNAME && pages_domain?(dns.first.cname.to_s)
end

# Is the domain's first response an A record to a valid GitHub Pages IP?
def pointed_to_github_pages_ip?
dns.first.class == Net::DNS::RR::A && CURRENT_IP_ADDRESSES.include?(dns.first.value)
end

# Is the given cname a pages domain?
#
# domain - the domain to check, generaly the target of a cname
@@ -98,6 +108,7 @@ def to_hash
:apex_domain? => apex_domain?,
:should_be_a_record? => should_be_a_record?,
:pointed_to_github_user_domain? => pointed_to_github_user_domain?,
:pointed_to_github_pages_ip? => pointed_to_github_pages_ip?,
:pages_domain? => pages_domain?,
:served_by_pages? => served_by_pages?,
:valid? => valid?,
2 changes: 1 addition & 1 deletion lib/github-pages-health-check/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class GitHubPages
class HealthCheck
VERSION = '0.2.2'
VERSION = "0.2.2"
end
end
10 changes: 5 additions & 5 deletions spec/github_pages_health_check_cloudflare_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'
require 'json'
require 'tempfile'
require 'ipaddr'
require "spec_helper"
require "json"
require "tempfile"
require "ipaddr"

describe(GitHubPages::HealthCheck::CloudFlare) do

@@ -11,7 +11,7 @@

context "default" do
let(:instance) { GitHubPages::HealthCheck::CloudFlare.instance }

it "loads the default config" do
path = File.expand_path(instance.path)
expected = File.expand_path("../config/cloudflare-ips.txt", File.dirname(__FILE__))
21 changes: 18 additions & 3 deletions spec/github_pages_health_check_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
require 'json'
require "spec_helper"
require "json"

describe(GitHubPages::HealthCheck) do
let(:health_check) { GitHubPages::HealthCheck.new("foo.github.io") }
@@ -89,6 +89,21 @@ def cname_packet(domain)
end
end

it "can determine when an apex domain is pointed at a GitHub Pages IP address" do
allow(health_check).to receive(:domain) { "getbootstrap.com" }
expect(health_check.pointed_to_github_pages_ip?).to be(true)
end

it "can determine when an apex domain is not pointed at a GitHub Pages IP address" do
allow(health_check).to receive(:domain) { "example.com" }
expect(health_check.pointed_to_github_pages_ip?).to be(false)
end

it "can determine that a subdomain with a CNAME record is not pointed at a GitHub Pages IP address" do
allow(health_check).to receive(:domain) { "pages.github.com" }
expect(health_check.pointed_to_github_pages_ip?).to be(false)
end

it "retrieves a site's dns record" do
allow(health_check).to receive(:domain) { "pages.github.com" }
expect(health_check.dns.first.class).to eql(Net::DNS::RR::CNAME)
@@ -123,7 +138,7 @@ def cname_packet(domain)

it "returns valid json" do
data = JSON.parse GitHubPages::HealthCheck.new("benbalter.com").to_json
expect(data.length).to eql(12)
expect(data.length).to eql(13)
data.each { |key, value| expect([true,false,nil].include?(value)).to eql(true) }
end

2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -9,5 +9,5 @@
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
config.order = "random"
end