site-inspector 3.1.1 → 4.0.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 +5 -5
- data/.github/workflows/ci.yml +30 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +14 -10
- data/.rubocop_todo.yml +245 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +71 -0
- data/Gemfile +2 -0
- data/Guardfile +2 -0
- data/README.md +8 -14
- data/Rakefile +2 -0
- data/bin/site-inspector +16 -15
- data/lib/cliver/dependency_ext.rb +8 -5
- data/lib/data/well-known.yml +51 -0
- data/lib/site-inspector/domain.rb +61 -43
- data/lib/site-inspector/domain_parser.rb +11 -0
- data/lib/site-inspector/{checks → endpoint}/accessibility.rb +35 -25
- data/lib/site-inspector/{checks → endpoint}/check.rb +9 -3
- data/lib/site-inspector/endpoint/content.rb +151 -0
- data/lib/site-inspector/endpoint/cookies.rb +53 -0
- data/lib/site-inspector/{checks → endpoint}/dns.rb +52 -26
- data/lib/site-inspector/endpoint/headers.rb +55 -0
- data/lib/site-inspector/endpoint/hsts.rb +112 -0
- data/lib/site-inspector/{checks → endpoint}/https.rb +3 -1
- data/lib/site-inspector/endpoint/wappalyzer.rb +68 -0
- data/lib/site-inspector/endpoint/well_known.rb +95 -0
- data/lib/site-inspector/endpoint/whois.rb +56 -0
- data/lib/site-inspector/endpoint.rb +80 -44
- data/lib/site-inspector/formatter.rb +118 -0
- data/lib/site-inspector/version.rb +3 -1
- data/lib/site-inspector.rb +42 -31
- data/package-lock.json +1152 -0
- data/package.json +2 -1
- data/renovate.json +4 -0
- data/script/benchmark +8 -0
- data/script/cibuild +2 -2
- data/script/console +1 -1
- data/script/pa11y-version +2 -1
- data/script/release +11 -4
- data/script/update-well-known +18 -0
- data/site-inspector.gemspec +33 -19
- data/spec/cliver/dependency_ext_spec.rb +21 -0
- data/spec/fixtures/wappalyzer.json +125 -0
- data/spec/{site_inspector_domain_spec.rb → site_inspector/domain_spec.rb} +105 -43
- data/spec/{checks/site_inspector_endpoint_accessibility_spec.rb → site_inspector/endpoint/accessibility_spec.rb} +24 -20
- data/spec/{checks/site_inspector_endpoint_check_spec.rb → site_inspector/endpoint/check_spec.rb} +9 -7
- data/spec/{checks/site_inspector_endpoint_content_spec.rb → site_inspector/endpoint/content_spec.rb} +43 -24
- data/spec/{checks/site_inspector_endpoint_cookies_spec.rb → site_inspector/endpoint/cookies_spec.rb} +37 -22
- data/spec/site_inspector/endpoint/dns_spec.rb +262 -0
- data/spec/{checks/site_inspector_endpoint_headers_spec.rb → site_inspector/endpoint/headers_spec.rb} +10 -15
- data/spec/site_inspector/endpoint/hsts_spec.rb +92 -0
- data/spec/{checks/site_inspector_endpoint_https_spec.rb → site_inspector/endpoint/https_spec.rb} +12 -10
- data/spec/site_inspector/endpoint/wappalyzer_spec.rb +20 -0
- data/spec/site_inspector/endpoint/well_known_spec.rb +12 -0
- data/spec/site_inspector/endpoint/whois_spec.rb +27 -0
- data/spec/{site_inspector_endpoint_spec.rb → site_inspector/endpoint_spec.rb} +102 -45
- data/spec/site_inspector_spec.rb +67 -18
- data/spec/spec_helper.rb +11 -2
- metadata +178 -100
- data/.travis.yml +0 -9
- data/lib/site-inspector/cache.rb +0 -15
- data/lib/site-inspector/checks/content.rb +0 -74
- data/lib/site-inspector/checks/cookies.rb +0 -43
- data/lib/site-inspector/checks/headers.rb +0 -66
- data/lib/site-inspector/checks/hsts.rb +0 -77
- data/lib/site-inspector/checks/sniffer.rb +0 -64
- data/lib/site-inspector/disk_cache.rb +0 -40
- data/lib/site-inspector/rails_cache.rb +0 -11
- data/spec/checks/site_inspector_endpoint_dns_spec.rb +0 -182
- data/spec/checks/site_inspector_endpoint_hsts_spec.rb +0 -90
- data/spec/checks/site_inspector_endpoint_sniffer_spec.rb +0 -148
- data/spec/site_inspector_cache_spec.rb +0 -13
- data/spec/site_inspector_disk_cache_spec.rb +0 -37
data/spec/{checks/site_inspector_endpoint_headers_spec.rb → site_inspector/endpoint/headers_spec.rb}
RENAMED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe SiteInspector::Endpoint::Headers do
|
|
@@ -5,7 +7,7 @@ describe SiteInspector::Endpoint::Headers do
|
|
|
5
7
|
stub_request(:head, 'http://example.com/')
|
|
6
8
|
.to_return(status: 200, headers: { foo: 'bar' })
|
|
7
9
|
endpoint = SiteInspector::Endpoint.new('http://example.com')
|
|
8
|
-
|
|
10
|
+
described_class.new(endpoint)
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def stub_header(header, value)
|
|
@@ -13,7 +15,7 @@ describe SiteInspector::Endpoint::Headers do
|
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
it 'parses the headers' do
|
|
16
|
-
expect(subject.headers.count).to
|
|
18
|
+
expect(subject.headers.count).to be(1)
|
|
17
19
|
expect(subject.headers.keys).to include('foo')
|
|
18
20
|
end
|
|
19
21
|
|
|
@@ -34,30 +36,23 @@ describe SiteInspector::Endpoint::Headers do
|
|
|
34
36
|
|
|
35
37
|
it 'validates xss-protection' do
|
|
36
38
|
stub_header 'x-xss-protection', 'foo'
|
|
37
|
-
expect(subject.xss_protection?).to
|
|
39
|
+
expect(subject.xss_protection?).to be(false)
|
|
38
40
|
|
|
39
41
|
stub_header 'x-xss-protection', '1; mode=block'
|
|
40
|
-
expect(subject.xss_protection?).to
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'checks for clickjack proetection' do
|
|
44
|
-
expect(subject.click_jacking_protection?).to eql(false)
|
|
45
|
-
stub_header 'x-frame-options', 'foo'
|
|
46
|
-
expect(subject.click_jacking_protection).to eql('foo')
|
|
47
|
-
expect(subject.click_jacking_protection?).to eql(true)
|
|
42
|
+
expect(subject.xss_protection?).to be(true)
|
|
48
43
|
end
|
|
49
44
|
|
|
50
45
|
it 'checks for CSP' do
|
|
51
|
-
expect(subject.content_security_policy?).to
|
|
46
|
+
expect(subject.content_security_policy?).to be(false)
|
|
52
47
|
stub_header 'content-security-policy', 'foo'
|
|
53
48
|
expect(subject.content_security_policy).to eql('foo')
|
|
54
|
-
expect(subject.content_security_policy?).to
|
|
49
|
+
expect(subject.content_security_policy?).to be(true)
|
|
55
50
|
end
|
|
56
51
|
|
|
57
52
|
it 'checks for strict-transport-security' do
|
|
58
|
-
expect(subject.strict_transport_security?).to
|
|
53
|
+
expect(subject.strict_transport_security?).to be(false)
|
|
59
54
|
stub_header 'strict-transport-security', 'foo'
|
|
60
55
|
expect(subject.strict_transport_security).to eql('foo')
|
|
61
|
-
expect(subject.strict_transport_security?).to
|
|
56
|
+
expect(subject.strict_transport_security?).to be(true)
|
|
62
57
|
end
|
|
63
58
|
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SiteInspector::Endpoint::Hsts do
|
|
6
|
+
subject do
|
|
7
|
+
headers = { 'strict-transport-security' => 'max-age=31536000; includeSubDomains;' }
|
|
8
|
+
stub_request(:head, 'http://example.com/')
|
|
9
|
+
.to_return(status: 200, headers:)
|
|
10
|
+
endpoint = SiteInspector::Endpoint.new('http://example.com')
|
|
11
|
+
described_class.new(endpoint)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def stub_header(value)
|
|
15
|
+
allow(subject).to receive(:header) { value }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'returns the headers' do
|
|
19
|
+
expect(subject.send(:headers).class).to eql(SiteInspector::Endpoint::Headers)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'returns the HSTS header' do
|
|
23
|
+
expect(subject.send(:header)).to eql('max-age=31536000; includeSubDomains;')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'parses the directives' do
|
|
27
|
+
expect(subject.send(:directives).count).to be(2)
|
|
28
|
+
expect(subject.send(:directives).first).to eql('max-age=31536000')
|
|
29
|
+
expect(subject.send(:directives).last).to eql('includeSubDomains')
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'parses pairs' do
|
|
33
|
+
expect(subject.send(:pairs).keys).to include(:'max-age')
|
|
34
|
+
expect(subject.send(:pairs)[:'max-age']).to eql('31536000')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'knows if the header is valid' do
|
|
38
|
+
expect(subject.valid?).to be(true)
|
|
39
|
+
|
|
40
|
+
allow(subject).to receive(:pairs).and_return(['fo o' => 'bar'])
|
|
41
|
+
expect(subject.valid?).to be(false)
|
|
42
|
+
|
|
43
|
+
allow(subject).to receive(:pairs).and_return(["fo'o" => 'bar'])
|
|
44
|
+
expect(subject.valid?).to be(false)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'knows the max age' do
|
|
48
|
+
expect(subject.max_age).to be(31_536_000)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'knows if subdomains are included' do
|
|
52
|
+
expect(subject.include_subdomains?).to be(true)
|
|
53
|
+
allow(subject).to receive(:pairs).and_return(foo: 'bar')
|
|
54
|
+
expect(subject.include_subdomains?).to be(false)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "knows if it's preloaded" do
|
|
58
|
+
expect(subject.preload?).to be(false)
|
|
59
|
+
allow(subject).to receive(:pairs).and_return(preload: nil)
|
|
60
|
+
expect(subject.preload?).to be(true)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "knows if it's enabled" do
|
|
64
|
+
expect(subject.enabled?).to be(true)
|
|
65
|
+
|
|
66
|
+
allow(subject).to receive(:pairs).and_return('max-age': 0)
|
|
67
|
+
expect(subject.preload?).to be(false)
|
|
68
|
+
|
|
69
|
+
allow(subject).to receive(:pairs).and_return(foo: 'bar')
|
|
70
|
+
expect(subject.preload?).to be(false)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "knows if it's preload ready" do
|
|
74
|
+
expect(subject.preload_ready?).to be(false)
|
|
75
|
+
|
|
76
|
+
pairs = { 'max-age': 10_886_401, preload: nil, includesubdomains: nil }
|
|
77
|
+
allow(subject).to receive(:pairs) { pairs }
|
|
78
|
+
expect(subject.preload_ready?).to be(true)
|
|
79
|
+
|
|
80
|
+
pairs = { 'max-age': 10_886_401, includesubdomains: nil }
|
|
81
|
+
allow(subject).to receive(:pairs) { pairs }
|
|
82
|
+
expect(subject.preload_ready?).to be(false)
|
|
83
|
+
|
|
84
|
+
pairs = { 'max-age': 10_886_401, preload: nil, includesubdomains: nil }
|
|
85
|
+
allow(subject).to receive(:pairs) { pairs }
|
|
86
|
+
expect(subject.preload_ready?).to be(true)
|
|
87
|
+
|
|
88
|
+
pairs = { 'max-age': 5, preload: nil, includesubdomains: nil }
|
|
89
|
+
allow(subject).to receive(:pairs) { pairs }
|
|
90
|
+
expect(subject.preload_ready?).to be(false)
|
|
91
|
+
end
|
|
92
|
+
end
|
data/spec/{checks/site_inspector_endpoint_https_spec.rb → site_inspector/endpoint/https_spec.rb}
RENAMED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe SiteInspector::Endpoint::Https do
|
|
@@ -5,8 +7,8 @@ describe SiteInspector::Endpoint::Https do
|
|
|
5
7
|
stub_request(:head, 'https://example.com/')
|
|
6
8
|
.to_return(status: 200)
|
|
7
9
|
endpoint = SiteInspector::Endpoint.new('https://example.com')
|
|
8
|
-
allow(endpoint.response).to receive(:return_code)
|
|
9
|
-
|
|
10
|
+
allow(endpoint.response).to receive(:return_code).and_return(:ok)
|
|
11
|
+
described_class.new(endpoint)
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
it 'knows the scheme' do
|
|
@@ -14,34 +16,34 @@ describe SiteInspector::Endpoint::Https do
|
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
it 'knows if the scheme is https' do
|
|
17
|
-
expect(subject.scheme?).to
|
|
18
|
-
allow(subject).to receive(:scheme)
|
|
19
|
-
expect(subject.scheme?).to
|
|
19
|
+
expect(subject.scheme?).to be(true)
|
|
20
|
+
allow(subject).to receive(:scheme).and_return('http')
|
|
21
|
+
expect(subject.scheme?).to be(false)
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
it "knows if it's valid" do
|
|
23
|
-
expect(subject.valid?).to
|
|
25
|
+
expect(subject.valid?).to be(true)
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
it "knows when there's a bad chain" do
|
|
27
|
-
expect(subject.bad_chain?).to
|
|
29
|
+
expect(subject.bad_chain?).to be(false)
|
|
28
30
|
|
|
29
31
|
url = Addressable::URI.parse('https://example.com')
|
|
30
32
|
response = Typhoeus::Response.new(return_code: :ssl_cacert)
|
|
31
33
|
response.request = Typhoeus::Request.new(url)
|
|
32
34
|
|
|
33
35
|
allow(subject).to receive(:response) { response }
|
|
34
|
-
expect(subject.bad_chain?).to
|
|
36
|
+
expect(subject.bad_chain?).to be(true)
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
it "knows when there's a bad name" do
|
|
38
|
-
expect(subject.bad_name?).to
|
|
40
|
+
expect(subject.bad_name?).to be(false)
|
|
39
41
|
|
|
40
42
|
url = Addressable::URI.parse('https://example.com')
|
|
41
43
|
response = Typhoeus::Response.new(return_code: :peer_failed_verification)
|
|
42
44
|
response.request = Typhoeus::Request.new(url)
|
|
43
45
|
|
|
44
46
|
allow(subject).to receive(:response) { response }
|
|
45
|
-
expect(subject.bad_name?).to
|
|
47
|
+
expect(subject.bad_name?).to be(true)
|
|
46
48
|
end
|
|
47
49
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SiteInspector::Endpoint::Wappalyzer do
|
|
6
|
+
subject(:wappalyzer) { described_class.new(endpoint) }
|
|
7
|
+
|
|
8
|
+
let(:domain) { 'http://example.com' }
|
|
9
|
+
let(:endpoint) { SiteInspector::Endpoint.new(domain) }
|
|
10
|
+
|
|
11
|
+
it 'raises a WappalyzerError naming the command when output is not JSON' do
|
|
12
|
+
status = instance_double(Process::Status, exitstatus: 1)
|
|
13
|
+
allow(described_class).to receive(:run_command).and_return(['not json', status])
|
|
14
|
+
|
|
15
|
+
expect { wappalyzer.send(:data) }.to raise_error(
|
|
16
|
+
SiteInspector::Endpoint::Wappalyzer::WappalyzerError,
|
|
17
|
+
%r{Command `wappalyzer http://example.com/` failed: not json}
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SiteInspector::Endpoint::WellKnown do
|
|
6
|
+
subject do
|
|
7
|
+
stub_request(:head, 'http://example.com/')
|
|
8
|
+
.to_return(status: 200, headers: { foo: 'bar' })
|
|
9
|
+
endpoint = SiteInspector::Endpoint.new('http://example.com')
|
|
10
|
+
described_class.new(endpoint)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
# NOTE: these tests make external WHOIS calls; run them with LIVE=1
|
|
6
|
+
describe SiteInspector::Endpoint::Whois, :live do
|
|
7
|
+
subject do
|
|
8
|
+
stub_request(:head, site).to_return(status: 200)
|
|
9
|
+
endpoint = SiteInspector::Endpoint.new(site)
|
|
10
|
+
described_class.new(endpoint)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:site) { 'https://example.com' }
|
|
14
|
+
|
|
15
|
+
it 'returns the whois for the IP' do
|
|
16
|
+
expect(subject.ip).to match(/Derrick Sawyer/)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'returns the whois for the domain' do
|
|
20
|
+
expect(subject.domain).to match(/Domain Name: EXAMPLE\.COM/)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'returns the hash' do
|
|
24
|
+
expect(subject.to_h[:domain].keys.first).to eql('Domain Name')
|
|
25
|
+
expect(subject.to_h[:domain].values.first).to eql('EXAMPLE.COM')
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe SiteInspector::Endpoint do
|
|
4
|
-
|
|
5
|
-
subject { SiteInspector::Endpoint.new('http://example.com') }
|
|
6
|
+
subject { described_class.new('http://example.com') }
|
|
6
7
|
|
|
7
8
|
it 'downcases the host' do
|
|
8
|
-
endpoint =
|
|
9
|
-
expect(endpoint.host).to eql('example.com')
|
|
9
|
+
endpoint = described_class.new('http://EXAMPLE.com')
|
|
10
|
+
expect(endpoint.host.to_s).to eql('example.com')
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
it 'strips www from the host' do
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
skip
|
|
15
|
+
endpoint = described_class.new('http://www.example.com')
|
|
16
|
+
expect(endpoint.host.to_s).to eql('example.com')
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
it 'returns the uri' do
|
|
@@ -19,12 +21,12 @@ describe SiteInspector::Endpoint do
|
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
it 'knows if an endpoint is www' do
|
|
22
|
-
expect(subject.www?).to
|
|
23
|
-
expect(subject.root?).to
|
|
24
|
+
expect(subject.www?).to be(false)
|
|
25
|
+
expect(subject.root?).to be(true)
|
|
24
26
|
|
|
25
|
-
endpoint =
|
|
26
|
-
expect(endpoint.www?).to
|
|
27
|
-
expect(endpoint.root?).to
|
|
27
|
+
endpoint = described_class.new('http://www.example.com')
|
|
28
|
+
expect(endpoint.www?).to be(true)
|
|
29
|
+
expect(endpoint.root?).to be(false)
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
it 'knows if an endpoint is http' do
|
|
@@ -34,8 +36,8 @@ describe SiteInspector::Endpoint do
|
|
|
34
36
|
stub_request(:head, 'https://example.com/')
|
|
35
37
|
.to_return(status: 500, body: 'content')
|
|
36
38
|
|
|
37
|
-
expect(subject.https?).to
|
|
38
|
-
expect(subject.http?).to
|
|
39
|
+
expect(subject.https?).to be(false)
|
|
40
|
+
expect(subject.http?).to be(true)
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
it 'knows if an endpoint is https' do
|
|
@@ -45,15 +47,15 @@ describe SiteInspector::Endpoint do
|
|
|
45
47
|
stub_request(:head, 'https://example.com/')
|
|
46
48
|
.to_return(status: 200, body: 'content')
|
|
47
49
|
|
|
48
|
-
endpoint =
|
|
49
|
-
expect(endpoint.https?).to
|
|
50
|
-
expect(endpoint.http?).to
|
|
50
|
+
endpoint = described_class.new('https://example.com')
|
|
51
|
+
expect(endpoint.https?).to be(true)
|
|
52
|
+
expect(endpoint.http?).to be(false)
|
|
51
53
|
end
|
|
52
54
|
|
|
53
55
|
it 'knows the scheme' do
|
|
54
56
|
expect(subject.scheme).to eql('http')
|
|
55
57
|
|
|
56
|
-
endpoint =
|
|
58
|
+
endpoint = described_class.new('https://example.com')
|
|
57
59
|
expect(endpoint.scheme).to eql('https')
|
|
58
60
|
end
|
|
59
61
|
|
|
@@ -79,7 +81,7 @@ describe SiteInspector::Endpoint do
|
|
|
79
81
|
.to_return(status: 301, headers: { location: 'http://example.com/foo' })
|
|
80
82
|
|
|
81
83
|
response = subject.request(followlocation: true)
|
|
82
|
-
expect(response.request.options[:followlocation]).to
|
|
84
|
+
expect(response.request.options[:followlocation]).to be(true)
|
|
83
85
|
end
|
|
84
86
|
|
|
85
87
|
it 'returns the response' do
|
|
@@ -95,15 +97,15 @@ describe SiteInspector::Endpoint do
|
|
|
95
97
|
stub_request(:head, 'http://example.com/')
|
|
96
98
|
.to_return(status: 200, body: 'content')
|
|
97
99
|
|
|
98
|
-
expect(subject.responds?).to
|
|
100
|
+
expect(subject.responds?).to be(true)
|
|
99
101
|
end
|
|
100
102
|
|
|
101
103
|
it "knows when there's not a response" do
|
|
102
104
|
allow(subject).to receive(:response) { Typhoeus::Response.new(code: 0) }
|
|
103
|
-
expect(subject.responds?).to
|
|
105
|
+
expect(subject.responds?).to be(false)
|
|
104
106
|
|
|
105
107
|
allow(subject).to receive(:response) { Typhoeus::Response.new(return_code: :operation_timedout) }
|
|
106
|
-
expect(subject.responds?).to
|
|
108
|
+
expect(subject.responds?).to be(false)
|
|
107
109
|
end
|
|
108
110
|
|
|
109
111
|
it 'knows the response code' do
|
|
@@ -113,55 +115,71 @@ describe SiteInspector::Endpoint do
|
|
|
113
115
|
expect(subject.response_code).to eql('200')
|
|
114
116
|
end
|
|
115
117
|
|
|
118
|
+
it 'is not up when there is no response' do
|
|
119
|
+
allow(subject).to receive(:response).and_return(nil)
|
|
120
|
+
expect(subject.up?).to be(false)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'is up for 2xx and 3xx responses and down otherwise' do
|
|
124
|
+
allow(subject).to receive(:response) { Typhoeus::Response.new(code: 200) }
|
|
125
|
+
expect(subject.up?).to be(true)
|
|
126
|
+
|
|
127
|
+
allow(subject).to receive(:response) { Typhoeus::Response.new(code: 301) }
|
|
128
|
+
expect(subject.up?).to be(true)
|
|
129
|
+
|
|
130
|
+
allow(subject).to receive(:response) { Typhoeus::Response.new(code: 500) }
|
|
131
|
+
expect(subject.up?).to be(false)
|
|
132
|
+
end
|
|
133
|
+
|
|
116
134
|
it 'knows if a response has timed out' do
|
|
117
135
|
allow(subject).to receive(:response) { Typhoeus::Response.new(return_code: :operation_timedout) }
|
|
118
|
-
expect(subject.timed_out?).to
|
|
136
|
+
expect(subject.timed_out?).to be(true)
|
|
119
137
|
end
|
|
120
138
|
|
|
121
139
|
it 'considers a 200 response code to be live and a response' do
|
|
122
140
|
stub_request(:head, 'http://example.com/')
|
|
123
141
|
.to_return(status: 200)
|
|
124
142
|
|
|
125
|
-
expect(subject.up?).to
|
|
126
|
-
expect(subject.responds?).to
|
|
143
|
+
expect(subject.up?).to be(true)
|
|
144
|
+
expect(subject.responds?).to be(true)
|
|
127
145
|
end
|
|
128
146
|
|
|
129
147
|
it 'considers a 301 response code to be live and a response' do
|
|
130
148
|
stub_request(:head, 'http://example.com/')
|
|
131
149
|
.to_return(status: 301)
|
|
132
150
|
|
|
133
|
-
expect(subject.up?).to
|
|
134
|
-
expect(subject.responds?).to
|
|
151
|
+
expect(subject.up?).to be(true)
|
|
152
|
+
expect(subject.responds?).to be(true)
|
|
135
153
|
end
|
|
136
154
|
|
|
137
155
|
it 'considers a 404 response code to be down but a response' do
|
|
138
156
|
stub_request(:head, 'http://example.com/')
|
|
139
157
|
.to_return(status: 404)
|
|
140
158
|
|
|
141
|
-
expect(subject.up?).to
|
|
142
|
-
expect(subject.responds?).to
|
|
159
|
+
expect(subject.up?).to be(false)
|
|
160
|
+
expect(subject.responds?).to be(true)
|
|
143
161
|
end
|
|
144
162
|
|
|
145
163
|
it 'considers a 500 response code to be down but a response' do
|
|
146
164
|
stub_request(:head, 'http://example.com/')
|
|
147
165
|
.to_return(status: 500)
|
|
148
166
|
|
|
149
|
-
expect(subject.up?).to
|
|
150
|
-
expect(subject.responds?).to
|
|
167
|
+
expect(subject.up?).to be(false)
|
|
168
|
+
expect(subject.responds?).to be(true)
|
|
151
169
|
end
|
|
152
170
|
|
|
153
171
|
it 'considers a 0 response code (error) to down and unresponsive' do
|
|
154
172
|
allow(subject).to receive(:response) { Typhoeus::Response.new(code: 0) }
|
|
155
173
|
|
|
156
|
-
expect(subject.up?).to
|
|
157
|
-
expect(subject.responds?).to
|
|
174
|
+
expect(subject.up?).to be(false)
|
|
175
|
+
expect(subject.responds?).to be(false)
|
|
158
176
|
end
|
|
159
177
|
|
|
160
178
|
it 'considers a timeout to be down and unresponsive' do
|
|
161
179
|
allow(subject).to receive(:response) { Typhoeus::Response.new(return_code: :operation_timedout) }
|
|
162
180
|
|
|
163
|
-
expect(subject.up?).to
|
|
164
|
-
expect(subject.responds?).to
|
|
181
|
+
expect(subject.up?).to be(false)
|
|
182
|
+
expect(subject.responds?).to be(false)
|
|
165
183
|
end
|
|
166
184
|
end
|
|
167
185
|
|
|
@@ -170,7 +188,7 @@ describe SiteInspector::Endpoint do
|
|
|
170
188
|
stub_request(:head, 'http://example.com/')
|
|
171
189
|
.to_return(status: 301, headers: { location: 'http://www.example.com' })
|
|
172
190
|
|
|
173
|
-
expect(subject.redirect?).to
|
|
191
|
+
expect(subject.redirect?).to be(true)
|
|
174
192
|
end
|
|
175
193
|
|
|
176
194
|
it 'returns the redirect' do
|
|
@@ -187,14 +205,52 @@ describe SiteInspector::Endpoint do
|
|
|
187
205
|
stub_request(:head, 'http://example.com/')
|
|
188
206
|
.to_return(status: 301, headers: { location: '/foo' })
|
|
189
207
|
|
|
190
|
-
expect(subject.redirect?).to
|
|
208
|
+
expect(subject.redirect?).to be(false)
|
|
191
209
|
end
|
|
192
210
|
|
|
193
211
|
it 'handles relative redirects without a leading slash' do
|
|
194
212
|
stub_request(:head, 'http://example.com/')
|
|
195
213
|
.to_return(status: 301, headers: { location: 'foo' })
|
|
196
214
|
|
|
197
|
-
expect(subject.redirect?).to
|
|
215
|
+
expect(subject.redirect?).to be(false)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
it 'resolves protocol-relative redirects against the current scheme' do
|
|
219
|
+
stub_request(:head, 'http://example.com/')
|
|
220
|
+
.to_return(status: 301, headers: { location: '//www.example.com/' })
|
|
221
|
+
|
|
222
|
+
expect(subject.redirect?).to be(true)
|
|
223
|
+
expect(subject.redirect.uri.to_s).to eql('http://www.example.com/')
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
it 'keeps the https scheme for protocol-relative redirects to another host' do
|
|
227
|
+
endpoint = described_class.new('https://example.com')
|
|
228
|
+
stub_request(:head, 'https://example.com/')
|
|
229
|
+
.to_return(status: 301, headers: { location: '//other.com/' })
|
|
230
|
+
|
|
231
|
+
expect(endpoint.redirect.uri.to_s).to eql('https://other.com/')
|
|
232
|
+
expect(endpoint.redirect.scheme).to eql('https')
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
it 'treats query-only redirects as internal' do
|
|
236
|
+
stub_request(:head, 'http://example.com/')
|
|
237
|
+
.to_return(status: 301, headers: { location: '?q=1' })
|
|
238
|
+
|
|
239
|
+
expect(subject.redirect?).to be(false)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
it 'treats dot-segment redirects as internal' do
|
|
243
|
+
stub_request(:head, 'http://example.com/')
|
|
244
|
+
.to_return(status: 301, headers: { location: '../x' })
|
|
245
|
+
|
|
246
|
+
expect(subject.redirect?).to be(false)
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
it 'handles a redirect without a location header' do
|
|
250
|
+
stub_request(:head, 'http://example.com/')
|
|
251
|
+
.to_return(status: 301)
|
|
252
|
+
|
|
253
|
+
expect(subject.redirect?).to be(false)
|
|
198
254
|
end
|
|
199
255
|
|
|
200
256
|
it 'knows what it resolves to' do
|
|
@@ -204,7 +260,7 @@ describe SiteInspector::Endpoint do
|
|
|
204
260
|
stub_request(:head, 'http://www.example.com/')
|
|
205
261
|
.to_return(status: 200)
|
|
206
262
|
|
|
207
|
-
expect(subject.redirect?).to
|
|
263
|
+
expect(subject.redirect?).to be(true)
|
|
208
264
|
expect(subject.resolves_to.uri.to_s).to eql('http://www.example.com/')
|
|
209
265
|
end
|
|
210
266
|
|
|
@@ -215,8 +271,8 @@ describe SiteInspector::Endpoint do
|
|
|
215
271
|
stub_request(:head, 'http://www.example.gov')
|
|
216
272
|
.to_return(status: 200)
|
|
217
273
|
|
|
218
|
-
expect(subject.redirect?).to
|
|
219
|
-
expect(subject.external_redirect?).to
|
|
274
|
+
expect(subject.redirect?).to be(true)
|
|
275
|
+
expect(subject.external_redirect?).to be(true)
|
|
220
276
|
end
|
|
221
277
|
|
|
222
278
|
it 'knows internal redirects are not external redirects' do
|
|
@@ -226,24 +282,25 @@ describe SiteInspector::Endpoint do
|
|
|
226
282
|
stub_request(:head, 'https://example.com/')
|
|
227
283
|
.to_return(status: 200)
|
|
228
284
|
|
|
229
|
-
expect(subject.external_redirect?).to
|
|
285
|
+
expect(subject.external_redirect?).to be(false)
|
|
230
286
|
end
|
|
231
287
|
end
|
|
232
288
|
|
|
233
289
|
context 'checks' do
|
|
234
290
|
it 'identifies checks' do
|
|
235
|
-
expected =
|
|
291
|
+
expected = 10
|
|
236
292
|
pa11y = SiteInspector::Endpoint::Accessibility.pa11y?
|
|
237
293
|
expected -= 1 unless pa11y
|
|
238
|
-
|
|
294
|
+
expected -= 1 unless SiteInspector::Endpoint::Wappalyzer.wappalyzer?
|
|
295
|
+
expect(described_class.checks.count).to eql(expected)
|
|
239
296
|
end
|
|
240
297
|
|
|
241
|
-
|
|
298
|
+
described_class.checks.each do |check|
|
|
242
299
|
it "responds to the #{check} check" do
|
|
243
300
|
stub_request(:head, 'http://example.com/')
|
|
244
301
|
.to_return(status: 200)
|
|
245
302
|
|
|
246
|
-
expect(subject.send(check.name)).
|
|
303
|
+
expect(subject.send(check.name)).not_to be_nil
|
|
247
304
|
expect(subject.send(check.name).class).to eql(check)
|
|
248
305
|
end
|
|
249
306
|
end
|