github-pages-health-check 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 091625c0c7a6bde1c78784374bf9f2a0c5dbec4f
4
- data.tar.gz: 89d2ec351698812775d18dc61abdb5c3aa9cdd63
3
+ metadata.gz: ac3f04f1179ebe2da4aba38ad08dfd5939855fb6
4
+ data.tar.gz: cc6745a890b982f0a6e6b066760177e512d23b3a
5
5
  SHA512:
6
- metadata.gz: 594c1a1021d27affdb275f780576aeb048402e6588f55c8e88478efce1162cb516c60aec7f7671b57e26ec467f0a16b6f895d1a205918a9dd8f268f0dfaa3c4e
7
- data.tar.gz: 7fe3282947ef56e8741dd38a21beea57ee860dfe09bc8e48fe248ead030b4f1f04d20177e4b1dc12f57b0fc47381d8ba821d33b27a4eb84a57e971ffd07a706a
6
+ metadata.gz: 03633518d82ee979a23eaa4c10ec36a2e55771bbeaf3af5074f784b89a096c9ce3979c33aeaf6bb04f87621eb65aa302d0743d626457d1c1eff3be3fefe05a4f
7
+ data.tar.gz: 7c04a0b9cd18c6d89a1bc1b539377867f350019beb6239a6a78fb69ba47931f70eb0d29e895788418375feb14134d969887f4f2edd6174b60fa64e175e2f5da5
@@ -1,5 +1,6 @@
1
1
  require "net/dns"
2
2
  require "net/dns/resolver"
3
+ require "addressable/uri"
3
4
  require "ipaddr"
4
5
  require "public_suffix"
5
6
  require "singleton"
@@ -29,6 +30,16 @@ class GitHubPages
29
30
  192.30.252.154
30
31
  ]
31
32
 
33
+ TYPHOEUS_OPTIONS = {
34
+ :followlocation => true,
35
+ :timeout => 10,
36
+ :accept_encoding => "gzip",
37
+ :method => :head,
38
+ :headers => {
39
+ "User-Agent" => "Mozilla/5.0 (compatible; GitHub Pages Health Check/#{VERSION}; +https://github.com/github/pages-health-check)"
40
+ }
41
+ }
42
+
32
43
  def initialize(domain)
33
44
  @domain = domain
34
45
  end
@@ -37,9 +48,21 @@ class GitHubPages
37
48
  dns.all? { |answer| answer.class == Net::DNS::RR::A && CloudFlare.controls_ip?(answer.address) }
38
49
  end
39
50
 
51
+ # Does this non-GitHub-pages domain proxy a GitHub Pages site?
52
+ #
53
+ # This can be:
54
+ # 1. A Cloudflare-owned IP address
55
+ # 2. A site that returns GitHub.com server headers, but isn't CNAME'd to a GitHub domain
56
+ # 3. A site that returns GitHub.com server headers, but isn't CNAME'd to a GitHub IP
57
+ def proxied?
58
+ return true if cloudflare_ip?
59
+ return false if pointed_to_github_pages_ip? || pointed_to_github_user_domain?
60
+ served_by_pages?
61
+ end
62
+
40
63
  # Returns an array of DNS answers
41
64
  def dns
42
- @dns ||= without_warnings { Net::DNS::Resolver.start(absolute_domain).answer } if domain
65
+ @dns ||= without_warnings { Net::DNS::Resolver.start(absolute_domain).answer } if domain
43
66
  rescue Exception
44
67
  false
45
68
  end
@@ -101,6 +124,8 @@ class GitHubPages
101
124
 
102
125
  def to_hash
103
126
  {
127
+ :uri => uri.to_s,
128
+ :proxied? => proxied?,
104
129
  :cloudflare_ip? => cloudflare_ip?,
105
130
  :old_ip_address? => old_ip_address?,
106
131
  :a_record? => a_record?,
@@ -116,9 +141,15 @@ class GitHubPages
116
141
  :reason => reason
117
142
  }
118
143
  end
144
+ alias_method :to_h, :to_hash
119
145
 
120
146
  def served_by_pages?
121
- response = Typhoeus.head(uri, followlocation: true)
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)
152
+ end
122
153
  response.success? && response.headers["Server"] == "GitHub.com"
123
154
  end
124
155
 
@@ -129,7 +160,7 @@ class GitHubPages
129
160
  # Runs all checks, raises an error if invalid
130
161
  def check!
131
162
  return unless dns
132
- return if cloudflare_ip?
163
+ return if proxied?
133
164
  raise DeprecatedIP if a_record? && old_ip_address?
134
165
  raise InvalidARecord if valid_domain? && a_record? && !should_be_a_record?
135
166
  raise InvalidCNAME if valid_domain? && !github_domain? && !apex_domain? && !pointed_to_github_user_domain?
@@ -187,7 +218,7 @@ class GitHubPages
187
218
  end
188
219
 
189
220
  def uri
190
- @uri ||= URI("#{scheme}://#{domain}")
221
+ @uri ||= Addressable::URI.new(:host => domain, :scheme => scheme, :path => "/").normalize
191
222
  end
192
223
  end
193
224
  end
@@ -1,5 +1,5 @@
1
1
  class GitHubPages
2
2
  class HealthCheck
3
- VERSION = "0.3.2"
3
+ VERSION = "0.4.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.3.2
4
+ version: 0.4.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-06 00:00:00.000000000 Z
11
+ date: 2015-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-dns
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: addressable
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -70,30 +84,44 @@ dependencies:
70
84
  name: pry
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ">="
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0'
89
+ version: '0.10'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ">="
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0'
96
+ version: '0.10'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: gem-release
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ">="
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
88
116
  - !ruby/object:Gem::Version
89
- version: '0'
117
+ version: '1.21'
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
- - - ">="
122
+ - - "~>"
95
123
  - !ruby/object:Gem::Version
96
- version: '0'
124
+ version: '1.21'
97
125
  description: Checks your GitHub Pages site for commons DNS configuration issues.
98
126
  email: support@github.com
99
127
  executables: []