rspec-webservice_matchers 0.0.5 → 0.1.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e17330d2e905a3120dc64763b72b809c09ff8d1f
|
4
|
+
data.tar.gz: 92b596e81ef958fdbeedb9a3d055e86652491a22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d28212c35e26776331e5890c7147e15e1bebc0eb6f594980e7d9006bb1a56fbb18b577ae473ebee312c200a669fe810701831ff09c510f345fba18fd11de527
|
7
|
+
data.tar.gz: ffc8b713dab93ef563264ca49dbdab0f50ad3dcb3a3a6140c6a1a20d27d8b570d0de0ffe8629df44870d1df342c41c77490dde98e2a0792cc6d22a05691c855b
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# RSpec::WebserviceMatchers
|
2
2
|
|
3
|
-
This gem 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.)
|
3
|
+
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
4
|
|
5
5
|
Installation
|
6
6
|
------------
|
@@ -4,18 +4,23 @@ require 'curb'
|
|
4
4
|
module RSpec
|
5
5
|
module WebserviceMatchers
|
6
6
|
|
7
|
-
def self.has_valid_ssl_cert?(
|
7
|
+
def self.has_valid_ssl_cert?(domain_name_or_url)
|
8
|
+
# Normalize the input: remove 'http(s)://' if it's there
|
9
|
+
if %r|^https?://(.+)$| === domain_name_or_url
|
10
|
+
domain_name_or_url = $1
|
11
|
+
end
|
12
|
+
|
13
|
+
# Test by seeing if Curl retrieves without complaining
|
8
14
|
begin
|
9
|
-
Curl.
|
15
|
+
Curl::Easy.http_head "https://#{domain_name_or_url}"
|
10
16
|
return true
|
11
17
|
rescue Curl::Err::ConnectionFailedError, Curl::Err::SSLCACertificateError, Curl::Err::SSLPeerCertificateError
|
12
|
-
# Not serving SSL, expired, or incorrect domain name
|
18
|
+
# Not serving SSL, expired, or incorrect domain name in certificate
|
13
19
|
return false
|
14
20
|
end
|
15
21
|
end
|
16
22
|
|
17
23
|
# Would this function be helpful?
|
18
|
-
|
19
24
|
#
|
20
25
|
# Return true if the domain serves content via SSL
|
21
26
|
# without checking certificate validity.
|
@@ -36,12 +41,14 @@ module RSpec
|
|
36
41
|
# See https://www.relishapp.com/rspec/rspec-expectations/v/3-0/docs/custom-matchers/define-matcher
|
37
42
|
|
38
43
|
|
44
|
+
# Test whether https is correctly implemented
|
39
45
|
RSpec::Matchers.define :have_a_valid_cert do
|
40
|
-
match do |
|
41
|
-
RSpec::WebserviceMatchers.has_valid_ssl_cert?(
|
46
|
+
match do |domain_name_or_url|
|
47
|
+
RSpec::WebserviceMatchers.has_valid_ssl_cert?(domain_name_or_url)
|
42
48
|
end
|
43
49
|
end
|
44
50
|
|
51
|
+
# Pass successfully if we get a 301 to the place we intend.
|
45
52
|
RSpec::Matchers.define :redirect_permanently_to do |expected|
|
46
53
|
match do |url|
|
47
54
|
# TODO: Refactor this code. Submit as pull request to Curb.
|
@@ -57,6 +64,10 @@ module RSpec
|
|
57
64
|
end
|
58
65
|
end
|
59
66
|
|
67
|
+
# This is a high level matcher which checks three things:
|
68
|
+
# 1. Permanent redirect
|
69
|
+
# 2. to an https url
|
70
|
+
# 3. which is correctly configured
|
60
71
|
RSpec::Matchers.define :enforce_https_everywhere do
|
61
72
|
match do |domain_name|
|
62
73
|
# TODO: Refactor this code. Submit as pull request to Curb.
|
@@ -68,7 +79,7 @@ module RSpec
|
|
68
79
|
key, value = line.split(': ')
|
69
80
|
header[key] = value
|
70
81
|
end
|
71
|
-
(result.response_code == 301) && (/https/ === header['Location'])
|
82
|
+
(result.response_code == 301) && (/https/ === header['Location']) && (RSpec::WebserviceMatchers.has_valid_ssl_cert?(header['Location']))
|
72
83
|
end
|
73
84
|
end
|
74
85
|
|
@@ -7,9 +7,3 @@ describe 'redirect_permanently_to' do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
# See https://www.eff.org/https-everywhere
|
11
|
-
describe 'enforce_https_everywhere' do
|
12
|
-
it 'passes when http requests are redirected to https urls' do
|
13
|
-
expect('eff.org').to enforce_https_everywhere
|
14
|
-
end
|
15
|
-
end
|
@@ -14,4 +14,12 @@ describe 'have_a_valid_cert matcher' do
|
|
14
14
|
expect('www.psu.edu').to have_a_valid_cert
|
15
15
|
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
# See https://www.eff.org/https-everywhere
|
21
|
+
describe 'enforce_https_everywhere' do
|
22
|
+
it 'passes when http requests are redirected to valid https urls' do
|
23
|
+
expect('eff.org').to enforce_https_everywhere
|
24
|
+
end
|
25
|
+
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: 0.0
|
4
|
+
version: 0.1.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-01-
|
11
|
+
date: 2014-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|