rspec-webservice_matchers 1.4.2 → 1.4.3

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: 5d0db24cd17e0dc1da5656291cf823dc6edd8823
4
- data.tar.gz: 88cb9edbd5986e4ad036cec34445a8c4a150a9b0
3
+ metadata.gz: e5e2f461f7c91199840fe5296000e9592ca4f7e3
4
+ data.tar.gz: 6d62373fefe398e53de5294763fcc9b2ccd612b4
5
5
  SHA512:
6
- metadata.gz: 687ea5c0d7d5bc1197c327ade4d7f5fc0daa7d586950ace47b0326dda17c63cd95e1e40e076ae4fa8fdf83a4b60ec3e071b9b325e0f6781dfb989a04c7c0b739
7
- data.tar.gz: 920efc3653699436d52518840eb4a83597463c54194a803265b9f84ffd1502567763a81fa552b9169f713194bbe0acc8d0b165530f4d25311ddb1b81fdaef384
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
- (response.status == 301) && (/https/ === new_url) && (RSpec::WebserviceMatchers.has_valid_ssl_cert?(new_url))
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 = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
93
- response = RSpec::WebserviceMatchers.connection.head(url)
94
- actual = response.status
95
- expected = expected.to_i
96
- actual_code = actual
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
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module WebserviceMatchers
3
- VERSION = "1.4.2"
3
+ VERSION = "1.4.3"
4
4
  end
5
5
  end
@@ -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 raise_error(RSpec::Expectations::ExpectationNotMetError)
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
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: 1.4.2
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter