site-inspector 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +34 -0
  3. data/.ruby-version +1 -1
  4. data/Gemfile +1 -1
  5. data/Guardfile +1 -1
  6. data/README.md +6 -1
  7. data/Rakefile +2 -2
  8. data/bin/site-inspector +15 -15
  9. data/lib/cliver/dependency_ext.rb +21 -0
  10. data/lib/site-inspector.rb +13 -11
  11. data/lib/site-inspector/checks/accessibility.rb +27 -17
  12. data/lib/site-inspector/checks/check.rb +1 -3
  13. data/lib/site-inspector/checks/content.rb +6 -6
  14. data/lib/site-inspector/checks/cookies.rb +6 -8
  15. data/lib/site-inspector/checks/dns.rb +21 -20
  16. data/lib/site-inspector/checks/headers.rb +12 -13
  17. data/lib/site-inspector/checks/hsts.rb +8 -9
  18. data/lib/site-inspector/checks/https.rb +3 -5
  19. data/lib/site-inspector/checks/sniffer.rb +8 -9
  20. data/lib/site-inspector/domain.rb +28 -32
  21. data/lib/site-inspector/endpoint.rb +31 -32
  22. data/lib/site-inspector/version.rb +1 -1
  23. data/script/cibuild +3 -1
  24. data/script/pa11y-version +9 -0
  25. data/site-inspector.gemspec +25 -25
  26. data/spec/checks/site_inspector_endpoint_accessibility_spec.rb +31 -30
  27. data/spec/checks/site_inspector_endpoint_check_spec.rb +10 -11
  28. data/spec/checks/site_inspector_endpoint_content_spec.rb +43 -44
  29. data/spec/checks/site_inspector_endpoint_cookies_spec.rb +30 -31
  30. data/spec/checks/site_inspector_endpoint_dns_spec.rb +72 -77
  31. data/spec/checks/site_inspector_endpoint_headers_spec.rb +26 -27
  32. data/spec/checks/site_inspector_endpoint_hsts_spec.rb +26 -27
  33. data/spec/checks/site_inspector_endpoint_https_spec.rb +11 -12
  34. data/spec/checks/site_inspector_endpoint_sniffer_spec.rb +56 -57
  35. data/spec/site_inspector_cache_spec.rb +6 -6
  36. data/spec/site_inspector_disk_cache_spec.rb +9 -9
  37. data/spec/site_inspector_domain_spec.rb +132 -136
  38. data/spec/site_inspector_endpoint_spec.rb +108 -108
  39. data/spec/site_inspector_spec.rb +17 -18
  40. data/spec/spec_helper.rb +3 -3
  41. metadata +21 -3
@@ -1,22 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SiteInspector::Endpoint::Https do
4
-
5
4
  subject do
6
- stub_request(:head, "https://example.com/").
7
- to_return(:status => 200 )
8
- endpoint = SiteInspector::Endpoint.new("https://example.com")
5
+ stub_request(:head, 'https://example.com/')
6
+ .to_return(status: 200)
7
+ endpoint = SiteInspector::Endpoint.new('https://example.com')
9
8
  allow(endpoint.response).to receive(:return_code) { :ok }
10
9
  SiteInspector::Endpoint::Https.new(endpoint)
11
10
  end
12
11
 
13
- it "knows the scheme" do
14
- expect(subject.send(:scheme)).to eql("https")
12
+ it 'knows the scheme' do
13
+ expect(subject.send(:scheme)).to eql('https')
15
14
  end
16
15
 
17
- it "knows if the scheme is https" do
16
+ it 'knows if the scheme is https' do
18
17
  expect(subject.scheme?).to eql(true)
19
- allow(subject).to receive(:scheme) { "http" }
18
+ allow(subject).to receive(:scheme) { 'http' }
20
19
  expect(subject.scheme?).to eql(false)
21
20
  end
22
21
 
@@ -27,8 +26,8 @@ describe SiteInspector::Endpoint::Https do
27
26
  it "knows when there's a bad chain" do
28
27
  expect(subject.bad_chain?).to eql(false)
29
28
 
30
- url = Addressable::URI.parse("https://example.com")
31
- response = Typhoeus::Response.new(:return_code => :ssl_cacert)
29
+ url = Addressable::URI.parse('https://example.com')
30
+ response = Typhoeus::Response.new(return_code: :ssl_cacert)
32
31
  response.request = Typhoeus::Request.new(url)
33
32
 
34
33
  allow(subject).to receive(:response) { response }
@@ -38,8 +37,8 @@ describe SiteInspector::Endpoint::Https do
38
37
  it "knows when there's a bad name" do
39
38
  expect(subject.bad_name?).to eql(false)
40
39
 
41
- url = Addressable::URI.parse("https://example.com")
42
- response = Typhoeus::Response.new(:return_code => :peer_failed_verification)
40
+ url = Addressable::URI.parse('https://example.com')
41
+ response = Typhoeus::Response.new(return_code: :peer_failed_verification)
43
42
  response.request = Typhoeus::Request.new(url)
44
43
 
45
44
  allow(subject).to receive(:response) { response }
@@ -1,35 +1,34 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SiteInspector::Endpoint::Sniffer do
4
-
5
4
  def stub_header(header, value)
6
5
  allow(subject.endpoint.headers).to receive(:headers) { { header => value } }
7
6
  end
8
7
 
9
8
  def set_cookie(key, value)
10
9
  cookies = [
11
- CGI::Cookie::new(
12
- "name" => "foo",
13
- "value" => "bar",
14
- "domain" => "example.com",
15
- "path" => "/"
10
+ CGI::Cookie.new(
11
+ 'name' => 'foo',
12
+ 'value' => 'bar',
13
+ 'domain' => 'example.com',
14
+ 'path' => '/'
16
15
  ),
17
- CGI::Cookie::new(
18
- "name" => key,
19
- "value" => value,
20
- "domain" => "example.com",
21
- "path" => "/"
16
+ CGI::Cookie.new(
17
+ 'name' => key,
18
+ 'value' => value,
19
+ 'domain' => 'example.com',
20
+ 'path' => '/'
22
21
  )
23
- ].map { |c| c.to_s }
22
+ ].map(&:to_s)
24
23
 
25
- stub_request(:get, "http://example.com/").
26
- to_return(:status => 200, :body => "" )
24
+ stub_request(:get, 'http://example.com/')
25
+ .to_return(status: 200, body: '')
27
26
 
28
- stub_request(:head, "http://example.com/").
29
- to_return(:status => 200, :headers => { "set-cookie" => cookies } )
27
+ stub_request(:head, 'http://example.com/')
28
+ .to_return(status: 200, headers: { 'set-cookie' => cookies })
30
29
  end
31
30
 
32
- context "stubbed body" do
31
+ context 'stubbed body' do
33
32
  subject do
34
33
  body = <<-eos
35
34
  <html>
@@ -51,96 +50,96 @@ describe SiteInspector::Endpoint::Sniffer do
51
50
  </html>
52
51
  eos
53
52
 
54
- stub_request(:get, "http://example.com/").
55
- to_return(:status => 200, :body => body )
53
+ stub_request(:get, 'http://example.com/')
54
+ .to_return(status: 200, body: body)
56
55
 
57
- stub_request(:head, "http://example.com/").
58
- to_return(:status => 200)
59
- endpoint = SiteInspector::Endpoint.new("http://example.com")
56
+ stub_request(:head, 'http://example.com/')
57
+ .to_return(status: 200)
58
+ endpoint = SiteInspector::Endpoint.new('http://example.com')
60
59
  SiteInspector::Endpoint::Sniffer.new(endpoint)
61
60
  end
62
61
 
63
- it "sniffs" do
62
+ it 'sniffs' do
64
63
  sniff = subject.send(:sniff, :cms)
65
64
  expect(sniff).to eql(:wordpress)
66
65
  end
67
66
 
68
- it "detects the CMS" do
67
+ it 'detects the CMS' do
69
68
  expect(subject.framework).to eql(:wordpress)
70
69
  end
71
70
 
72
- it "detects the analytics" do
71
+ it 'detects the analytics' do
73
72
  expect(subject.analytics).to eql(:google_analytics)
74
73
  end
75
74
 
76
- it "detects javascript" do
75
+ it 'detects javascript' do
77
76
  expect(subject.javascript).to eql(:jquery)
78
77
  end
79
78
 
80
- it "detects advertising" do
79
+ it 'detects advertising' do
81
80
  expect(subject.advertising).to eql(:adsense)
82
81
  end
83
82
 
84
- it "knows wordpress is open source" do
83
+ it 'knows wordpress is open source' do
85
84
  expect(subject.open_source?).to eql(true)
86
85
  end
87
86
  end
88
87
 
89
- context "no body" do
88
+ context 'no body' do
90
89
  subject do
91
- endpoint = SiteInspector::Endpoint.new("http://example.com")
90
+ endpoint = SiteInspector::Endpoint.new('http://example.com')
92
91
  SiteInspector::Endpoint::Sniffer.new(endpoint)
93
92
  end
94
93
 
95
94
  it "knows when something isn't open source" do
96
- set_cookie("foo", "bar")
95
+ set_cookie('foo', 'bar')
97
96
  expect(subject.open_source?).to eql(false)
98
97
  end
99
98
 
100
- it "detects PHP" do
101
- set_cookie("PHPSESSID", "1234")
99
+ it 'detects PHP' do
100
+ set_cookie('PHPSESSID', '1234')
102
101
  expect(subject.framework).to eql(:php)
103
102
  expect(subject.open_source?).to eql(true)
104
103
  end
105
104
 
106
- it "detects Expression Engine" do
107
- set_cookie("exp_csrf_token", "1234")
105
+ it 'detects Expression Engine' do
106
+ set_cookie('exp_csrf_token', '1234')
108
107
  expect(subject.framework).to eql(:expression_engine)
109
108
  expect(subject.open_source?).to eql(true)
110
109
  end
111
110
 
112
- it "detects cowboy" do
113
- stub_request(:get, "http://example.com/").
114
- to_return(:status => 200, :body => "" )
111
+ it 'detects cowboy' do
112
+ stub_request(:get, 'http://example.com/')
113
+ .to_return(status: 200, body: '')
115
114
 
116
- stub_request(:head, "http://example.com/").
117
- to_return(:status => 200, :headers => { "server" => "Cowboy" } )
115
+ stub_request(:head, 'http://example.com/')
116
+ .to_return(status: 200, headers: { 'server' => 'Cowboy' })
118
117
 
119
118
  expect(subject.framework).to eql(:cowboy)
120
119
  expect(subject.open_source?).to eql(true)
121
120
  end
122
121
 
123
- it "detects ColdFusion" do
122
+ it 'detects ColdFusion' do
124
123
  cookies = [
125
- CGI::Cookie::new(
126
- "name" => "CFID",
127
- "value" => "1234",
128
- "domain" => "example.com",
129
- "path" => "/"
124
+ CGI::Cookie.new(
125
+ 'name' => 'CFID',
126
+ 'value' => '1234',
127
+ 'domain' => 'example.com',
128
+ 'path' => '/'
130
129
  ),
131
- CGI::Cookie::new(
132
- "name" => "CFTOKEN",
133
- "value" => "5678",
134
- "domain" => "example.com",
135
- "path" => "/"
130
+ CGI::Cookie.new(
131
+ 'name' => 'CFTOKEN',
132
+ 'value' => '5678',
133
+ 'domain' => 'example.com',
134
+ 'path' => '/'
136
135
  )
137
- ].map { |c| c.to_s }
136
+ ].map(&:to_s)
137
+
138
+ stub_request(:get, 'http://example.com/')
139
+ .to_return(status: 200, body: '')
138
140
 
139
- stub_request(:get, "http://example.com/").
140
- to_return(:status => 200, :body => "" )
141
-
142
- stub_request(:head, "http://example.com/").
143
- to_return(:status => 200, :headers => { "set-cookie" => cookies } )
141
+ stub_request(:head, 'http://example.com/')
142
+ .to_return(status: 200, headers: { 'set-cookie' => cookies })
144
143
 
145
144
  expect(subject.framework).to eql(:coldfusion)
146
145
  expect(subject.open_source?).to eql(false)
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SiteInspector::Cache do
4
- it "stores a cache value" do
5
- subject.set "foo", "bar"
6
- expect(subject.instance_variable_get("@memory")["foo"]).to eql("bar")
4
+ it 'stores a cache value' do
5
+ subject.set 'foo', 'bar'
6
+ expect(subject.instance_variable_get('@memory')['foo']).to eql('bar')
7
7
  end
8
8
 
9
- it "retrieves values from the cache" do
10
- subject.instance_variable_set("@memory", {"foo" => "bar"})
11
- expect(subject.get("foo")).to eql("bar")
9
+ it 'retrieves values from the cache' do
10
+ subject.instance_variable_set('@memory', 'foo' => 'bar')
11
+ expect(subject.get('foo')).to eql('bar')
12
12
  end
13
13
  end
@@ -8,28 +8,28 @@ describe SiteInspector::DiskCache do
8
8
  Dir.mkdir(tmpdir)
9
9
  end
10
10
 
11
- it "should write a value to disk" do
12
- foo = Typhoeus::Request.new("foo")
11
+ it 'should write a value to disk' do
12
+ foo = Typhoeus::Request.new('foo')
13
13
 
14
14
  path = File.expand_path foo.cache_key, tmpdir
15
- expect(File.exists?(path)).to eql(false)
15
+ expect(File.exist?(path)).to eql(false)
16
16
 
17
- subject.set foo, "bar"
17
+ subject.set foo, 'bar'
18
18
 
19
- expect(File.exists?(path)).to eql(true)
19
+ expect(File.exist?(path)).to eql(true)
20
20
  expect(File.open(path).read).to eql("I\"bar:ET")
21
21
  end
22
22
 
23
- it "should read a value from disk" do
24
- foo = Typhoeus::Request.new("foo")
23
+ it 'should read a value from disk' do
24
+ foo = Typhoeus::Request.new('foo')
25
25
 
26
26
  path = File.expand_path foo.cache_key, tmpdir
27
27
  File.write(path, "I\"bar:ET")
28
- expect(subject.get(foo)).to eql("bar")
28
+ expect(subject.get(foo)).to eql('bar')
29
29
  end
30
30
 
31
31
  it "should calculate a file's path" do
32
- foo = Typhoeus::Request.new("foo")
32
+ foo = Typhoeus::Request.new('foo')
33
33
 
34
34
  path = File.expand_path foo.cache_key, tmpdir
35
35
  expect(subject.send(:path, foo)).to eql(path)
@@ -1,81 +1,80 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SiteInspector::Domain do
4
+ subject { SiteInspector::Domain.new('example.com') }
4
5
 
5
- subject { SiteInspector::Domain.new("example.com") }
6
-
7
- context "domain parsing" do
8
- it "downcases the domain" do
9
- domain = SiteInspector::Domain.new("EXAMPLE.com")
10
- expect(domain.host).to eql("example.com")
6
+ context 'domain parsing' do
7
+ it 'downcases the domain' do
8
+ domain = SiteInspector::Domain.new('EXAMPLE.com')
9
+ expect(domain.host).to eql('example.com')
11
10
  end
12
11
 
13
- it "strips http from the domain" do
14
- domain = SiteInspector::Domain.new("http://example.com")
15
- expect(domain.host).to eql("example.com")
12
+ it 'strips http from the domain' do
13
+ domain = SiteInspector::Domain.new('http://example.com')
14
+ expect(domain.host).to eql('example.com')
16
15
  end
17
16
 
18
- it "strips https from the domain" do
19
- domain = SiteInspector::Domain.new("https://example.com")
20
- expect(domain.host).to eql("example.com")
17
+ it 'strips https from the domain' do
18
+ domain = SiteInspector::Domain.new('https://example.com')
19
+ expect(domain.host).to eql('example.com')
21
20
  end
22
21
 
23
- it "strips www from the domain" do
24
- domain = SiteInspector::Domain.new("www.example.com")
25
- expect(domain.host).to eql("example.com")
22
+ it 'strips www from the domain' do
23
+ domain = SiteInspector::Domain.new('www.example.com')
24
+ expect(domain.host).to eql('example.com')
26
25
  end
27
26
 
28
- it "strips http://www from the domain" do
29
- domain = SiteInspector::Domain.new("http://www.example.com")
30
- expect(domain.host).to eql("example.com")
27
+ it 'strips http://www from the domain' do
28
+ domain = SiteInspector::Domain.new('http://www.example.com')
29
+ expect(domain.host).to eql('example.com')
31
30
  end
32
31
 
33
- it "strips paths from the domain" do
34
- domain = SiteInspector::Domain.new("http://www.example.com/foo")
35
- expect(domain.host).to eql("example.com")
32
+ it 'strips paths from the domain' do
33
+ domain = SiteInspector::Domain.new('http://www.example.com/foo')
34
+ expect(domain.host).to eql('example.com')
36
35
  end
37
36
 
38
- it "strips trailing slashes from the domain" do
39
- domain = SiteInspector::Domain.new("http://www.example.com/")
40
- expect(domain.host).to eql("example.com")
37
+ it 'strips trailing slashes from the domain' do
38
+ domain = SiteInspector::Domain.new('http://www.example.com/')
39
+ expect(domain.host).to eql('example.com')
41
40
  end
42
41
  end
43
42
 
44
- context "endpoints" do
45
- it "generates the endpoints" do
43
+ context 'endpoints' do
44
+ it 'generates the endpoints' do
46
45
  endpoints = subject.endpoints
47
46
  expect(endpoints.count).to eql(4)
48
- expect(endpoints[0].to_s).to eql("https://example.com/")
49
- expect(endpoints[1].to_s).to eql("https://www.example.com/")
50
- expect(endpoints[2].to_s).to eql("http://example.com/")
51
- expect(endpoints[3].to_s).to eql("http://www.example.com/")
47
+ expect(endpoints[0].to_s).to eql('https://example.com/')
48
+ expect(endpoints[1].to_s).to eql('https://www.example.com/')
49
+ expect(endpoints[2].to_s).to eql('http://example.com/')
50
+ expect(endpoints[3].to_s).to eql('http://www.example.com/')
52
51
  end
53
52
  end
54
53
 
55
- it "knows the canonical domain" do
56
- stub_request(:head, "https://example.com/").to_return(:status => 500)
57
- stub_request(:head, "https://www.example.com/").to_return(:status => 500)
58
- stub_request(:head, "http://www.example.com/").to_return(:status => 200)
59
- stub_request(:head, "http://example.com/").to_return(:status => 200)
60
- expect(subject.canonical_endpoint.to_s).to eql("http://example.com/")
54
+ it 'knows the canonical domain' do
55
+ stub_request(:head, 'https://example.com/').to_return(status: 500)
56
+ stub_request(:head, 'https://www.example.com/').to_return(status: 500)
57
+ stub_request(:head, 'http://www.example.com/').to_return(status: 200)
58
+ stub_request(:head, 'http://example.com/').to_return(status: 200)
59
+ expect(subject.canonical_endpoint.to_s).to eql('http://example.com/')
61
60
  end
62
61
 
63
- it "knows if a domain is a government domain" do
62
+ it 'knows if a domain is a government domain' do
64
63
  expect(subject.government?).to eql(false)
65
64
 
66
- domain = SiteInspector::Domain.new("whitehouse.gov")
65
+ domain = SiteInspector::Domain.new('whitehouse.gov')
67
66
  expect(domain.government?).to eql(true)
68
67
  end
69
68
 
70
- context "up" do
71
- it "considers a domain up if at least one endpoint is up" do
69
+ context 'up' do
70
+ it 'considers a domain up if at least one endpoint is up' do
72
71
  subject.endpoints.each do |endpoint|
73
- unless endpoint.uri.to_s.start_with?("http://www")
72
+ unless endpoint.uri.to_s.start_with?('http://www')
74
73
  allow(endpoint).to receive(:response) { Typhoeus::Response.new(code: 0) }
75
74
  end
76
75
  end
77
76
 
78
- stub_request(:head, "http://www.example.com/").to_return(:status => 200)
77
+ stub_request(:head, 'http://www.example.com/').to_return(status: 200)
79
78
 
80
79
  expect(subject.up?).to eql(true)
81
80
  end
@@ -89,152 +88,152 @@ describe SiteInspector::Domain do
89
88
  end
90
89
  end
91
90
 
92
- context "up" do
93
- it "considers a domain up if at least one endpoint is up" do
94
- stub_request(:head, "https://example.com/").to_return(:status => 500)
95
- stub_request(:head, "https://www.example.com/").to_return(:status => 500)
96
- stub_request(:head, "http://example.com/").to_return(:status => 500)
97
- stub_request(:head, "http://www.example.com/").to_return(:status => 200)
91
+ context 'up' do
92
+ it 'considers a domain up if at least one endpoint is up' do
93
+ stub_request(:head, 'https://example.com/').to_return(status: 500)
94
+ stub_request(:head, 'https://www.example.com/').to_return(status: 500)
95
+ stub_request(:head, 'http://example.com/').to_return(status: 500)
96
+ stub_request(:head, 'http://www.example.com/').to_return(status: 200)
98
97
 
99
98
  expect(subject.up?).to eql(true)
100
99
  end
101
100
 
102
101
  it "doesn't consider a domain up if all endpoints are down" do
103
- stub_request(:head, "https://example.com/").to_return(:status => 500)
104
- stub_request(:head, "https://www.example.com/").to_return(:status => 500)
105
- stub_request(:head, "http://example.com/").to_return(:status => 500)
106
- stub_request(:head, "http://www.example.com/").to_return(:status => 500)
102
+ stub_request(:head, 'https://example.com/').to_return(status: 500)
103
+ stub_request(:head, 'https://www.example.com/').to_return(status: 500)
104
+ stub_request(:head, 'http://example.com/').to_return(status: 500)
105
+ stub_request(:head, 'http://www.example.com/').to_return(status: 500)
107
106
 
108
107
  expect(subject.up?).to eql(false)
109
108
  end
110
109
  end
111
110
 
112
- context "www" do
113
- it "considers a site www when at least one endpoint is www" do
114
- stub_request(:head, "https://example.com/").to_return(:status => 200)
115
- stub_request(:head, "https://www.example.com/").to_return(:status => 500)
116
- stub_request(:head, "http://example.com/").to_return(:status => 500)
117
- stub_request(:head, "http://www.example.com/").to_return(:status => 200)
111
+ context 'www' do
112
+ it 'considers a site www when at least one endpoint is www' do
113
+ stub_request(:head, 'https://example.com/').to_return(status: 200)
114
+ stub_request(:head, 'https://www.example.com/').to_return(status: 500)
115
+ stub_request(:head, 'http://example.com/').to_return(status: 500)
116
+ stub_request(:head, 'http://www.example.com/').to_return(status: 200)
118
117
 
119
118
  expect(subject.www?).to eql(true)
120
119
  end
121
120
 
122
121
  it "doesn't consider a site www when no endpoint is www" do
123
- stub_request(:head, "https://example.com/").to_return(:status => 200)
124
- stub_request(:head, "https://www.example.com/").to_return(:status => 500)
125
- stub_request(:head, "http://example.com/").to_return(:status => 200)
126
- stub_request(:head, "http://www.example.com/").to_return(:status => 500)
122
+ stub_request(:head, 'https://example.com/').to_return(status: 200)
123
+ stub_request(:head, 'https://www.example.com/').to_return(status: 500)
124
+ stub_request(:head, 'http://example.com/').to_return(status: 200)
125
+ stub_request(:head, 'http://www.example.com/').to_return(status: 500)
127
126
 
128
127
  expect(subject.www?).to eql(false)
129
128
  end
130
129
  end
131
130
 
132
- context "root" do
133
- it "considers a domain root if you can connect without www" do
134
- stub_request(:head, "https://example.com/").to_return(:status => 200)
135
- stub_request(:head, "https://www.example.com/").to_return(:status => 500)
136
- stub_request(:head, "http://example.com/").to_return(:status => 500)
137
- stub_request(:head, "http://www.example.com/").to_return(:status => 500)
131
+ context 'root' do
132
+ it 'considers a domain root if you can connect without www' do
133
+ stub_request(:head, 'https://example.com/').to_return(status: 200)
134
+ stub_request(:head, 'https://www.example.com/').to_return(status: 500)
135
+ stub_request(:head, 'http://example.com/').to_return(status: 500)
136
+ stub_request(:head, 'http://www.example.com/').to_return(status: 500)
138
137
 
139
138
  expect(subject.root?).to eql(true)
140
139
  end
141
140
 
142
141
  it "doesn't call a www-only domain root" do
143
- stub_request(:head, "https://example.com/").to_return(:status => 500)
144
- stub_request(:head, "https://www.example.com/").to_return(:status => 200)
145
- stub_request(:head, "http://example.com/").to_return(:status => 500)
146
- stub_request(:head, "http://www.example.com/").to_return(:status => 200)
142
+ stub_request(:head, 'https://example.com/').to_return(status: 500)
143
+ stub_request(:head, 'https://www.example.com/').to_return(status: 200)
144
+ stub_request(:head, 'http://example.com/').to_return(status: 500)
145
+ stub_request(:head, 'http://www.example.com/').to_return(status: 200)
147
146
 
148
147
  expect(subject.root?).to eql(false)
149
148
  end
150
149
  end
151
150
 
152
- context "https" do
153
- it "knows when a domain supports https" do
154
- stub_request(:head, "https://example.com/").to_return(:status => 200)
155
- stub_request(:head, "https://www.example.com/").to_return(:status => 200)
156
- stub_request(:head, "http://example.com/").to_return(:status => 200)
157
- stub_request(:head, "http://www.example.com/").to_return(:status => 200)
151
+ context 'https' do
152
+ it 'knows when a domain supports https' do
153
+ stub_request(:head, 'https://example.com/').to_return(status: 200)
154
+ stub_request(:head, 'https://www.example.com/').to_return(status: 200)
155
+ stub_request(:head, 'http://example.com/').to_return(status: 200)
156
+ stub_request(:head, 'http://www.example.com/').to_return(status: 200)
158
157
  allow(subject.endpoints.first.https).to receive(:valid?) { true }
159
158
 
160
159
  expect(subject.https?).to eql(true)
161
160
  end
162
161
 
163
162
  it "knows when a domain doesn't support https" do
164
- stub_request(:head, "https://example.com/").to_return(:status => 500)
165
- stub_request(:head, "https://www.example.com/").to_return(:status => 500)
166
- stub_request(:head, "http://example.com/").to_return(:status => 200)
167
- stub_request(:head, "http://www.example.com/").to_return(:status => 200)
163
+ stub_request(:head, 'https://example.com/').to_return(status: 500)
164
+ stub_request(:head, 'https://www.example.com/').to_return(status: 500)
165
+ stub_request(:head, 'http://example.com/').to_return(status: 200)
166
+ stub_request(:head, 'http://www.example.com/').to_return(status: 200)
168
167
 
169
168
  expect(subject.https?).to eql(false)
170
169
  end
171
170
 
172
- it "considers HTTPS inforced when no http endpoint responds" do
173
- stub_request(:head, "https://example.com/").to_return(:status => 200)
174
- stub_request(:head, "https://www.example.com/").to_return(:status => 500)
175
- stub_request(:head, "http://example.com/").to_return(:status => 500)
176
- stub_request(:head, "http://www.example.com/").to_return(:status => 500)
171
+ it 'considers HTTPS inforced when no http endpoint responds' do
172
+ stub_request(:head, 'https://example.com/').to_return(status: 200)
173
+ stub_request(:head, 'https://www.example.com/').to_return(status: 500)
174
+ stub_request(:head, 'http://example.com/').to_return(status: 500)
175
+ stub_request(:head, 'http://www.example.com/').to_return(status: 500)
177
176
 
178
- #expect(subject.enforces_https?).to eql(true)
177
+ # expect(subject.enforces_https?).to eql(true)
179
178
  end
180
179
 
181
180
  it "doesn't consider HTTPS inforced when an http endpoint responds" do
182
- stub_request(:head, "https://example.com/").to_return(:status => 200)
183
- stub_request(:head, "https://www.example.com/").to_return(:status => 500)
184
- stub_request(:head, "http://example.com/").to_return(:status => 500)
185
- stub_request(:head, "http://www.example.com/").to_return(:status => 200)
181
+ stub_request(:head, 'https://example.com/').to_return(status: 200)
182
+ stub_request(:head, 'https://www.example.com/').to_return(status: 500)
183
+ stub_request(:head, 'http://example.com/').to_return(status: 500)
184
+ stub_request(:head, 'http://www.example.com/').to_return(status: 200)
186
185
 
187
186
  expect(subject.enforces_https?).to eql(false)
188
187
  end
189
188
 
190
- it "detects when a domain downgrades to http" do
189
+ it 'detects when a domain downgrades to http' do
191
190
  # TODO
192
191
  end
193
192
 
194
- it "detects when a domain enforces https" do
193
+ it 'detects when a domain enforces https' do
195
194
  # TODO
196
195
  end
197
196
  end
198
197
 
199
- context "canonical" do
200
- context "www" do
201
- it "detects a domain as canonically www when root is down" do
202
- stub_request(:head, "https://example.com/").to_return(:status => 500)
203
- stub_request(:head, "https://www.example.com/").to_return(:status => 500)
204
- stub_request(:head, "http://example.com/").to_return(:status => 500)
205
- stub_request(:head, "http://www.example.com/").to_return(:status => 200)
198
+ context 'canonical' do
199
+ context 'www' do
200
+ it 'detects a domain as canonically www when root is down' do
201
+ stub_request(:head, 'https://example.com/').to_return(status: 500)
202
+ stub_request(:head, 'https://www.example.com/').to_return(status: 500)
203
+ stub_request(:head, 'http://example.com/').to_return(status: 500)
204
+ stub_request(:head, 'http://www.example.com/').to_return(status: 200)
206
205
 
207
206
  expect(subject.canonically_www?).to eql(true)
208
207
  end
209
208
 
210
- it "detects a domain as canonically www when root redirects" do
211
- stub_request(:head, "https://example.com/").to_return(:status => 500)
212
- stub_request(:head, "https://www.example.com/").to_return(:status => 500)
213
- stub_request(:head, "http://example.com/").
214
- to_return(:status => 301, :headers => { :location => "http://www.example.com" } )
215
- stub_request(:head, "http://www.example.com/").to_return(:status => 200)
209
+ it 'detects a domain as canonically www when root redirects' do
210
+ stub_request(:head, 'https://example.com/').to_return(status: 500)
211
+ stub_request(:head, 'https://www.example.com/').to_return(status: 500)
212
+ stub_request(:head, 'http://example.com/')
213
+ .to_return(status: 301, headers: { location: 'http://www.example.com' })
214
+ stub_request(:head, 'http://www.example.com/').to_return(status: 200)
216
215
 
217
216
  expect(subject.canonically_www?).to eql(true)
218
217
  end
219
218
  end
220
219
 
221
- context "https" do
222
- it "detects a domain as canonically https when http is down" do
223
- stub_request(:head, "https://example.com/").to_return(:status => 200)
224
- stub_request(:head, "https://www.example.com/").to_return(:status => 200)
225
- stub_request(:head, "http://example.com/").to_return(:status => 500)
226
- stub_request(:head, "http://www.example.com/").to_return(:status => 500)
220
+ context 'https' do
221
+ it 'detects a domain as canonically https when http is down' do
222
+ stub_request(:head, 'https://example.com/').to_return(status: 200)
223
+ stub_request(:head, 'https://www.example.com/').to_return(status: 200)
224
+ stub_request(:head, 'http://example.com/').to_return(status: 500)
225
+ stub_request(:head, 'http://www.example.com/').to_return(status: 500)
227
226
  allow(subject.endpoints.first.https).to receive(:valid?) { true }
228
227
 
229
228
  expect(subject.canonically_https?).to eql(true)
230
229
  end
231
230
 
232
- it "detects a domain as canonically https when http redirect" do
233
- stub_request(:head, "https://example.com/").to_return(:status => 200)
234
- stub_request(:head, "https://www.example.com/").to_return(:status => 200)
235
- stub_request(:head, "http://example.com/").
236
- to_return(:status => 301, :headers => { :location => "https://example.com" } )
237
- stub_request(:head, "http://www.example.com/").to_return(:status => 500)
231
+ it 'detects a domain as canonically https when http redirect' do
232
+ stub_request(:head, 'https://example.com/').to_return(status: 200)
233
+ stub_request(:head, 'https://www.example.com/').to_return(status: 200)
234
+ stub_request(:head, 'http://example.com/')
235
+ .to_return(status: 301, headers: { location: 'https://example.com' })
236
+ stub_request(:head, 'http://www.example.com/').to_return(status: 500)
238
237
  allow(subject.endpoints.first.https).to receive(:valid?) { true }
239
238
 
240
239
  expect(subject.canonically_https?).to eql(true)
@@ -242,34 +241,31 @@ describe SiteInspector::Domain do
242
241
  end
243
242
  end
244
243
 
245
- context "redirects" do
246
- it "knows when a domain redirects" do
247
- stub_request(:head, "https://example.com/").to_return(:status => 500)
248
- stub_request(:head, "https://www.example.com/").to_return(:status => 500)
249
- stub_request(:head, "http://example.com/").
250
- to_return(:status => 301, :headers => { :location => "http://foo.example.com" } )
251
- stub_request(:head, "http://www.example.com/").to_return(:status => 500)
252
- stub_request(:head, "http://foo.example.com/").to_return(:status => 200)
244
+ context 'redirects' do
245
+ it 'knows when a domain redirects' do
246
+ stub_request(:head, 'https://example.com/').to_return(status: 500)
247
+ stub_request(:head, 'https://www.example.com/').to_return(status: 500)
248
+ stub_request(:head, 'http://example.com/')
249
+ .to_return(status: 301, headers: { location: 'http://foo.example.com' })
250
+ stub_request(:head, 'http://www.example.com/').to_return(status: 500)
251
+ stub_request(:head, 'http://foo.example.com/').to_return(status: 200)
253
252
 
254
253
  expect(subject.redirect?).to eql(true)
255
254
  end
256
255
  end
257
256
 
258
- context "hsts" do
259
- it "enabled" do
260
-
257
+ context 'hsts' do
258
+ it 'enabled' do
261
259
  end
262
260
 
263
- it "subdomains" do
264
-
261
+ it 'subdomains' do
265
262
  end
266
263
 
267
- it "preload ready" do
268
-
264
+ it 'preload ready' do
269
265
  end
270
266
  end
271
267
 
272
- it "returns the host as a string" do
273
- expect(subject.to_s).to eql("example.com")
268
+ it 'returns the host as a string' do
269
+ expect(subject.to_s).to eql('example.com')
274
270
  end
275
271
  end