rspec-webservice_matchers 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9f1f32a80f4f1fd30f9e7ae4d6242cf4243535f
4
- data.tar.gz: bf308f90fd8b6f110a4678f0f5bc45a9cb6114bf
3
+ metadata.gz: 3aca3e244bcc6fba59a64f758e107b9999b4a42a
4
+ data.tar.gz: c6168cb912525614671e2538edc946c0be787447
5
5
  SHA512:
6
- metadata.gz: 0498468205c9dd6e29278c6364c5e9ae240b1e40b18e2507260fb9a1cc332936bfe5db7a3a537bc992cc9d533a905c0da36e81c7fc088e64c5b04b645b8eeeca
7
- data.tar.gz: 2d02fae806afedd97717468d530cdd0861b3f92cf81aa682a07d4dd368a18223bd0dd53b83da4656293556489d8a3d077caf6dc24c82cdddc79ab07d54cc42d2
6
+ metadata.gz: 3d56795b8f888bf11c74e2cbc79904b0bad918e5ea99d23f8f178d86dfe3d517bf52110dfe4e0681bea82ebd496ddc8f178eb7560956911baa25753d5ae0eeb9
7
+ data.tar.gz: 813f7c6dbf6bd14837135163517b2233ee559dcf1516064e92f47da139f565978107620d09705ae4600735d6ee22bddb1194d5ac7cf9c4088ffedd6af558d49f
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0.0"
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # RSpec::WebserviceMatchers
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/rspec-webservice_matchers.png)](http://badge.fury.io/rb/rspec-webservice_matchers) [![Build Status](https://travis-ci.org/dogweather/rspec-webservice_matchers.png?branch=master)](https://travis-ci.org/dogweather/rspec-webservice_matchers)
4
+
3
5
  This [gem](https://rubygems.org/gems/rspec-webservice_matchers) enables you to black-box test a web app's server configuration. For example, whether its SSL certificate is correctly configured and not expired. It's a tool for doing **Test Driven Devops**. (I just made that up.)
4
6
 
5
7
  This library takes a very minimalist approach: it simply adds new RSpec matchers,
@@ -19,15 +21,17 @@ These new RSpec matchers:
19
21
  -------------------------------|------------------------------------------------
20
22
  **be_status** |
21
23
  **be_up** | Follows redirects if necessary and checks for 200
22
- **have_a_valid_cert** | Uses [lib-curl](http://curl.haxx.se/libcurl/) via [Curb](https://github.com/taf2/curb) to test validity
24
+ **have_a_valid_cert** |
23
25
  **enforce_https_everywhere** | See the [EFF project](https://www.eff.org/https-everywhere)
24
- **redirect_permanently_to** | Allows 301
25
- **redirect_temporarily_to** | Allows 302 or 307
26
+ **redirect_permanently_to** | Checks for 301
27
+ **redirect_temporarily_to** | Checks for 302 or 307
26
28
 
27
29
 
28
30
  Example
29
31
  -------
30
32
 
33
+ Here's an example which uses them all:
34
+
31
35
  ```Ruby
32
36
  require 'rspec/webservice_matchers'
33
37
 
@@ -37,11 +41,11 @@ describe 'My app' do
37
41
  it { should have_a_valid_cert }
38
42
  end
39
43
 
40
- it 'serves the about page without redirects' do
44
+ it 'serves the "about" page without redirecting' do
41
45
  expect('http://www.myapp.com/about').to be_status 200
42
46
  end
43
47
 
44
- it 'redirects to www' do
48
+ it 'only serves via www' do
45
49
  expect('http://myapp.com').to redirect_permanently_to 'http://www.myapp.com/'
46
50
  end
47
51
 
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ task :default => :spec
@@ -1,5 +1,7 @@
1
1
  require 'rspec/webservice_matchers/version'
2
- require 'curb'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+ require 'pry'
3
5
 
4
6
  module RSpec
5
7
  module WebserviceMatchers
@@ -12,9 +14,10 @@ module RSpec
12
14
 
13
15
  # Test by seeing if Curl retrieves without complaining
14
16
  begin
15
- Curl::Easy.http_head "https://#{domain_name_or_url}"
17
+ conn = Faraday.new(:url => "https://#{domain_name_or_url}")
18
+ response = conn.head
16
19
  return true
17
- rescue Curl::Err::ConnectionFailedError, Curl::Err::SSLCACertificateError, Curl::Err::SSLPeerCertificateError
20
+ rescue
18
21
  # Not serving SSL, expired, or incorrect domain name in certificate
19
22
  return false
20
23
  end
@@ -34,18 +37,18 @@ module RSpec
34
37
  # Pass successfully if we get a 301 to the place we intend.
35
38
  RSpec::Matchers.define :redirect_permanently_to do |expected|
36
39
  match do |url|
37
- result = Curl::Easy.http_head(url)
38
- headers = RSpec::WebserviceMatchers.parse_response_headers(result)
39
- result.response_code == 301 && headers['Location'] == expected
40
+ conn = Faraday.new(:url => url)
41
+ response = conn.head
42
+ response.status == 301 && response.headers['Location'] == expected
40
43
  end
41
44
  end
42
45
 
43
46
  # Pass successfully if we get a 302 or 307 to the place we intend.
44
47
  RSpec::Matchers.define :redirect_temporarily_to do |expected|
45
48
  match do |url|
46
- result = Curl::Easy.http_head(url)
47
- headers = RSpec::WebserviceMatchers.parse_response_headers(result)
48
- [302, 307].include?(result.response_code) && headers['Location'] == expected
49
+ conn = Faraday.new(:url => url)
50
+ response = conn.head
51
+ [302, 307].include?(response.status) && response.headers['Location'] == expected
49
52
  end
50
53
  end
51
54
 
@@ -55,10 +58,10 @@ module RSpec
55
58
  # 3. which is correctly configured
56
59
  RSpec::Matchers.define :enforce_https_everywhere do
57
60
  match do |domain_name|
58
- result = Curl::Easy.http_head("http://#{domain_name}")
59
- headers = RSpec::WebserviceMatchers.parse_response_headers(result)
60
- new_url = headers['Location']
61
- (result.response_code == 301) && (/https/ === new_url) && (RSpec::WebserviceMatchers.has_valid_ssl_cert?(new_url))
61
+ conn = Faraday.new(:url => "http://#{domain_name}")
62
+ response = conn.head
63
+ new_url = response.headers['Location']
64
+ (response.status == 301) && (/https/ === new_url) && (RSpec::WebserviceMatchers.has_valid_ssl_cert?(new_url))
62
65
  end
63
66
  end
64
67
 
@@ -66,17 +69,24 @@ module RSpec
66
69
  # Codes are defined in http://www.rfc-editor.org/rfc/rfc2616.txt
67
70
  RSpec::Matchers.define :be_status do |expected|
68
71
  match do |url_or_domain_name|
69
- url = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
70
- result = Curl::Easy.http_head(url)
71
- (result.response_code == expected.to_i)
72
+ url = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
73
+ conn = Faraday.new(:url => url)
74
+ response = conn.head
75
+ response.status == expected
72
76
  end
73
77
  end
74
78
 
79
+ #Pass when the response code is 200, following redirects
80
+ #if necessary.
75
81
  RSpec::Matchers.define :be_up do
76
82
  match do |url_or_domain_name|
77
- url = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
78
- result = Curl::Easy.http_head(url) { |curl| curl.follow_location = true }
79
- (result.response_code == 200)
83
+ url = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
84
+ conn = Faraday.new(url) do |c|
85
+ c.use FaradayMiddleware::FollowRedirects, limit: 5
86
+ c.adapter :net_http
87
+ end
88
+ response = conn.head
89
+ response.status == 200
80
90
  end
81
91
  end
82
92
 
@@ -93,20 +103,5 @@ module RSpec
93
103
  end
94
104
  end
95
105
 
96
-
97
- # Return a hash of response headers from the
98
- # given curl result.
99
- # TODO: Submit as a pull request to the Curb gem.
100
- def self.parse_response_headers(curl_result)
101
- header_lines = curl_result.head.split("\r\n")
102
- header_lines.delete_at(0) # The first reponse header is in another format and already parsed.
103
- response_headers = {}
104
- header_lines.each do |line|
105
- key, value = line.split(': ')
106
- response_headers[key] = value
107
- end
108
- return response_headers
109
- end
110
-
111
106
  end
112
107
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module WebserviceMatchers
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
@@ -20,7 +20,9 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
23
24
 
24
- spec.add_runtime_dependency 'curb', '~> 0.8'
25
25
  spec.add_runtime_dependency 'rspec', '~> 2'
26
+ spec.add_runtime_dependency 'faraday'
27
+ spec.add_runtime_dependency 'faraday_middleware'
26
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-webservice_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-19 00:00:00.000000000 Z
11
+ date: 2014-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: curb
42
+ name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0.8'
48
- type: :runtime
47
+ version: '0'
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0.8'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday_middleware
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description: Black-box web app configuration testing
70
98
  email:
71
99
  - robb@weblaws.org
@@ -74,6 +102,7 @@ extensions: []
74
102
  extra_rdoc_files: []
75
103
  files:
76
104
  - ".gitignore"
105
+ - ".travis.yml"
77
106
  - Gemfile
78
107
  - LICENSE.txt
79
108
  - README.md