rspec-webservice_matchers 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/README.md +9 -5
- data/Rakefile +6 -0
- data/lib/rspec/webservice_matchers.rb +29 -34
- data/lib/rspec/webservice_matchers/version.rb +1 -1
- data/rspec-webservice_matchers.gemspec +3 -1
- metadata +37 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3aca3e244bcc6fba59a64f758e107b9999b4a42a
|
4
|
+
data.tar.gz: c6168cb912525614671e2538edc946c0be787447
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d56795b8f888bf11c74e2cbc79904b0bad918e5ea99d23f8f178d86dfe3d517bf52110dfe4e0681bea82ebd496ddc8f178eb7560956911baa25753d5ae0eeb9
|
7
|
+
data.tar.gz: 813f7c6dbf6bd14837135163517b2233ee559dcf1516064e92f47da139f565978107620d09705ae4600735d6ee22bddb1194d5ac7cf9c4088ffedd6af558d49f
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# RSpec::WebserviceMatchers
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rspec-webservice_matchers.png)](http://badge.fury.io/rb/rspec-webservice_matchers) [![Build Status](https://travis-ci.org/dogweather/rspec-webservice_matchers.png?branch=master)](https://travis-ci.org/dogweather/rspec-webservice_matchers)
|
4
|
+
|
3
5
|
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
6
|
|
5
7
|
This library takes a very minimalist approach: it simply adds new RSpec matchers,
|
@@ -19,15 +21,17 @@ These new RSpec matchers:
|
|
19
21
|
-------------------------------|------------------------------------------------
|
20
22
|
**be_status** |
|
21
23
|
**be_up** | Follows redirects if necessary and checks for 200
|
22
|
-
**have_a_valid_cert** |
|
24
|
+
**have_a_valid_cert** |
|
23
25
|
**enforce_https_everywhere** | See the [EFF project](https://www.eff.org/https-everywhere)
|
24
|
-
**redirect_permanently_to** |
|
25
|
-
**redirect_temporarily_to** |
|
26
|
+
**redirect_permanently_to** | Checks for 301
|
27
|
+
**redirect_temporarily_to** | Checks for 302 or 307
|
26
28
|
|
27
29
|
|
28
30
|
Example
|
29
31
|
-------
|
30
32
|
|
33
|
+
Here's an example which uses them all:
|
34
|
+
|
31
35
|
```Ruby
|
32
36
|
require 'rspec/webservice_matchers'
|
33
37
|
|
@@ -37,11 +41,11 @@ describe 'My app' do
|
|
37
41
|
it { should have_a_valid_cert }
|
38
42
|
end
|
39
43
|
|
40
|
-
it 'serves the about page without
|
44
|
+
it 'serves the "about" page without redirecting' do
|
41
45
|
expect('http://www.myapp.com/about').to be_status 200
|
42
46
|
end
|
43
47
|
|
44
|
-
it '
|
48
|
+
it 'only serves via www' do
|
45
49
|
expect('http://myapp.com').to redirect_permanently_to 'http://www.myapp.com/'
|
46
50
|
end
|
47
51
|
|
data/Rakefile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'rspec/webservice_matchers/version'
|
2
|
-
require '
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday_middleware'
|
4
|
+
require 'pry'
|
3
5
|
|
4
6
|
module RSpec
|
5
7
|
module WebserviceMatchers
|
@@ -12,9 +14,10 @@ module RSpec
|
|
12
14
|
|
13
15
|
# Test by seeing if Curl retrieves without complaining
|
14
16
|
begin
|
15
|
-
|
17
|
+
conn = Faraday.new(:url => "https://#{domain_name_or_url}")
|
18
|
+
response = conn.head
|
16
19
|
return true
|
17
|
-
rescue
|
20
|
+
rescue
|
18
21
|
# Not serving SSL, expired, or incorrect domain name in certificate
|
19
22
|
return false
|
20
23
|
end
|
@@ -34,18 +37,18 @@ module RSpec
|
|
34
37
|
# Pass successfully if we get a 301 to the place we intend.
|
35
38
|
RSpec::Matchers.define :redirect_permanently_to do |expected|
|
36
39
|
match do |url|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
conn = Faraday.new(:url => url)
|
41
|
+
response = conn.head
|
42
|
+
response.status == 301 && response.headers['Location'] == expected
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
43
46
|
# Pass successfully if we get a 302 or 307 to the place we intend.
|
44
47
|
RSpec::Matchers.define :redirect_temporarily_to do |expected|
|
45
48
|
match do |url|
|
46
|
-
|
47
|
-
|
48
|
-
[302, 307].include?(
|
49
|
+
conn = Faraday.new(:url => url)
|
50
|
+
response = conn.head
|
51
|
+
[302, 307].include?(response.status) && response.headers['Location'] == expected
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
@@ -55,10 +58,10 @@ module RSpec
|
|
55
58
|
# 3. which is correctly configured
|
56
59
|
RSpec::Matchers.define :enforce_https_everywhere do
|
57
60
|
match do |domain_name|
|
58
|
-
|
59
|
-
|
60
|
-
new_url
|
61
|
-
(
|
61
|
+
conn = Faraday.new(:url => "http://#{domain_name}")
|
62
|
+
response = conn.head
|
63
|
+
new_url = response.headers['Location']
|
64
|
+
(response.status == 301) && (/https/ === new_url) && (RSpec::WebserviceMatchers.has_valid_ssl_cert?(new_url))
|
62
65
|
end
|
63
66
|
end
|
64
67
|
|
@@ -66,17 +69,24 @@ module RSpec
|
|
66
69
|
# Codes are defined in http://www.rfc-editor.org/rfc/rfc2616.txt
|
67
70
|
RSpec::Matchers.define :be_status do |expected|
|
68
71
|
match do |url_or_domain_name|
|
69
|
-
url
|
70
|
-
|
71
|
-
|
72
|
+
url = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
|
73
|
+
conn = Faraday.new(:url => url)
|
74
|
+
response = conn.head
|
75
|
+
response.status == expected
|
72
76
|
end
|
73
77
|
end
|
74
78
|
|
79
|
+
#Pass when the response code is 200, following redirects
|
80
|
+
#if necessary.
|
75
81
|
RSpec::Matchers.define :be_up do
|
76
82
|
match do |url_or_domain_name|
|
77
|
-
url
|
78
|
-
|
79
|
-
|
83
|
+
url = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
|
84
|
+
conn = Faraday.new(url) do |c|
|
85
|
+
c.use FaradayMiddleware::FollowRedirects, limit: 5
|
86
|
+
c.adapter :net_http
|
87
|
+
end
|
88
|
+
response = conn.head
|
89
|
+
response.status == 200
|
80
90
|
end
|
81
91
|
end
|
82
92
|
|
@@ -93,20 +103,5 @@ module RSpec
|
|
93
103
|
end
|
94
104
|
end
|
95
105
|
|
96
|
-
|
97
|
-
# Return a hash of response headers from the
|
98
|
-
# given curl result.
|
99
|
-
# TODO: Submit as a pull request to the Curb gem.
|
100
|
-
def self.parse_response_headers(curl_result)
|
101
|
-
header_lines = curl_result.head.split("\r\n")
|
102
|
-
header_lines.delete_at(0) # The first reponse header is in another format and already parsed.
|
103
|
-
response_headers = {}
|
104
|
-
header_lines.each do |line|
|
105
|
-
key, value = line.split(': ')
|
106
|
-
response_headers[key] = value
|
107
|
-
end
|
108
|
-
return response_headers
|
109
|
-
end
|
110
|
-
|
111
106
|
end
|
112
107
|
end
|
@@ -20,7 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "pry"
|
23
24
|
|
24
|
-
spec.add_runtime_dependency 'curb', '~> 0.8'
|
25
25
|
spec.add_runtime_dependency 'rspec', '~> 2'
|
26
|
+
spec.add_runtime_dependency 'faraday'
|
27
|
+
spec.add_runtime_dependency 'faraday_middleware'
|
26
28
|
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: 1.1.
|
4
|
+
version: 1.1.1
|
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-
|
11
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0
|
48
|
-
type: :
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday_middleware
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
description: Black-box web app configuration testing
|
70
98
|
email:
|
71
99
|
- robb@weblaws.org
|
@@ -74,6 +102,7 @@ extensions: []
|
|
74
102
|
extra_rdoc_files: []
|
75
103
|
files:
|
76
104
|
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
77
106
|
- Gemfile
|
78
107
|
- LICENSE.txt
|
79
108
|
- README.md
|