Skip to content

Commit

Permalink
Merge branch 'cdn_ip_should_return_false_unless_a_records' into 1.3-s…
Browse files Browse the repository at this point in the history
…table

* cdn_ip_should_return_false_unless_a_records:
  Bump required ruby version up to 2.2.0
  Apply Rubocop automatic fixes
  Update rubocop to v0.52 & update configuration namespaces
  GitHub Pages is now running Ruby 2.4.2
  Fix Domain tests so they no longer rely on the state of the world
  Domain#cdn_ip?: return false if there are no A records
  Domain#apex_domain?: use PublicSuffix.domain() to determine if it's an apex domain
  bump copyright date
  Release 💎 v1.3.5
  • Loading branch information
parkr committed Feb 16, 2018
2 parents b769876 + 7bcb2b0 commit b095e9f
Show file tree
Hide file tree
Showing 38 changed files with 116 additions and 69 deletions.
36 changes: 15 additions & 21 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# https://github.com/bbatsov/rubocop/blob/master/config/default.yml
#
# If you disable a check, document why.
#

AllCops:
Exclude:
Expand All @@ -25,17 +26,9 @@ AllCops:
Lint/EndAlignment:
Severity: error

Lint/RescueException:
Exclude:
- lib/pages_jekyll.rb

Lint/UnreachableCode:
Severity: error

Lint/AmbiguousRegexpLiteral:
Exclude:
- 'features/step_definitions/pages_steps.rb'

Style/StringLiterals:
EnforcedStyle: double_quotes
Severity: error
Expand All @@ -47,10 +40,10 @@ Style/HashSyntax:
EnforcedStyle: hash_rockets
Severity: error

Style/AlignHash:
Layout/AlignHash:
SupportedLastArgumentHashStyles: always_ignore

Style/AlignParameters:
Layout/AlignParameters:
Enabled: false # This is usually true, but we often want to roll back to
# the start of a line.

Expand All @@ -75,14 +68,14 @@ Metrics/LineLength:

Metrics/BlockLength:
Enabled: false

Style/MultilineTernaryOperator:
Severity: error

Style/AndOr:
Severity: error

Style/IndentationWidth:
Layout/IndentationWidth:
Severity: error

Metrics/MethodLength:
Expand All @@ -101,20 +94,20 @@ Style/RedundantSelf:
Style/IfUnlessModifier:
Enabled: false

Style/FileName: #Rubocop doesn't like the Git*H*ub namespace
Naming/FileName: #Rubocop doesn't like the Git*H*ub namespace
Enabled: false

Metrics/ParameterLists: { Max: 4 }
Metrics/AbcSize: { Max: 20 }

Style/IndentHash: { EnforcedStyle: consistent }
Layout/IndentHash: { EnforcedStyle: consistent }
Layout/MultilineMethodCallIndentation: { EnforcedStyle: indented }
Layout/MultilineOperationIndentation: { EnforcedStyle: indented }
Layout/FirstParameterIndentation: { EnforcedStyle: consistent }
Layout/IndentArray: { EnforcedStyle: consistent }
Layout/ExtraSpacing: { AllowForAlignment: true }
Style/SignalException: { EnforcedStyle: only_raise }
Style/MultilineMethodCallIndentation: { EnforcedStyle: indented }
Style/MultilineOperationIndentation: { EnforcedStyle: indented }
Style/FirstParameterIndentation: { EnforcedStyle: consistent }
Style/StringLiterals: { EnforcedStyle: double_quotes }
Style/IndentArray: { EnforcedStyle: consistent }
Style/ExtraSpacing: { AllowForAlignment: true }

Style/PercentLiteralDelimiters:
PreferredDelimiters:
Expand Down Expand Up @@ -153,5 +146,6 @@ Metrics/AbcSize:
Style/DoubleNegation:
Enabled: false

Style/FileName:
Enabled: false
Layout/EmptyLineAfterMagicComment:
Exclude:
- script/*
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1
2.4.2
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ before_install: bundle update
install:
- sudo bash -c 'echo search github.com >> /etc/resolv.conf'
cache: bundler
rvm: 2.3.1
rvm: 2.4.2
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gemspec
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 GitHub, Inc.
Copyright (c) 2014 - 2017 GitHub, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
15 changes: 8 additions & 7 deletions github-pages-health-check.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# frozen_string_literal: true

require File.expand_path("../lib/github-pages-health-check/version", __FILE__)

Gem::Specification.new do |s|
s.required_ruby_version = ">= 1.9.3"
s.required_ruby_version = ">= 2.2.0"

s.name = "github-pages-health-check"
s.version = GitHubPages::HealthCheck::VERSION
Expand All @@ -15,16 +16,16 @@ Gem::Specification.new do |s|
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
s.require_paths = ["lib"]

s.add_dependency("addressable", "~> 2.3")
s.add_dependency("net-dns", "~> 0.8")
s.add_dependency("octokit", "~> 4.0")
s.add_dependency("public_suffix", "~> 2.0")
s.add_dependency("typhoeus", "~> 0.7")
s.add_dependency("addressable", "~> 2.3")
s.add_dependency("octokit", "~> 4.0")

s.add_development_dependency("rspec", "~> 3.0")
s.add_development_dependency("pry", "~> 0.10")
s.add_development_dependency("dotenv", "~> 1.0")
s.add_development_dependency("gem-release", "~> 0.7")
s.add_development_dependency("pry", "~> 0.10")
s.add_development_dependency("rspec", "~> 3.0")
s.add_development_dependency("rubocop", "~> 0.52")
s.add_development_dependency("webmock", "~> 1.21")
s.add_development_dependency("dotenv", "~> 1.0")
s.add_development_dependency("rubocop", "~> 0.40")
end
1 change: 1 addition & 0 deletions lib/github-pages-health-check.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "net/dns"
require "net/dns/resolver"
require "addressable/uri"
Expand Down
1 change: 1 addition & 0 deletions lib/github-pages-health-check/cdn.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
class CDN
Expand Down
1 change: 1 addition & 0 deletions lib/github-pages-health-check/cdns/cloudflare.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
# Instance of the CloudFlare CDN for checking IP ownership
Expand Down
3 changes: 2 additions & 1 deletion lib/github-pages-health-check/cdns/fastly.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
# Instance of the Fastly CDN for checking IP ownership
Expand All @@ -10,7 +11,7 @@ class Fastly < CDN
github.map.fastly.net.
sni.github.map.fastly.net
sni.github.map.fastly.net.
)
).freeze
end
end
end
1 change: 1 addition & 0 deletions lib/github-pages-health-check/checkable.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
class Checkable
Expand Down
38 changes: 19 additions & 19 deletions lib/github-pages-health-check/domain.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
class Domain < Checkable
Expand Down Expand Up @@ -70,13 +71,13 @@ class Domain < Checkable
192.30.252.154
).freeze

HASH_METHODS = [
:host, :uri, :dns_resolves?, :proxied?, :cloudflare_ip?, :fastly_ip?,
:old_ip_address?, :a_record?, :cname_record?, :mx_records_present?,
:valid_domain?, :apex_domain?, :should_be_a_record?,
:cname_to_github_user_domain?, :cname_to_pages_dot_github_dot_com?,
:cname_to_fastly?, :pointed_to_github_pages_ip?, :pages_domain?,
:served_by_pages?, :valid_domain?, :https?, :enforces_https?, :https_error
HASH_METHODS = %i[
host uri dns_resolves? proxied? cloudflare_ip? fastly_ip?
old_ip_address? a_record? cname_record? mx_records_present?
valid_domain? apex_domain? should_be_a_record?
cname_to_github_user_domain? cname_to_pages_dot_github_dot_com?
cname_to_fastly? pointed_to_github_pages_ip? pages_domain?
served_by_pages? valid_domain? https? enforces_https? https_error
].freeze

def initialize(host)
Expand Down Expand Up @@ -131,16 +132,12 @@ def apex_domain?
return @apex_domain if defined?(@apex_domain)
return unless valid_domain?

answers = begin
Resolv::DNS.open do |dns|
dns.timeouts = TIMEOUT
dns.getresources(absolute_domain, Resolv::DNS::Resource::IN::NS)
end
rescue Timeout::Error, NoMethodError
[]
end

@apex_domain = answers.any?
# PublicSuffix.domain pulls out the apex-level domain name.
# E.g. PublicSuffix.domain("techblog.netflix.com") # => "netflix.com"
# It's aware of multi-step top-level domain names:
# E.g. PublicSuffix.domain("blog.digital.gov.uk") # => "digital.gov.uk"
# For apex-level domain names, DNS providers do not support CNAME records.
PublicSuffix.domain(host) == host
end

# Should the domain be an apex record?
Expand Down Expand Up @@ -389,8 +386,11 @@ def scheme
# Does the domain resolve to a CDN-owned IP
def cdn_ip?(cdn)
return unless dns?
dns.all? do |answer|
next true unless answer.class == Net::DNS::RR::A

a_records = dns.select { |answer| answer.class == Net::DNS::RR::A }
return false if !a_records || a_records.empty?

a_records.all? do |answer|
cdn.controls_ip?(answer.address)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/github-pages-health-check/error.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
class Error < StandardError
Expand Down
1 change: 1 addition & 0 deletions lib/github-pages-health-check/errors.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

Dir[File.expand_path("../errors/*_error.rb", __FILE__)].each do |f|
require f
end
Expand Down
1 change: 1 addition & 0 deletions lib/github-pages-health-check/errors/build_error.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
module Errors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
module Errors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
module Errors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
module Errors
Expand Down
1 change: 1 addition & 0 deletions lib/github-pages-health-check/errors/invalid_dns_error.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
module Errors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
module Errors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
module Errors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
module Errors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
module Errors
Expand Down
1 change: 1 addition & 0 deletions lib/github-pages-health-check/printer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
class Printer
Expand Down
5 changes: 3 additions & 2 deletions lib/github-pages-health-check/repository.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
class Repository < Checkable
attr_reader :name, :owner

REPO_REGEX = %r{\A[a-z0-9_\-]+/[a-z0-9_\-\.]+\z}i

HASH_METHODS = [
:name_with_owner, :built?, :last_built, :build_duration, :build_error
HASH_METHODS = %i[
name_with_owner built? last_built build_duration build_error
].freeze

def initialize(name_with_owner, access_token: nil)
Expand Down
1 change: 1 addition & 0 deletions lib/github-pages-health-check/site.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
class Site < Checkable
Expand Down
1 change: 1 addition & 0 deletions lib/github-pages-health-check/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module GitHubPages
module HealthCheck
VERSION = "1.3.5".freeze
Expand Down
1 change: 1 addition & 0 deletions script/check
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# Usage: script/check [DOMAIN]

require_relative "../lib/github-pages-health-check"
Expand Down
5 changes: 3 additions & 2 deletions script/update-cdn-ips
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
# / Usage script/update-ips
# / updates config/cloudflare-ips.txt and config/fastly-ips.txt
#
# Usage script/update-ips
# updates config/cloudflare-ips.txt and config/fastly-ips.txt

require "open-uri"
require "json"
Expand Down
1 change: 1 addition & 0 deletions spec/github_pages_health_check/cdn_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "spec_helper"
require "json"
require "tempfile"
Expand Down
1 change: 1 addition & 0 deletions spec/github_pages_health_check/checkable_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "spec_helper"

class CheckableHelper < GitHubPages::HealthCheck::Checkable
Expand Down
Loading

0 comments on commit b095e9f

Please sign in to comment.