github-pages-health-check 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42efe0c8aed8e2ed80f9ac52320d85bf88de688e
4
- data.tar.gz: 5b574275227155b07aa0cb39107f9a6d09527d5e
3
+ metadata.gz: 772a584d8e1bf36334d9bb61fece099e0b03191d
4
+ data.tar.gz: 52ca8bb64c040312f08c42ffb5ce41b3bf7a3cf8
5
5
  SHA512:
6
- metadata.gz: eb6ec54346c93947a6afeddf8788c501cd2344e2ebaaaeb18494701ca63e31a485720e586d9b5c69bc62287aeee517fd7290c767d2f95b5ffa34f601f6921a31
7
- data.tar.gz: c7affa539aafe96ec648c756d776ad71e8d5040092fb4f25a261e33aee6e3369a2fef9fb469f5e1a3df5b542ab4695c5ea97723f547b7c7f43e62b810b8d4e6a
6
+ metadata.gz: fbe626e01d4231bcb1f62b032bf1c1e46a3bf565e41923bcec764adaa233ad5a14d14107395aaff624147d359956757d84a3f9617f2003fe7b0400766e193286
7
+ data.tar.gz: 7d5ac6b67c15fb6e6d5517be3d237919c21b529177bdf68c3a16e01f7ee7cde5948e0e63d13318ac7dcd5dbe52f41260594c76965cb4d7ddc85daf69578ca1cc
@@ -6,12 +6,14 @@ require "public_suffix"
6
6
  require "singleton"
7
7
  require "net/http"
8
8
  require 'typhoeus'
9
+ require 'timeout'
9
10
  require_relative "github-pages-health-check/version"
10
11
  require_relative "github-pages-health-check/cloudflare"
11
12
  require_relative "github-pages-health-check/error"
12
13
  require_relative "github-pages-health-check/errors/deprecated_ip"
13
14
  require_relative "github-pages-health-check/errors/invalid_a_record"
14
15
  require_relative "github-pages-health-check/errors/invalid_cname"
16
+ require_relative "github-pages-health-check/errors/invalid_dns"
15
17
  require_relative "github-pages-health-check/errors/not_served_by_pages"
16
18
 
17
19
  class GitHubPages
@@ -30,9 +32,12 @@ class GitHubPages
30
32
  192.30.252.154
31
33
  ]
32
34
 
35
+ # DNS and HTTP timeout, in seconds
36
+ TIMEOUT = 10
37
+
33
38
  TYPHOEUS_OPTIONS = {
34
39
  :followlocation => true,
35
- :timeout => 10,
40
+ :timeout => TIMEOUT,
36
41
  :accept_encoding => "gzip",
37
42
  :method => :head,
38
43
  :headers => {
@@ -45,7 +50,9 @@ class GitHubPages
45
50
  end
46
51
 
47
52
  def cloudflare_ip?
48
- dns.all? { |answer| answer.class == Net::DNS::RR::A && CloudFlare.controls_ip?(answer.address) }
53
+ dns.all? do |answer|
54
+ answer.class == Net::DNS::RR::A && CloudFlare.controls_ip?(answer.address)
55
+ end if dns?
49
56
  end
50
57
 
51
58
  # Does this non-GitHub-pages domain proxy a GitHub Pages site?
@@ -55,6 +62,7 @@ class GitHubPages
55
62
  # 2. A site that returns GitHub.com server headers, but isn't CNAME'd to a GitHub domain
56
63
  # 3. A site that returns GitHub.com server headers, but isn't CNAME'd to a GitHub IP
57
64
  def proxied?
65
+ return unless dns?
58
66
  return true if cloudflare_ip?
59
67
  return false if pointed_to_github_pages_ip? || pointed_to_github_user_domain?
60
68
  served_by_pages?
@@ -62,24 +70,36 @@ class GitHubPages
62
70
 
63
71
  # Returns an array of DNS answers
64
72
  def dns
65
- @dns ||= without_warnings { Net::DNS::Resolver.start(absolute_domain).answer } if domain
73
+ @dns ||= Timeout::timeout(TIMEOUT) do
74
+ without_warnings do
75
+ Net::DNS::Resolver.start(absolute_domain).answer if domain
76
+ end
77
+ end
66
78
  rescue Exception
67
- false
79
+ nil
80
+ end
81
+
82
+ # Are we even able to get the DNS record?
83
+ def dns?
84
+ !dns.nil?
68
85
  end
86
+ alias_method :dns_resolves?, :dns
69
87
 
70
88
  # Does this domain have *any* A record that points to the legacy IPs?
71
89
  def old_ip_address?
72
- dns.any? { |answer| answer.class == Net::DNS::RR::A && LEGACY_IP_ADDRESSES.include?(answer.address.to_s) }
90
+ dns.any? do |answer|
91
+ answer.class == Net::DNS::RR::A && LEGACY_IP_ADDRESSES.include?(answer.address.to_s)
92
+ end if dns?
73
93
  end
74
94
 
75
95
  # Is this domain's first response an A record?
76
96
  def a_record?
77
- dns.first.class == Net::DNS::RR::A
97
+ dns.first.class == Net::DNS::RR::A if dns?
78
98
  end
79
99
 
80
100
  # Is this domain's first response a CNAME record?
81
101
  def cname_record?
82
- dns.first.class == Net::DNS::RR::CNAME
102
+ dns.first.class == Net::DNS::RR::CNAME if dns?
83
103
  end
84
104
 
85
105
  # Is this a valid domain that PublicSuffix recognizes?
@@ -102,12 +122,12 @@ class GitHubPages
102
122
 
103
123
  # Is the domain's first response a CNAME to a pages domain?
104
124
  def pointed_to_github_user_domain?
105
- dns.first.class == Net::DNS::RR::CNAME && pages_domain?(dns.first.cname.to_s)
125
+ dns.first.class == Net::DNS::RR::CNAME && pages_domain?(dns.first.cname.to_s) if dns?
106
126
  end
107
127
 
108
128
  # Is the domain's first response an A record to a valid GitHub Pages IP?
109
129
  def pointed_to_github_pages_ip?
110
- dns.first.class == Net::DNS::RR::A && CURRENT_IP_ADDRESSES.include?(dns.first.value)
130
+ dns.first.class == Net::DNS::RR::A && CURRENT_IP_ADDRESSES.include?(dns.first.value) if dns?
111
131
  end
112
132
 
113
133
  # Is the given cname a pages domain?
@@ -125,6 +145,7 @@ class GitHubPages
125
145
  def to_hash
126
146
  {
127
147
  :uri => uri.to_s,
148
+ :dns_resolves? => dns?,
128
149
  :proxied? => proxied?,
129
150
  :cloudflare_ip? => cloudflare_ip?,
130
151
  :old_ip_address? => old_ip_address?,
@@ -144,14 +165,16 @@ class GitHubPages
144
165
  alias_method :to_h, :to_hash
145
166
 
146
167
  def served_by_pages?
147
- response = Typhoeus.head(uri, TYPHOEUS_OPTIONS)
148
- # Workaround for webmock not playing nicely with Typhoeus redirects
149
- # See https://github.com/bblimke/webmock/issues/237
150
- if response.mock? && response.headers["Location"]
151
- response = Typhoeus.head(response.headers["Location"], TYPHOEUS_OPTIONS)
168
+ @served_by_pages ||= begin
169
+ response = Typhoeus.head(uri, TYPHOEUS_OPTIONS)
170
+ # Workaround for webmock not playing nicely with Typhoeus redirects
171
+ # See https://github.com/bblimke/webmock/issues/237
172
+ if response.mock? && response.headers["Location"]
173
+ response = Typhoeus.head(response.headers["Location"], TYPHOEUS_OPTIONS)
174
+ end
175
+
176
+ (response.mock? || response.return_code == :ok) && response.headers["Server"] == "GitHub.com"
152
177
  end
153
-
154
- (response.mock? || response.return_code == :ok) && response.headers["Server"] == "GitHub.com"
155
178
  end
156
179
 
157
180
  def to_json
@@ -160,7 +183,7 @@ class GitHubPages
160
183
 
161
184
  # Runs all checks, raises an error if invalid
162
185
  def check!
163
- return unless dns
186
+ raise InvalidDNS unless dns?
164
187
  return if proxied?
165
188
  raise DeprecatedIP if a_record? && old_ip_address?
166
189
  raise InvalidARecord if valid_domain? && a_record? && !should_be_a_record?
@@ -1,5 +1,5 @@
1
1
  class GitHubPages
2
2
  class HealthCheck
3
- VERSION = "0.4.2"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-pages-health-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-12 00:00:00.000000000 Z
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-dns