rspec-webservice_matchers 0.0.5 → 0.1.0

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: f523d14031fccb0830c1107be6e032769ec6a9ca
4
- data.tar.gz: 002708e606a501f751ef4b431121e9dc88956f67
3
+ metadata.gz: e17330d2e905a3120dc64763b72b809c09ff8d1f
4
+ data.tar.gz: 92b596e81ef958fdbeedb9a3d055e86652491a22
5
5
  SHA512:
6
- metadata.gz: 492a5913d17beb16d18384dc782d945eb073c485b8e5fd3e5d35c5f47f012c8553c8de2e0fc30a2a5c2ce52323fbeb190acedc64783a1f16b02ade18feaca7bb
7
- data.tar.gz: a08db1c519eea652b3d85082133d0103783d2ad844a0b65415b0457348725253835c12817e4c2787c03eb6facf8c0df19f47c22146d8149989facd3c75533f03
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
  ------------
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module WebserviceMatchers
3
- VERSION = "0.0.5"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -4,18 +4,23 @@ require 'curb'
4
4
  module RSpec
5
5
  module WebserviceMatchers
6
6
 
7
- def self.has_valid_ssl_cert?(domain_name)
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.get "https://#{domain_name}" # Faster than Curl.head; not sure why.
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 |domain_name|
41
- RSpec::WebserviceMatchers.has_valid_ssl_cert?(domain_name)
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.5
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-16 00:00:00.000000000 Z
11
+ date: 2014-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler