rspec-webservice_matchers 0.1.0 → 0.1.1

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: e17330d2e905a3120dc64763b72b809c09ff8d1f
4
- data.tar.gz: 92b596e81ef958fdbeedb9a3d055e86652491a22
3
+ metadata.gz: 7a91cd72d70ca58ac4b471caef6ff810ee90b2b1
4
+ data.tar.gz: fbda72dad2ca7a23c05be9fc90af9fcb98dfe198
5
5
  SHA512:
6
- metadata.gz: 0d28212c35e26776331e5890c7147e15e1bebc0eb6f594980e7d9006bb1a56fbb18b577ae473ebee312c200a669fe810701831ff09c510f345fba18fd11de527
7
- data.tar.gz: ffc8b713dab93ef563264ca49dbdab0f50ad3dcb3a3a6140c6a1a20d27d8b570d0de0ffe8629df44870d1df342c41c77490dde98e2a0792cc6d22a05691c855b
6
+ metadata.gz: 8b846008102ec2520cff3be9481d15dc5862dbdcca59025199dbdb6f7c9a887534858cfb9b6dd3bd32b3b31c7bf6a91ba34df8c19065ed32f93e41bfdc46e42c
7
+ data.tar.gz: f7c089dfbee764e7b96f05cd71e41c03ad97e4ea1ed6dbeb306b57bebc6efb808806a3dcd42111549e7c30725829e5887365f368dacf1a9f17e4114906bf4e1b
@@ -20,26 +20,9 @@ module RSpec
20
20
  end
21
21
  end
22
22
 
23
- # Would this function be helpful?
24
- #
25
- # Return true if the domain serves content via SSL
26
- # without checking certificate validity.
27
- #
28
- # def self.supports_ssl?(domain_name)
29
- # begin
30
- # has_valid_ssl_cert?(domain_name)
31
- # # Cert may not be valid, but content IS
32
- # # being served via https.
33
- # return true
34
- # rescue Curl::Err::ConnectionFailedError
35
- # return false
36
- # end
37
- # end
38
-
39
23
 
40
24
  # RSpec Custom Matchers ###########################################
41
- # See https://www.relishapp.com/rspec/rspec-expectations/v/3-0/docs/custom-matchers/define-matcher
42
-
25
+ # See https://www.relishapp.com/rspec/rspec-expectations/v/2-3/docs/custom-matchers/define-matcher
43
26
 
44
27
  # Test whether https is correctly implemented
45
28
  RSpec::Matchers.define :have_a_valid_cert do
@@ -51,16 +34,9 @@ module RSpec
51
34
  # Pass successfully if we get a 301 to the place we intend.
52
35
  RSpec::Matchers.define :redirect_permanently_to do |expected|
53
36
  match do |url|
54
- # TODO: Refactor this code. Submit as pull request to Curb.
55
- result = Curl::Easy.http_head(url)
56
- header_lines = result.head.split("\r\n")
57
- header_lines.delete_at(0) # The first reponse header is already parsed.
58
- header = {}
59
- header_lines.each do |line|
60
- key, value = line.split(': ')
61
- header[key] = value
62
- end
63
- result.response_code == 301 && header['Location'] == expected
37
+ result = Curl::Easy.http_head(url)
38
+ headers = RSpec::WebserviceMatchers.parse_response_headers(result)
39
+ result.response_code == 301 && headers['Location'] == expected
64
40
  end
65
41
  end
66
42
 
@@ -70,18 +46,29 @@ module RSpec
70
46
  # 3. which is correctly configured
71
47
  RSpec::Matchers.define :enforce_https_everywhere do
72
48
  match do |domain_name|
73
- # TODO: Refactor this code. Submit as pull request to Curb.
74
- result = Curl::Easy.http_head("http://#{domain_name}")
75
- header_lines = result.head.split("\r\n")
76
- header_lines.delete_at(0) # The first reponse header is already parsed.
77
- header = {}
78
- header_lines.each do |line|
79
- key, value = line.split(': ')
80
- header[key] = value
81
- end
82
- (result.response_code == 301) && (/https/ === header['Location']) && (RSpec::WebserviceMatchers.has_valid_ssl_cert?(header['Location']))
49
+ result = Curl::Easy.http_head("http://#{domain_name}")
50
+ headers = RSpec::WebserviceMatchers.parse_response_headers(result)
51
+ new_url = headers['Location']
52
+ (result.response_code == 301) && (/https/ === new_url) && (RSpec::WebserviceMatchers.has_valid_ssl_cert?(new_url))
83
53
  end
84
- end
54
+ end
55
+
56
+
57
+ private
58
+
59
+ # Return a hash of response headers from the
60
+ # given curl result.
61
+ # TODO: Submit as a pull request to the Curb gem.
62
+ def self.parse_response_headers(curl_result)
63
+ header_lines = curl_result.head.split("\r\n")
64
+ header_lines.delete_at(0) # The first reponse header is in another format and already parsed.
65
+ response_headers = {}
66
+ header_lines.each do |line|
67
+ key, value = line.split(': ')
68
+ response_headers[key] = value
69
+ end
70
+ return response_headers
71
+ end
85
72
 
86
73
  end
87
74
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module WebserviceMatchers
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-webservice_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter