site-inspector 3.1.0 → 3.1.1
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 +4 -4
- data/.rubocop.yml +34 -0
- data/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/Guardfile +1 -1
- data/README.md +6 -1
- data/Rakefile +2 -2
- data/bin/site-inspector +15 -15
- data/lib/cliver/dependency_ext.rb +21 -0
- data/lib/site-inspector.rb +13 -11
- data/lib/site-inspector/checks/accessibility.rb +27 -17
- data/lib/site-inspector/checks/check.rb +1 -3
- data/lib/site-inspector/checks/content.rb +6 -6
- data/lib/site-inspector/checks/cookies.rb +6 -8
- data/lib/site-inspector/checks/dns.rb +21 -20
- data/lib/site-inspector/checks/headers.rb +12 -13
- data/lib/site-inspector/checks/hsts.rb +8 -9
- data/lib/site-inspector/checks/https.rb +3 -5
- data/lib/site-inspector/checks/sniffer.rb +8 -9
- data/lib/site-inspector/domain.rb +28 -32
- data/lib/site-inspector/endpoint.rb +31 -32
- data/lib/site-inspector/version.rb +1 -1
- data/script/cibuild +3 -1
- data/script/pa11y-version +9 -0
- data/site-inspector.gemspec +25 -25
- data/spec/checks/site_inspector_endpoint_accessibility_spec.rb +31 -30
- data/spec/checks/site_inspector_endpoint_check_spec.rb +10 -11
- data/spec/checks/site_inspector_endpoint_content_spec.rb +43 -44
- data/spec/checks/site_inspector_endpoint_cookies_spec.rb +30 -31
- data/spec/checks/site_inspector_endpoint_dns_spec.rb +72 -77
- data/spec/checks/site_inspector_endpoint_headers_spec.rb +26 -27
- data/spec/checks/site_inspector_endpoint_hsts_spec.rb +26 -27
- data/spec/checks/site_inspector_endpoint_https_spec.rb +11 -12
- data/spec/checks/site_inspector_endpoint_sniffer_spec.rb +56 -57
- data/spec/site_inspector_cache_spec.rb +6 -6
- data/spec/site_inspector_disk_cache_spec.rb +9 -9
- data/spec/site_inspector_domain_spec.rb +132 -136
- data/spec/site_inspector_endpoint_spec.rb +108 -108
- data/spec/site_inspector_spec.rb +17 -18
- data/spec/spec_helper.rb +3 -3
- 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,
|
7
|
-
to_return(:
|
8
|
-
endpoint = SiteInspector::Endpoint.new(
|
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
|
14
|
-
expect(subject.send(:scheme)).to eql(
|
12
|
+
it 'knows the scheme' do
|
13
|
+
expect(subject.send(:scheme)).to eql('https')
|
15
14
|
end
|
16
15
|
|
17
|
-
it
|
16
|
+
it 'knows if the scheme is https' do
|
18
17
|
expect(subject.scheme?).to eql(true)
|
19
|
-
allow(subject).to receive(:scheme) {
|
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(
|
31
|
-
response = Typhoeus::Response.new(:
|
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(
|
42
|
-
response = Typhoeus::Response.new(:
|
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
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
CGI::Cookie.new(
|
11
|
+
'name' => 'foo',
|
12
|
+
'value' => 'bar',
|
13
|
+
'domain' => 'example.com',
|
14
|
+
'path' => '/'
|
16
15
|
),
|
17
|
-
CGI::Cookie
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
CGI::Cookie.new(
|
17
|
+
'name' => key,
|
18
|
+
'value' => value,
|
19
|
+
'domain' => 'example.com',
|
20
|
+
'path' => '/'
|
22
21
|
)
|
23
|
-
].map
|
22
|
+
].map(&:to_s)
|
24
23
|
|
25
|
-
stub_request(:get,
|
26
|
-
to_return(:
|
24
|
+
stub_request(:get, 'http://example.com/')
|
25
|
+
.to_return(status: 200, body: '')
|
27
26
|
|
28
|
-
stub_request(:head,
|
29
|
-
to_return(:
|
27
|
+
stub_request(:head, 'http://example.com/')
|
28
|
+
.to_return(status: 200, headers: { 'set-cookie' => cookies })
|
30
29
|
end
|
31
30
|
|
32
|
-
context
|
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,
|
55
|
-
to_return(:
|
53
|
+
stub_request(:get, 'http://example.com/')
|
54
|
+
.to_return(status: 200, body: body)
|
56
55
|
|
57
|
-
stub_request(:head,
|
58
|
-
|
59
|
-
endpoint = SiteInspector::Endpoint.new(
|
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
|
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
|
67
|
+
it 'detects the CMS' do
|
69
68
|
expect(subject.framework).to eql(:wordpress)
|
70
69
|
end
|
71
70
|
|
72
|
-
it
|
71
|
+
it 'detects the analytics' do
|
73
72
|
expect(subject.analytics).to eql(:google_analytics)
|
74
73
|
end
|
75
74
|
|
76
|
-
it
|
75
|
+
it 'detects javascript' do
|
77
76
|
expect(subject.javascript).to eql(:jquery)
|
78
77
|
end
|
79
78
|
|
80
|
-
it
|
79
|
+
it 'detects advertising' do
|
81
80
|
expect(subject.advertising).to eql(:adsense)
|
82
81
|
end
|
83
82
|
|
84
|
-
it
|
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
|
88
|
+
context 'no body' do
|
90
89
|
subject do
|
91
|
-
endpoint = SiteInspector::Endpoint.new(
|
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(
|
95
|
+
set_cookie('foo', 'bar')
|
97
96
|
expect(subject.open_source?).to eql(false)
|
98
97
|
end
|
99
98
|
|
100
|
-
it
|
101
|
-
set_cookie(
|
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
|
107
|
-
set_cookie(
|
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
|
113
|
-
stub_request(:get,
|
114
|
-
to_return(:
|
111
|
+
it 'detects cowboy' do
|
112
|
+
stub_request(:get, 'http://example.com/')
|
113
|
+
.to_return(status: 200, body: '')
|
115
114
|
|
116
|
-
stub_request(:head,
|
117
|
-
to_return(:
|
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
|
122
|
+
it 'detects ColdFusion' do
|
124
123
|
cookies = [
|
125
|
-
CGI::Cookie
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
124
|
+
CGI::Cookie.new(
|
125
|
+
'name' => 'CFID',
|
126
|
+
'value' => '1234',
|
127
|
+
'domain' => 'example.com',
|
128
|
+
'path' => '/'
|
130
129
|
),
|
131
|
-
CGI::Cookie
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
130
|
+
CGI::Cookie.new(
|
131
|
+
'name' => 'CFTOKEN',
|
132
|
+
'value' => '5678',
|
133
|
+
'domain' => 'example.com',
|
134
|
+
'path' => '/'
|
136
135
|
)
|
137
|
-
].map
|
136
|
+
].map(&:to_s)
|
137
|
+
|
138
|
+
stub_request(:get, 'http://example.com/')
|
139
|
+
.to_return(status: 200, body: '')
|
138
140
|
|
139
|
-
stub_request(:
|
140
|
-
to_return(:
|
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
|
5
|
-
subject.set
|
6
|
-
expect(subject.instance_variable_get(
|
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
|
10
|
-
subject.instance_variable_set(
|
11
|
-
expect(subject.get(
|
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
|
12
|
-
foo = Typhoeus::Request.new(
|
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.
|
15
|
+
expect(File.exist?(path)).to eql(false)
|
16
16
|
|
17
|
-
subject.set foo,
|
17
|
+
subject.set foo, 'bar'
|
18
18
|
|
19
|
-
expect(File.
|
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
|
24
|
-
foo = Typhoeus::Request.new(
|
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(
|
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(
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
14
|
-
domain = SiteInspector::Domain.new(
|
15
|
-
expect(domain.host).to eql(
|
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
|
19
|
-
domain = SiteInspector::Domain.new(
|
20
|
-
expect(domain.host).to eql(
|
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
|
24
|
-
domain = SiteInspector::Domain.new(
|
25
|
-
expect(domain.host).to eql(
|
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
|
29
|
-
domain = SiteInspector::Domain.new(
|
30
|
-
expect(domain.host).to eql(
|
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
|
34
|
-
domain = SiteInspector::Domain.new(
|
35
|
-
expect(domain.host).to eql(
|
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
|
39
|
-
domain = SiteInspector::Domain.new(
|
40
|
-
expect(domain.host).to eql(
|
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
|
45
|
-
it
|
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(
|
49
|
-
expect(endpoints[1].to_s).to eql(
|
50
|
-
expect(endpoints[2].to_s).to eql(
|
51
|
-
expect(endpoints[3].to_s).to eql(
|
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
|
56
|
-
stub_request(:head,
|
57
|
-
stub_request(:head,
|
58
|
-
stub_request(:head,
|
59
|
-
stub_request(:head,
|
60
|
-
expect(subject.canonical_endpoint.to_s).to eql(
|
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
|
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(
|
65
|
+
domain = SiteInspector::Domain.new('whitehouse.gov')
|
67
66
|
expect(domain.government?).to eql(true)
|
68
67
|
end
|
69
68
|
|
70
|
-
context
|
71
|
-
it
|
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?(
|
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,
|
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
|
93
|
-
it
|
94
|
-
stub_request(:head,
|
95
|
-
stub_request(:head,
|
96
|
-
stub_request(:head,
|
97
|
-
stub_request(:head,
|
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,
|
104
|
-
stub_request(:head,
|
105
|
-
stub_request(:head,
|
106
|
-
stub_request(:head,
|
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
|
113
|
-
it
|
114
|
-
stub_request(:head,
|
115
|
-
stub_request(:head,
|
116
|
-
stub_request(:head,
|
117
|
-
stub_request(:head,
|
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,
|
124
|
-
stub_request(:head,
|
125
|
-
stub_request(:head,
|
126
|
-
stub_request(:head,
|
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
|
133
|
-
it
|
134
|
-
stub_request(:head,
|
135
|
-
stub_request(:head,
|
136
|
-
stub_request(:head,
|
137
|
-
stub_request(:head,
|
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,
|
144
|
-
stub_request(:head,
|
145
|
-
stub_request(:head,
|
146
|
-
stub_request(:head,
|
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
|
153
|
-
it
|
154
|
-
stub_request(:head,
|
155
|
-
stub_request(:head,
|
156
|
-
stub_request(:head,
|
157
|
-
stub_request(:head,
|
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,
|
165
|
-
stub_request(:head,
|
166
|
-
stub_request(:head,
|
167
|
-
stub_request(:head,
|
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
|
173
|
-
stub_request(:head,
|
174
|
-
stub_request(:head,
|
175
|
-
stub_request(:head,
|
176
|
-
stub_request(:head,
|
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,
|
183
|
-
stub_request(:head,
|
184
|
-
stub_request(:head,
|
185
|
-
stub_request(:head,
|
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
|
189
|
+
it 'detects when a domain downgrades to http' do
|
191
190
|
# TODO
|
192
191
|
end
|
193
192
|
|
194
|
-
it
|
193
|
+
it 'detects when a domain enforces https' do
|
195
194
|
# TODO
|
196
195
|
end
|
197
196
|
end
|
198
197
|
|
199
|
-
context
|
200
|
-
context
|
201
|
-
it
|
202
|
-
stub_request(:head,
|
203
|
-
stub_request(:head,
|
204
|
-
stub_request(:head,
|
205
|
-
stub_request(:head,
|
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
|
211
|
-
stub_request(:head,
|
212
|
-
stub_request(:head,
|
213
|
-
stub_request(:head,
|
214
|
-
to_return(:
|
215
|
-
stub_request(:head,
|
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
|
222
|
-
it
|
223
|
-
stub_request(:head,
|
224
|
-
stub_request(:head,
|
225
|
-
stub_request(:head,
|
226
|
-
stub_request(:head,
|
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
|
233
|
-
stub_request(:head,
|
234
|
-
stub_request(:head,
|
235
|
-
stub_request(:head,
|
236
|
-
to_return(:
|
237
|
-
stub_request(:head,
|
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
|
246
|
-
it
|
247
|
-
stub_request(:head,
|
248
|
-
stub_request(:head,
|
249
|
-
stub_request(:head,
|
250
|
-
to_return(:
|
251
|
-
stub_request(:head,
|
252
|
-
stub_request(:head,
|
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
|
259
|
-
it
|
260
|
-
|
257
|
+
context 'hsts' do
|
258
|
+
it 'enabled' do
|
261
259
|
end
|
262
260
|
|
263
|
-
it
|
264
|
-
|
261
|
+
it 'subdomains' do
|
265
262
|
end
|
266
263
|
|
267
|
-
it
|
268
|
-
|
264
|
+
it 'preload ready' do
|
269
265
|
end
|
270
266
|
end
|
271
267
|
|
272
|
-
it
|
273
|
-
expect(subject.to_s).to eql(
|
268
|
+
it 'returns the host as a string' do
|
269
|
+
expect(subject.to_s).to eql('example.com')
|
274
270
|
end
|
275
271
|
end
|