rspec-webservice_matchers 1.1.2 → 1.2.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 +4 -4
- data/README.md +1 -1
- data/lib/rspec/webservice_matchers.rb +26 -12
- data/lib/rspec/webservice_matchers/version.rb +1 -1
- data/rspec-webservice_matchers.gemspec +1 -0
- data/spec/rspec/webservice_matchers/protcol_spec.rb +12 -3
- data/spec/rspec/webservice_matchers/redirect_spec.rb +1 -0
- data/spec/rspec/webservice_matchers/ssl_spec.rb +5 -2
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c61a14a2ef20872e409fb4d49f0009e987abdd4b
|
4
|
+
data.tar.gz: ed10304376894e7cdfcd83fee505791c931a12ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66899e9f493857af03f4d40f032b6b8094c6e19ab1a2b8ff1f4062854939fcc0c72b0cd4cddff90c06f5bd8c1f54ec44da3c3d4278e05be98c83e6815d767d12
|
7
|
+
data.tar.gz: 14dadfd238f5f4e4c46571a96f9896b07f29f8aa2b49ff905f8fcc147d88eb5a40b5002f0afb574eb90b8d8a6c02fdc774e114592667212f9b5eea26f01c63b7
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/rspec-webservice_matchers) [](https://travis-ci.org/dogweather/rspec-webservice_matchers)
|
4
4
|
|
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.)
|
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.) See [my blog post](http://robb.weblaws.org/2014/01/16/new-open-source-library-for-test-driven-devops/) for more about my motivations for making this.
|
6
6
|
|
7
7
|
This library takes a very minimalist approach: it simply adds new RSpec matchers,
|
8
8
|
and so you can use your own RSpec writing style; there's no new DSL to learn.
|
@@ -3,6 +3,11 @@ require 'faraday'
|
|
3
3
|
require 'faraday_middleware'
|
4
4
|
require 'pry'
|
5
5
|
|
6
|
+
# Seconds
|
7
|
+
TIMEOUT = 5
|
8
|
+
OPEN_TIMEOUT = 2
|
9
|
+
|
10
|
+
|
6
11
|
module RSpec
|
7
12
|
module WebserviceMatchers
|
8
13
|
|
@@ -14,8 +19,7 @@ module RSpec
|
|
14
19
|
|
15
20
|
# Test by seeing if Curl retrieves without complaining
|
16
21
|
begin
|
17
|
-
|
18
|
-
response = conn.head("https://#{domain_name_or_url}")
|
22
|
+
connection.head("https://#{domain_name_or_url}")
|
19
23
|
return true
|
20
24
|
rescue
|
21
25
|
# Not serving SSL, expired, or incorrect domain name in certificate
|
@@ -37,19 +41,19 @@ module RSpec
|
|
37
41
|
# Pass successfully if we get a 301 to the place we intend.
|
38
42
|
RSpec::Matchers.define :redirect_permanently_to do |expected|
|
39
43
|
match do |url|
|
40
|
-
response =
|
44
|
+
response = RSpec::WebserviceMatchers.connection.head(url)
|
41
45
|
# binding.pry
|
42
46
|
response.status == 301 && response.headers['location'] == expected
|
43
47
|
end
|
44
|
-
end
|
48
|
+
end
|
45
49
|
|
46
50
|
# Pass successfully if we get a 302 or 307 to the place we intend.
|
47
51
|
RSpec::Matchers.define :redirect_temporarily_to do |expected|
|
48
52
|
match do |url|
|
49
|
-
response =
|
53
|
+
response = RSpec::WebserviceMatchers.connection.head(url)
|
50
54
|
[302, 307].include?(response.status) && response.headers['location'] == expected
|
51
55
|
end
|
52
|
-
end
|
56
|
+
end
|
53
57
|
|
54
58
|
# This is a high level matcher which checks three things:
|
55
59
|
# 1. Permanent redirect
|
@@ -57,28 +61,30 @@ module RSpec
|
|
57
61
|
# 3. which is correctly configured
|
58
62
|
RSpec::Matchers.define :enforce_https_everywhere do
|
59
63
|
match do |domain_name|
|
60
|
-
response =
|
64
|
+
response = RSpec::WebserviceMatchers.connection.head("http://#{domain_name}")
|
61
65
|
new_url = response.headers['location']
|
62
66
|
(response.status == 301) && (/https/ === new_url) && (RSpec::WebserviceMatchers.has_valid_ssl_cert?(new_url))
|
63
67
|
end
|
64
|
-
end
|
68
|
+
end
|
65
69
|
|
66
70
|
# Pass when a URL returns the expected status code
|
67
71
|
# Codes are defined in http://www.rfc-editor.org/rfc/rfc2616.txt
|
68
72
|
RSpec::Matchers.define :be_status do |expected|
|
69
73
|
match do |url_or_domain_name|
|
70
74
|
url = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
|
71
|
-
response =
|
75
|
+
response = RSpec::WebserviceMatchers.connection.head(url)
|
72
76
|
response.status == expected
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
76
|
-
#Pass when the response code is 200, following redirects
|
77
|
-
#if necessary.
|
80
|
+
# Pass when the response code is 200, following redirects
|
81
|
+
# if necessary.
|
78
82
|
RSpec::Matchers.define :be_up do
|
79
|
-
match do |url_or_domain_name|
|
83
|
+
match do |url_or_domain_name|
|
80
84
|
url = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
|
81
85
|
conn = Faraday.new do |c|
|
86
|
+
c.options[:timeout] = TIMEOUT
|
87
|
+
c.options[:open_timeout] = TIMEOUT
|
82
88
|
c.use FaradayMiddleware::FollowRedirects, limit: 5
|
83
89
|
c.adapter :net_http
|
84
90
|
end
|
@@ -90,6 +96,14 @@ module RSpec
|
|
90
96
|
|
91
97
|
private
|
92
98
|
|
99
|
+
def self.connection
|
100
|
+
Faraday.new do |c|
|
101
|
+
c.options[:timeout] = TIMEOUT
|
102
|
+
c.options[:open_timeout] = TIMEOUT
|
103
|
+
c.adapter :net_http
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
93
107
|
# Ensure that the given string is a URL,
|
94
108
|
# making it into one if necessary.
|
95
109
|
def self.make_url(url_or_domain_name)
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "pry"
|
24
|
+
spec.add_development_dependency 'webmock'
|
24
25
|
|
25
26
|
spec.add_runtime_dependency 'rspec', '~> 2'
|
26
27
|
spec.add_runtime_dependency 'faraday'
|
@@ -1,15 +1,24 @@
|
|
1
|
+
require 'webmock/rspec'
|
1
2
|
require 'rspec/webservice_matchers'
|
2
3
|
|
3
4
|
#
|
4
|
-
# TODO: set up
|
5
|
+
# TODO: set up mocks or VCR for the rest of these.
|
6
|
+
# SEE: http://www.slideshare.net/kjbuckley/testing-http-calls-with-webmock-and-vcr
|
5
7
|
#
|
8
|
+
|
9
|
+
WebMock.stub_request :any, 'http://www.website.com/a/page.txt'
|
10
|
+
WebMock.stub_request :any, 'http://www.website.com/'
|
11
|
+
|
12
|
+
WebMock.allow_net_connect!
|
13
|
+
|
14
|
+
|
6
15
|
describe 'status_code' do
|
7
16
|
it 'can check 200 for successful resource requests' do
|
8
|
-
'http://www.
|
17
|
+
'http://www.website.com/a/page.txt'.should be_status 200
|
9
18
|
end
|
10
19
|
|
11
20
|
it 'handles domain names as well as URLs' do
|
12
|
-
'www.
|
21
|
+
'www.website.com'.should be_status 200
|
13
22
|
end
|
14
23
|
|
15
24
|
it 'can check 503 for the Service Unavailable status' do
|
@@ -4,6 +4,7 @@ require 'rspec/webservice_matchers'
|
|
4
4
|
# TODO: Set up a server for these. (Or a mock?)
|
5
5
|
# Faraday supports testing: we can use that now.
|
6
6
|
#
|
7
|
+
|
7
8
|
describe 'redirect_permanently_to' do
|
8
9
|
it 'passes when receiving a 301 to the given URL' do
|
9
10
|
expect('http://weblaws.org').to redirect_permanently_to('http://www.weblaws.org/')
|
@@ -1,16 +1,19 @@
|
|
1
1
|
require 'rspec/webservice_matchers'
|
2
2
|
|
3
|
+
# VCR may be the tool to use for this. Can it handle https? Would that work?
|
4
|
+
|
5
|
+
|
3
6
|
describe 'have_a_valid_cert matcher' do
|
4
7
|
it 'passes when SSL is properly configured' do
|
5
8
|
# EFF created the HTTPS Everywhere movement
|
6
|
-
# TODO: set up a test server for this.
|
9
|
+
# TODO: set up a test server for this. (?)
|
7
10
|
expect('www.eff.org').to have_a_valid_cert
|
8
11
|
end
|
9
12
|
|
10
13
|
it 'fails if the server is not serving SSL at all' do
|
11
14
|
expect {
|
12
15
|
# www.psu.edu only supports HTTP, port 80.
|
13
|
-
# TODO: set up a test server for this.
|
16
|
+
# TODO: set up a test server for this. (?)
|
14
17
|
expect('www.psu.edu').to have_a_valid_cert
|
15
18
|
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
16
19
|
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.
|
4
|
+
version: 1.2.0
|
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-
|
11
|
+
date: 2014-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|