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 +4 -4
- data/lib/rspec/webservice_matchers.rb +26 -39
- data/lib/rspec/webservice_matchers/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a91cd72d70ca58ac4b471caef6ff810ee90b2b1
|
4
|
+
data.tar.gz: fbda72dad2ca7a23c05be9fc90af9fcb98dfe198
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|