rspec-webservice_matchers 1.4.2 → 1.4.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5e2f461f7c91199840fe5296000e9592ca4f7e3
|
4
|
+
data.tar.gz: 6d62373fefe398e53de5294763fcc9b2ccd612b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a63683fe144143b747a1b78dd57e5761ef38a2a32aba37867808e3388a3aa7efd3739592f85714f6e398d2be0f5e7ffc87e63dbfa28ddf24f68ba18c649168a8
|
7
|
+
data.tar.gz: 9105da66765a264943fa94e2b14bc64a90ab02e8f05201396e62258c0a7510b2546d5f4a0010dcc6d1041f964c5e59e3a93f7db9cfb2ce57037a5810f9447e0f
|
@@ -70,15 +70,41 @@ module RSpec
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
|
73
74
|
# This is a high level matcher which checks three things:
|
74
75
|
# 1. Permanent redirect
|
75
76
|
# 2. to an https url
|
76
77
|
# 3. which is correctly configured
|
77
78
|
RSpec::Matchers.define :enforce_https_everywhere do
|
79
|
+
actual_status = actual_protocol = actual_valid_cert = nil
|
80
|
+
|
78
81
|
match do |domain_name|
|
79
82
|
response = RSpec::WebserviceMatchers.connection.head("http://#{domain_name}")
|
80
83
|
new_url = response.headers['location']
|
81
|
-
|
84
|
+
|
85
|
+
actual_status = response.status
|
86
|
+
if new_url =~ /^(https?)/
|
87
|
+
actual_protocol = $1
|
88
|
+
end
|
89
|
+
actual_valid_cert = RSpec::WebserviceMatchers.has_valid_ssl_cert?(new_url)
|
90
|
+
|
91
|
+
(actual_status == 301) &&
|
92
|
+
(actual_protocol == 'https') &&
|
93
|
+
(actual_valid_cert == true)
|
94
|
+
end
|
95
|
+
|
96
|
+
failure_message_for_should do
|
97
|
+
mesgs = []
|
98
|
+
if actual_status != 301
|
99
|
+
mesgs << "Received status #{actual_status} instead of 301"
|
100
|
+
end
|
101
|
+
if !actual_protocol.nil? && actual_protocol != 'https'
|
102
|
+
mesgs << "Destination uses protocol #{actual_protocol.upcase}"
|
103
|
+
end
|
104
|
+
if ! actual_valid_cert
|
105
|
+
mesgs << "There's no valid SSL certificate"
|
106
|
+
end
|
107
|
+
mesgs.join('; ')
|
82
108
|
end
|
83
109
|
end
|
84
110
|
|
@@ -89,12 +115,11 @@ module RSpec
|
|
89
115
|
actual_code = nil
|
90
116
|
|
91
117
|
match do |url_or_domain_name|
|
92
|
-
url
|
93
|
-
response
|
94
|
-
|
95
|
-
expected
|
96
|
-
actual_code
|
97
|
-
actual == expected
|
118
|
+
url = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
|
119
|
+
response = RSpec::WebserviceMatchers.connection.head(url)
|
120
|
+
actual_code = response.status
|
121
|
+
expected = expected.to_i
|
122
|
+
actual_code == expected
|
98
123
|
end
|
99
124
|
|
100
125
|
failure_message_for_should do
|
@@ -12,10 +12,8 @@ describe 'have_a_valid_cert matcher' do
|
|
12
12
|
|
13
13
|
it 'fails if the server is not serving SSL at all' do
|
14
14
|
expect {
|
15
|
-
# www.psu.edu only supports HTTP, port 80.
|
16
|
-
# TODO: set up a test server for this. (?)
|
17
15
|
expect('www.psu.edu').to have_a_valid_cert
|
18
|
-
}.to
|
16
|
+
}.to fail
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
@@ -25,4 +23,10 @@ describe 'enforce_https_everywhere' do
|
|
25
23
|
it 'passes when http requests are redirected to valid https urls' do
|
26
24
|
expect('eff.org').to enforce_https_everywhere
|
27
25
|
end
|
26
|
+
|
27
|
+
it 'provides a relevant error message' do
|
28
|
+
expect {
|
29
|
+
expect('www.psu.edu').to enforce_https_everywhere
|
30
|
+
}.to fail_matching(/200/)
|
31
|
+
end
|
28
32
|
end
|