rspec-webservice_matchers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fdde871a9bb1b3c46d81476b0e0d7e9dc7378d4c
4
+ data.tar.gz: 9292c0781c7f84c9702c4db4d5e07dbd59b4dad3
5
+ SHA512:
6
+ metadata.gz: 00aecb1d00ec6df7fb22b017348e35f115855a8958266bb04ef38a39cf55074d60d936f63670208461bf1ffb0ed3ea016ebdfb01000c4adfdb9fb4130fdca497
7
+ data.tar.gz: 80237c517ab3e2dbd7a4a97d0d05daa31e68f92e6c7b71f282d31528937384f4364820cad6d8ef51f538dc6a60157795fe3ef6e1ebcb21603afb955634a24b15
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-webservice_matchers.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Robb Shecter
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Rspec::WebserviceMatchers
2
+
3
+ This gem 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
+
5
+ TODO: Finish the Gem set up and register as a Gem.
6
+
7
+
8
+ Example
9
+ -------
10
+
11
+ ```Ruby
12
+ require 'rspec/webservice_matchers'
13
+
14
+ describe 'My app' do
15
+ it 'is configured for ssl' do
16
+ # New-style RSpec syntax
17
+ expect('www.myapp.com').to have_a_valid_cert
18
+
19
+ # Old-style RSpec syntax
20
+ 'www.weblaws.org'.should have_a_valid_cert
21
+ end
22
+ end
23
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module WebserviceMatchers
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,45 @@
1
+ require 'rspec/webservice_matchers/version'
2
+ require 'curb'
3
+
4
+ module RSpec
5
+ module WebserviceMatchers
6
+
7
+ def self.has_valid_ssl_cert?(domain_name)
8
+ begin
9
+ Curl.get "https://#{domain_name}" # Faster than Curl.head; not sure why.
10
+ return true
11
+ rescue Curl::Err::ConnectionFailedError, Curl::Err::SSLCACertificateError, Curl::Err::SSLPeerCertificateError
12
+ # Not serving SSL, expired, or incorrect domain name
13
+ return false
14
+ end
15
+ end
16
+
17
+ #
18
+ # Custom RSpec matcher: have_a_valid_cert
19
+ #
20
+ RSpec::Matchers.define :have_a_valid_cert do
21
+ match do |domain_name|
22
+ RSpec::WebserviceMatchers.has_valid_ssl_cert?(domain_name)
23
+ end
24
+ end
25
+
26
+
27
+ # Would this matcher be helpful?
28
+
29
+ #
30
+ # Return true if the domain serves content via SSL
31
+ # without checking certificate validity.
32
+ #
33
+ # def self.supports_ssl?(domain_name)
34
+ # begin
35
+ # has_valid_ssl_cert?(domain_name)
36
+ # # Cert may not be valid, but content IS
37
+ # # being served via https.
38
+ # return true
39
+ # rescue Curl::Err::ConnectionFailedError
40
+ # return false
41
+ # end
42
+ # end
43
+
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/webservice_matchers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec-webservice_matchers"
8
+ spec.version = RSpec::WebserviceMatchers::VERSION
9
+ spec.authors = ["Robb Shecter"]
10
+ spec.email = ["robb@weblaws.org"]
11
+ spec.description = %q{Match specific HTTP result codes and valid HTTPS configuration}
12
+ spec.summary = %q{Handy matchers for testing web services}
13
+ spec.homepage = "https://github.com/dogweather/rspec-webservice_matchers"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,19 @@
1
+ require 'rspec/webservice_matchers'
2
+
3
+ describe 'have_a_valid_cert matcher' do
4
+
5
+ it 'passes when SSL is properly configured' do
6
+ # EFF created the HTTPS Everywhere movement
7
+ # TODO: set up test servers for this.
8
+ expect('www.eff.org').to have_a_valid_cert
9
+ end
10
+
11
+ it 'fails if the server is not serving SSL at all' do
12
+ expect {
13
+ # www.psu.edu only supports HTTP, port 80.
14
+ # TODO: set up test servers for this.
15
+ expect('www.psu.edu').to have_a_valid_cert
16
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
17
+ end
18
+
19
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-webservice_matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Robb Shecter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Match specific HTTP result codes and valid HTTPS configuration
42
+ email:
43
+ - robb@weblaws.org
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/rspec/webservice_matchers.rb
54
+ - lib/rspec/webservice_matchers/version.rb
55
+ - rspec-webservice_matchers.gemspec
56
+ - spec/rspec/webservice_matchers/ssl_spec.rb
57
+ homepage: https://github.com/dogweather/rspec-webservice_matchers
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.1
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Handy matchers for testing web services
81
+ test_files:
82
+ - spec/rspec/webservice_matchers/ssl_spec.rb