site-inspector 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +3 -0
  6. data/Guardfile +8 -0
  7. data/README.md +175 -0
  8. data/Rakefile +8 -0
  9. data/bin/site-inspector +48 -21
  10. data/lib/site-inspector.rb +38 -613
  11. data/lib/site-inspector/cache.rb +9 -52
  12. data/lib/site-inspector/checks/check.rb +41 -0
  13. data/lib/site-inspector/checks/content.rb +67 -0
  14. data/lib/site-inspector/checks/dns.rb +129 -0
  15. data/lib/site-inspector/checks/headers.rb +83 -0
  16. data/lib/site-inspector/checks/hsts.rb +78 -0
  17. data/lib/site-inspector/checks/https.rb +40 -0
  18. data/lib/site-inspector/checks/sniffer.rb +42 -0
  19. data/lib/site-inspector/disk_cache.rb +38 -0
  20. data/lib/site-inspector/domain.rb +248 -0
  21. data/lib/site-inspector/endpoint.rb +200 -0
  22. data/lib/site-inspector/rails_cache.rb +11 -0
  23. data/lib/site-inspector/version.rb +3 -0
  24. data/script/bootstrap +1 -0
  25. data/script/cibuild +7 -0
  26. data/script/console +1 -0
  27. data/script/release +38 -0
  28. data/site-inspector.gemspec +33 -0
  29. data/spec/checks/site_inspector_endpoint_check_spec.rb +34 -0
  30. data/spec/checks/site_inspector_endpoint_content_spec.rb +89 -0
  31. data/spec/checks/site_inspector_endpoint_dns_spec.rb +167 -0
  32. data/spec/checks/site_inspector_endpoint_headers_spec.rb +74 -0
  33. data/spec/checks/site_inspector_endpoint_hsts_spec.rb +91 -0
  34. data/spec/checks/site_inspector_endpoint_https_spec.rb +48 -0
  35. data/spec/checks/site_inspector_endpoint_sniffer_spec.rb +52 -0
  36. data/spec/site_inspector_cache_spec.rb +13 -0
  37. data/spec/site_inspector_disc_cache_spec.rb +31 -0
  38. data/spec/site_inspector_domain_spec.rb +252 -0
  39. data/spec/site_inspector_endpoint_spec.rb +224 -0
  40. data/spec/site_inspector_spec.rb +46 -0
  41. data/spec/spec_helper.rb +17 -0
  42. metadata +75 -57
  43. data/lib/site-inspector/compliance.rb +0 -19
  44. data/lib/site-inspector/dns.rb +0 -92
  45. data/lib/site-inspector/headers.rb +0 -59
  46. data/lib/site-inspector/sniffer.rb +0 -26
@@ -0,0 +1,224 @@
1
+ require 'spec_helper'
2
+
3
+ describe SiteInspector::Endpoint do
4
+
5
+ subject { SiteInspector::Endpoint.new("http://example.com") }
6
+
7
+ it "downcases the host" do
8
+ endpoint = SiteInspector::Endpoint.new("http://EXAMPLE.com")
9
+ expect(endpoint.host).to eql("example.com")
10
+ end
11
+
12
+ it "strips www from the host" do
13
+ endpoint = SiteInspector::Endpoint.new("http://www.example.com")
14
+ expect(endpoint.host).to eql("example.com")
15
+ end
16
+
17
+ it "returns the uri" do
18
+ expect(subject.uri.to_s).to eql("http://example.com")
19
+ end
20
+
21
+ it "knows if an endpoint is www" do
22
+ expect(subject.www?).to eql(false)
23
+ expect(subject.root?).to eql(true)
24
+
25
+ endpoint = SiteInspector::Endpoint.new("http://www.example.com")
26
+ expect(endpoint.www?).to eql(true)
27
+ expect(endpoint.root?).to eql(false)
28
+ end
29
+
30
+ it "knows if an endpoint is http" do
31
+ stub_request(:get, "http://example.com/").
32
+ to_return(:status => 200, :body => "content")
33
+
34
+ stub_request(:get, "https://example.com/").
35
+ to_return(:status => 500, :body => "content")
36
+
37
+ expect(subject.https?).to eql(false)
38
+ expect(subject.http?).to eql(true)
39
+ end
40
+
41
+ it "knows if an endpoint is https" do
42
+ stub_request(:get, "http://example.com/").
43
+ to_return(:status => 200, :body => "content")
44
+
45
+ stub_request(:get, "https://example.com/").
46
+ to_return(:status => 200, :body => "content")
47
+
48
+ endpoint = SiteInspector::Endpoint.new("https://example.com")
49
+ expect(endpoint.https?).to eql(true)
50
+ expect(endpoint.http?).to eql(false)
51
+ end
52
+
53
+ it "knows the scheme" do
54
+ expect(subject.scheme).to eql("http")
55
+
56
+ endpoint = SiteInspector::Endpoint.new("https://example.com")
57
+ expect(endpoint.scheme).to eql("https")
58
+ end
59
+
60
+ context "requests" do
61
+
62
+ it "requests a URL" do
63
+ stub = stub_request(:get, "http://example.com/").
64
+ to_return(:status => 200, :body => "content")
65
+
66
+ expect(subject.request.body).to eql("content")
67
+ expect(stub).to have_been_requested
68
+ end
69
+
70
+ it "requests a requested path" do
71
+ stub = stub_request(:get, "http://example.com/foo").
72
+ to_return(:status => 200, :body => "content")
73
+
74
+ expect(subject.request(:path => "foo").body).to eql("content")
75
+ expect(stub).to have_been_requested
76
+ end
77
+
78
+ it "requests with typhoeus options" do
79
+ stub_request(:get, "http://example.com/").
80
+ to_return(:status => 301, :headers => { :location => "http://example.com/foo" } )
81
+
82
+ response = subject.request(:followlocation => true)
83
+ expect(response.request.options[:followlocation]).to eql(true)
84
+ end
85
+
86
+ it "returns the response" do
87
+ stub = stub_request(:get, "http://example.com/").
88
+ to_return(:status => 200, :body => "content")
89
+
90
+ expect(subject.response.body).to eql("content")
91
+ expect(subject.response.body).to eql("content")
92
+ expect(stub).to have_been_requested.once
93
+ end
94
+
95
+ it "knows if there's a response" do
96
+ stub_request(:get, "http://example.com/").
97
+ to_return(:status => 200, :body => "content")
98
+
99
+ expect(subject.response?).to eql(true)
100
+ end
101
+
102
+ it "knows when there's not a response" do
103
+ allow(subject).to receive(:response) { Typhoeus::Response.new(code: 0) }
104
+ expect(subject.response?).to eql(false)
105
+
106
+ allow(subject).to receive(:response) { Typhoeus::Response.new(:return_code => :operation_timedout) }
107
+ expect(subject.response?).to eql(false)
108
+ end
109
+
110
+ it "knows the response code" do
111
+ stub_request(:get, "http://example.com/").
112
+ to_return(:status => 200)
113
+
114
+ expect(subject.response_code).to eql("200")
115
+ end
116
+
117
+ it "knows if a response has timed out" do
118
+ allow(subject).to receive(:response) { Typhoeus::Response.new(:return_code => :operation_timedout) }
119
+ expect(subject.timed_out?).to eql(true)
120
+ end
121
+
122
+ it "considers a 200 response code to be up" do
123
+ stub_request(:get, "http://example.com/").
124
+ to_return(:status => 200)
125
+
126
+ expect(subject.up?).to eql(true)
127
+ expect(subject.down?).to eql(false)
128
+
129
+ end
130
+
131
+ it "considers a 301 response code to be up" do
132
+ stub_request(:get, "http://example.com/").
133
+ to_return(:status => 301)
134
+
135
+ expect(subject.up?).to eql(true)
136
+ expect(subject.down?).to eql(false)
137
+ end
138
+
139
+ it "doesn't consider a 500 response code to be up" do
140
+ stub_request(:get, "http://example.com/").
141
+ to_return(:status => 500)
142
+
143
+ expect(subject.up?).to eql(false)
144
+ expect(subject.down?).to eql(true)
145
+ end
146
+ end
147
+
148
+ context "redirects" do
149
+ it "knows when there's a redirect" do
150
+ stub_request(:get, "http://example.com/").
151
+ to_return(:status => 301, :headers => { :location => "http://www.example.com" } )
152
+
153
+ expect(subject.redirect?).to eql(true)
154
+ end
155
+
156
+ it "returns the redirect" do
157
+ stub_request(:get, "http://example.com/").
158
+ to_return(:status => 301, :headers => { :location => "http://www.example.com" } )
159
+
160
+ stub_request(:get, "http://www.example.com/").
161
+ to_return(:status => 200)
162
+
163
+ expect(subject.redirect.uri.to_s).to eql("http://www.example.com")
164
+ end
165
+
166
+ it "handles relative redirects" do
167
+ stub_request(:get, "http://example.com/").
168
+ to_return(:status => 301, :headers => { :location => "/foo" } )
169
+
170
+ expect(subject.redirect?).to eql(false)
171
+ end
172
+
173
+ it "handles relative redirects without a leading slash" do
174
+ stub_request(:get, "http://example.com/").
175
+ to_return(:status => 301, :headers => { :location => "foo" } )
176
+
177
+ expect(subject.redirect?).to eql(false)
178
+ end
179
+
180
+ it "knows what it resolves to" do
181
+ stub_request(:get, "http://example.com/").
182
+ to_return(:status => 301, :headers => { :location => "http://www.example.com" } )
183
+
184
+ stub_request(:get, "http://www.example.com/").
185
+ to_return(:status => 200)
186
+
187
+ expect(subject.redirect?).to eql(true)
188
+ expect(subject.resolves_to.uri.to_s).to eql("http://www.example.com")
189
+ end
190
+
191
+ it "detects external redirects" do
192
+ stub_request(:get, "http://example.com/").
193
+ to_return(:status => 301, :headers => { :location => "http://www.example.gov" } )
194
+
195
+ expect(subject.redirect?).to eql(true)
196
+ expect(subject.external_redirect?).to eql(true)
197
+ end
198
+
199
+ it "knows internal redirects are not external redirects" do
200
+ stub_request(:get, "http://example.com/").
201
+ to_return(:status => 301, :headers => { :location => "https://example.com" } )
202
+
203
+ expect(subject.external_redirect?).to eql(false)
204
+ end
205
+ end
206
+
207
+ context "checks" do
208
+ it "identifies checks" do
209
+ expect(SiteInspector::Endpoint.checks.count).to eql(6)
210
+ end
211
+
212
+ SiteInspector::Endpoint.checks.each do |check|
213
+ it "responds to the #{check} check" do
214
+
215
+ stub_request(:get, "http://example.com/").
216
+ to_return(:status => 200)
217
+
218
+ expect(subject.send(check.name)).to_not be_nil
219
+ expect(subject.send(check.name).class).to eql(check)
220
+
221
+ end
222
+ end
223
+ end
224
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe SiteInspector do
4
+
5
+ before do
6
+ SiteInspector.instance_variable_set("@cache", nil)
7
+ SiteInspector.instance_variable_set("@timeout", nil)
8
+ end
9
+
10
+ it "defaults to ephemeral cache" do
11
+ with_env "CACHE", nil do
12
+ expect(SiteInspector.cache.class).to be(SiteInspector::Cache)
13
+ end
14
+ end
15
+
16
+ it "uses disk cache when requested" do
17
+ with_env "CACHE", "/tmp" do
18
+ expect(SiteInspector.cache.class).to be(SiteInspector::DiskCache)
19
+ end
20
+ end
21
+
22
+ it "returns the default timeout" do
23
+ expect(SiteInspector.timeout).to eql(10)
24
+ end
25
+
26
+ it "honors custom timeouts" do
27
+ SiteInspector.timeout = 20
28
+ expect(SiteInspector.timeout).to eql(20)
29
+ end
30
+
31
+ it "returns a domain when inspecting" do
32
+ expect(SiteInspector.inspect("example.com").class).to be(SiteInspector::Domain)
33
+ end
34
+
35
+ it "returns the typhoeus defaults" do
36
+ expected = {
37
+ :accept_encoding => "gzip",
38
+ :followlocation => false,
39
+ :timeout => 10,
40
+ :headers => {
41
+ "User-Agent" => "Mozilla/5.0 (compatible; SiteInspector/#{SiteInspector::VERSION}; +https://github.com/benbalter/site-inspector-ruby)"
42
+ }
43
+ }
44
+ expect(SiteInspector.typhoeus_defaults).to eql(expected)
45
+ end
46
+ end
@@ -0,0 +1,17 @@
1
+ require "bundler/setup"
2
+ require 'webmock/rspec'
3
+ require 'fileutils'
4
+ require_relative "../lib/site-inspector"
5
+
6
+ WebMock.disable_net_connect!
7
+
8
+ def with_env(key, value)
9
+ old_env = ENV[key]
10
+ ENV[key] = value
11
+ yield
12
+ ENV[key] = old_env
13
+ end
14
+
15
+ def tmpdir
16
+ File.expand_path "../tmp", File.dirname(__FILE__)
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: site-inspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-01 00:00:00.000000000 Z
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.6'
89
+ version: '0.7'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.6'
96
+ version: '0.7'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: oj
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -109,103 +109,89 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '2.11'
111
111
  - !ruby/object:Gem::Dependency
112
- name: pry
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '0.10'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '0.10'
125
- - !ruby/object:Gem::Dependency
126
- name: rake
112
+ name: mercenary
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - "~>"
130
116
  - !ruby/object:Gem::Version
131
- version: '10.4'
132
- type: :development
117
+ version: '0.3'
118
+ type: :runtime
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
122
  - - "~>"
137
123
  - !ruby/object:Gem::Version
138
- version: '10.4'
124
+ version: '0.3'
139
125
  - !ruby/object:Gem::Dependency
140
- name: shoulda
126
+ name: colorator
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
129
  - - "~>"
144
130
  - !ruby/object:Gem::Version
145
- version: '3.5'
146
- type: :development
131
+ version: '0.1'
132
+ type: :runtime
147
133
  prerelease: false
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
136
  - - "~>"
151
137
  - !ruby/object:Gem::Version
152
- version: '3.5'
138
+ version: '0.1'
153
139
  - !ruby/object:Gem::Dependency
154
- name: rdoc
140
+ name: pry
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
143
  - - "~>"
158
144
  - !ruby/object:Gem::Version
159
- version: '4.1'
145
+ version: '0.10'
160
146
  type: :development
161
147
  prerelease: false
162
148
  version_requirements: !ruby/object:Gem::Requirement
163
149
  requirements:
164
150
  - - "~>"
165
151
  - !ruby/object:Gem::Version
166
- version: '4.1'
152
+ version: '0.10'
167
153
  - !ruby/object:Gem::Dependency
168
- name: bundler
154
+ name: rake
169
155
  requirement: !ruby/object:Gem::Requirement
170
156
  requirements:
171
157
  - - "~>"
172
158
  - !ruby/object:Gem::Version
173
- version: '1.6'
159
+ version: '10.4'
174
160
  type: :development
175
161
  prerelease: false
176
162
  version_requirements: !ruby/object:Gem::Requirement
177
163
  requirements:
178
164
  - - "~>"
179
165
  - !ruby/object:Gem::Version
180
- version: '1.6'
166
+ version: '10.4'
181
167
  - !ruby/object:Gem::Dependency
182
- name: rerun
168
+ name: rspec
183
169
  requirement: !ruby/object:Gem::Requirement
184
170
  requirements:
185
171
  - - "~>"
186
172
  - !ruby/object:Gem::Version
187
- version: '0.10'
173
+ version: '3.2'
188
174
  type: :development
189
175
  prerelease: false
190
176
  version_requirements: !ruby/object:Gem::Requirement
191
177
  requirements:
192
178
  - - "~>"
193
179
  - !ruby/object:Gem::Version
194
- version: '0.10'
180
+ version: '3.2'
195
181
  - !ruby/object:Gem::Dependency
196
- name: vcr
182
+ name: bundler
197
183
  requirement: !ruby/object:Gem::Requirement
198
184
  requirements:
199
185
  - - "~>"
200
186
  - !ruby/object:Gem::Version
201
- version: '2.9'
187
+ version: '1.6'
202
188
  type: :development
203
189
  prerelease: false
204
190
  version_requirements: !ruby/object:Gem::Requirement
205
191
  requirements:
206
192
  - - "~>"
207
193
  - !ruby/object:Gem::Version
208
- version: '2.9'
194
+ version: '1.6'
209
195
  - !ruby/object:Gem::Dependency
210
196
  name: webmock
211
197
  requirement: !ruby/object:Gem::Requirement
@@ -220,20 +206,6 @@ dependencies:
220
206
  - - "~>"
221
207
  - !ruby/object:Gem::Version
222
208
  version: '1.2'
223
- - !ruby/object:Gem::Dependency
224
- name: guard-rake
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - "~>"
228
- - !ruby/object:Gem::Version
229
- version: '1.0'
230
- type: :development
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - "~>"
235
- - !ruby/object:Gem::Version
236
- version: '1.0'
237
209
  description: Returns information about a domain's technology and capabilities
238
210
  email: ben@balter.com
239
211
  executables:
@@ -241,16 +213,49 @@ executables:
241
213
  extensions: []
242
214
  extra_rdoc_files: []
243
215
  files:
216
+ - ".gitignore"
217
+ - ".ruby-version"
218
+ - ".travis.yml"
219
+ - Gemfile
220
+ - Guardfile
244
221
  - LICENSE
222
+ - README.md
223
+ - Rakefile
245
224
  - bin/site-inspector
246
225
  - lib/data/cdn.yml
247
226
  - lib/data/cloud.yml
248
227
  - lib/site-inspector.rb
249
228
  - lib/site-inspector/cache.rb
250
- - lib/site-inspector/compliance.rb
251
- - lib/site-inspector/dns.rb
252
- - lib/site-inspector/headers.rb
253
- - lib/site-inspector/sniffer.rb
229
+ - lib/site-inspector/checks/check.rb
230
+ - lib/site-inspector/checks/content.rb
231
+ - lib/site-inspector/checks/dns.rb
232
+ - lib/site-inspector/checks/headers.rb
233
+ - lib/site-inspector/checks/hsts.rb
234
+ - lib/site-inspector/checks/https.rb
235
+ - lib/site-inspector/checks/sniffer.rb
236
+ - lib/site-inspector/disk_cache.rb
237
+ - lib/site-inspector/domain.rb
238
+ - lib/site-inspector/endpoint.rb
239
+ - lib/site-inspector/rails_cache.rb
240
+ - lib/site-inspector/version.rb
241
+ - script/bootstrap
242
+ - script/cibuild
243
+ - script/console
244
+ - script/release
245
+ - site-inspector.gemspec
246
+ - spec/checks/site_inspector_endpoint_check_spec.rb
247
+ - spec/checks/site_inspector_endpoint_content_spec.rb
248
+ - spec/checks/site_inspector_endpoint_dns_spec.rb
249
+ - spec/checks/site_inspector_endpoint_headers_spec.rb
250
+ - spec/checks/site_inspector_endpoint_hsts_spec.rb
251
+ - spec/checks/site_inspector_endpoint_https_spec.rb
252
+ - spec/checks/site_inspector_endpoint_sniffer_spec.rb
253
+ - spec/site_inspector_cache_spec.rb
254
+ - spec/site_inspector_disc_cache_spec.rb
255
+ - spec/site_inspector_domain_spec.rb
256
+ - spec/site_inspector_endpoint_spec.rb
257
+ - spec/site_inspector_spec.rb
258
+ - spec/spec_helper.rb
254
259
  homepage: https://github.com/benbalter/site-inspector-ruby
255
260
  licenses:
256
261
  - MIT
@@ -275,4 +280,17 @@ rubygems_version: 2.2.2
275
280
  signing_key:
276
281
  specification_version: 4
277
282
  summary: A Ruby port and v2 of Site Inspector (http://github.com/benbalter/site-inspector)
278
- test_files: []
283
+ test_files:
284
+ - spec/checks/site_inspector_endpoint_check_spec.rb
285
+ - spec/checks/site_inspector_endpoint_content_spec.rb
286
+ - spec/checks/site_inspector_endpoint_dns_spec.rb
287
+ - spec/checks/site_inspector_endpoint_headers_spec.rb
288
+ - spec/checks/site_inspector_endpoint_hsts_spec.rb
289
+ - spec/checks/site_inspector_endpoint_https_spec.rb
290
+ - spec/checks/site_inspector_endpoint_sniffer_spec.rb
291
+ - spec/site_inspector_cache_spec.rb
292
+ - spec/site_inspector_disc_cache_spec.rb
293
+ - spec/site_inspector_domain_spec.rb
294
+ - spec/site_inspector_endpoint_spec.rb
295
+ - spec/site_inspector_spec.rb
296
+ - spec/spec_helper.rb