rspec-ssltls 0.0.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 +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.rubocop.yml +7 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +16 -0
- data/lib/rspec_ssltls.rb +9 -0
- data/lib/rspec_ssltls/have_certificate.rb +67 -0
- data/lib/rspec_ssltls/support_cipher.rb +61 -0
- data/lib/rspec_ssltls/support_protocol.rb +50 -0
- data/lib/rspec_ssltls/util.rb +21 -0
- data/lib/rspec_ssltls/version.rb +4 -0
- data/rspec-ssltls.gemspec +27 -0
- data/spec/rspec_ssltls/have_certificate_spec.rb +60 -0
- data/spec/rspec_ssltls/rspec_ssltls_spec.rb +9 -0
- data/spec/rspec_ssltls/support_cipher_spec.rb +32 -0
- data/spec/rspec_ssltls/support_protocol_spec.rb +29 -0
- data/spec/spec_helper.rb +28 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 106422eae27ce3fcfb374cad4f40064c67c0ced8
|
4
|
+
data.tar.gz: 408d3000f6594d1c366767d1601717d6e478c7e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 745474287c2168102ea143d447d3d1b1cff131c9b92c766b222b412030e340fdcdd399b65b643860960f228adc9aa24b3f9ccbd245ef843f7e29782bc1190979
|
7
|
+
data.tar.gz: a37e12b745101f13bf736f0fa3580287ac5808475230d05b7d9972891923b16ac8e1a82b8392ccd075b4d37b3c30269c409c93d4455221857a637a23bce89a00
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 OTA Hiroshi
|
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,64 @@
|
|
1
|
+
# rspec-ssltls [](https://travis-ci.org/otahi/rspec-ssltls)[](https://coveralls.io/r/otahi/rspec-ssltls?branch=master)[](https://codeclimate.com/github/otahi/rspec-ssltls)[](http://badge.fury.io/rb/rspec-ssltls)
|
2
|
+
|
3
|
+
|
4
|
+
Rspec-ssltls is an rspec plugin for easy SSL/TLS testing.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
RSpec-ssltls is best described by example. First, require `rspec-ssltls` in your `spec_helper.rb`:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
# spec/spec_helper.rb
|
12
|
+
require 'rspec-ssltls'
|
13
|
+
```
|
14
|
+
|
15
|
+
Then, create a spec like this:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'spec_helper'
|
19
|
+
|
20
|
+
describe 'www.example.com:443' do
|
21
|
+
it { is_expected.to have_certificate.subject(CN: '*.example.com') }
|
22
|
+
it { is_expected.to support_protocol('TLSv1_2') }
|
23
|
+
it { is_expected.to support_cipher('AES256-SHA').protocol('TLSv1') }
|
24
|
+
it { is_expected.to support_cipher('DES-CBC3-SHA').protocol('SSLv3') }
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
You can use followings for `support_protocol` and `support_cipher.protocol`:
|
29
|
+
```
|
30
|
+
OpenSSL::SSL::SSLContext::METHODS
|
31
|
+
:TLSv1, :TLSv1_server, :TLSv1_client,
|
32
|
+
:TLSv1_2, :TLSv1_2_server, :TLSv1_2_client,
|
33
|
+
:TLSv1_1, :TLSv1_1_server, :TLSv1_1_client,
|
34
|
+
:SSLv2, :SSLv2_server, :SSLv2_client,
|
35
|
+
:SSLv3, :SSLv3_server, :SSLv3_client,
|
36
|
+
:SSLv23, :SSLv23_server, :SSLv23_client
|
37
|
+
```
|
38
|
+
|
39
|
+
You can use [ciphers](https://www.openssl.org/docs/apps/ciphers.html) for `support_cipher`.
|
40
|
+
|
41
|
+
|
42
|
+
## Installation
|
43
|
+
|
44
|
+
Add this line to your application's Gemfile:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
gem 'rspec-ssltls'
|
48
|
+
```
|
49
|
+
|
50
|
+
And then execute:
|
51
|
+
|
52
|
+
$ bundle
|
53
|
+
|
54
|
+
Or install it yourself as:
|
55
|
+
|
56
|
+
$ gem install rspec-ssltls
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
1. Fork it ( https://github.com/otahi/rspec-ssltls/fork )
|
61
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rubocop/rake_task'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'coveralls/rake/task'
|
5
|
+
|
6
|
+
task default: [:spec, 'coveralls:push', :rubocop]
|
7
|
+
|
8
|
+
Coveralls::RakeTask.new
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
11
|
+
t.pattern = 'spec/**/*_spec.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
15
|
+
task.patterns = %w(lib/**/*.rb spec/**/*.rb)
|
16
|
+
end
|
data/lib/rspec_ssltls.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'rspec_ssltls'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :have_certificate do
|
5
|
+
match do |dest|
|
6
|
+
@chain_string = ''
|
7
|
+
@result_string = ''
|
8
|
+
uri = URI.parse('https://' + dest)
|
9
|
+
socket = TCPSocket.open(uri.host, uri.port)
|
10
|
+
ssl_context = OpenSSL::SSL::SSLContext.new
|
11
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
|
12
|
+
ssl_socket.sync_close = true
|
13
|
+
ssl_socket.connect
|
14
|
+
@peer_cert = ssl_socket.peer_cert
|
15
|
+
ssl_socket.close
|
16
|
+
@peer_cert ? valid_cert? : false
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid_cert?
|
20
|
+
@result_cert = {}
|
21
|
+
@result_cert.merge!(subject: valid_subject?)
|
22
|
+
@result_cert.values.all? { |r| r == true }
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid_subject?
|
26
|
+
return true unless @subject
|
27
|
+
invalid = false
|
28
|
+
@subject.each_pair do |k, v|
|
29
|
+
value = cert_value(k)
|
30
|
+
next if value == v
|
31
|
+
@result_string += " expected: #{k}=#{v}\n actual: #{k}=#{value}\n"
|
32
|
+
invalid = true
|
33
|
+
end
|
34
|
+
invalid ? false : true
|
35
|
+
end
|
36
|
+
|
37
|
+
def cert_value(key)
|
38
|
+
values = @peer_cert.subject.to_a.select do |k, _, _|
|
39
|
+
k.to_s == key.to_s
|
40
|
+
end
|
41
|
+
values.first ? values.first[1] : ''
|
42
|
+
end
|
43
|
+
|
44
|
+
chain :subject do |subject|
|
45
|
+
fail 'Argument Error. Needs hash arguments' unless
|
46
|
+
subject.respond_to?(:each_pair)
|
47
|
+
|
48
|
+
@subject = subject
|
49
|
+
@subject.each_pair do |k, v|
|
50
|
+
RspecSsltls::Util.add_string(@chain_string, "#{k}=#{v}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
description do
|
55
|
+
"have a certificate#{@chain_string}"
|
56
|
+
end
|
57
|
+
|
58
|
+
failure_message do
|
59
|
+
s = "expected to have a certificate#{@chain_string}, but did not."
|
60
|
+
s + "\n#{@result_string}"
|
61
|
+
end
|
62
|
+
|
63
|
+
failure_message_when_negated do
|
64
|
+
s = "expected not to have a certificate#{@chain_string}, but did."
|
65
|
+
s + "\n#{@result_string}"
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'rspec_ssltls'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
# See Chiphers
|
5
|
+
# https://www.openssl.org/docs/apps/ciphers.html
|
6
|
+
|
7
|
+
RSpec::Matchers.define :support_cipher do |cipher|
|
8
|
+
match do |dest|
|
9
|
+
fail 'No Argument Error.' unless cipher
|
10
|
+
@protocol ||= 'SSLv23'
|
11
|
+
@cipher = Set.new + [cipher].flatten
|
12
|
+
|
13
|
+
@supported_cipher = Set.new
|
14
|
+
@not_supported_cipher = Set.new
|
15
|
+
uri = URI.parse('https://' + dest)
|
16
|
+
|
17
|
+
@cipher.each do |ci|
|
18
|
+
socket = TCPSocket.open(uri.host, uri.port)
|
19
|
+
ssl_context = OpenSSL::SSL::SSLContext.new(@protocol)
|
20
|
+
ssl_context.ciphers = [ci]
|
21
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
|
22
|
+
ssl_socket.sync_close = true
|
23
|
+
begin
|
24
|
+
ssl_socket.connect
|
25
|
+
@supported_cipher.add(ci) if ssl_socket.cipher
|
26
|
+
ssl_socket.close
|
27
|
+
rescue
|
28
|
+
@not_supported_cipher.add(ci)
|
29
|
+
ensure
|
30
|
+
ssl_socket && ssl_socket.close
|
31
|
+
end
|
32
|
+
end
|
33
|
+
(@cipher - @supported_cipher).size == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
chain :protocol do |protocol|
|
37
|
+
invalid_protocol = RspecSsltls::Util.invalid_ssl_tls_protocol(protocol)
|
38
|
+
fail "Invalid protocol.#{invalid_protocol.to_a}" if invalid_protocol
|
39
|
+
@protocol = [protocol].flatten.first
|
40
|
+
@chain_string =
|
41
|
+
RspecSsltls::Util.add_string(@chain_string, "on #{@protocol}")
|
42
|
+
end
|
43
|
+
|
44
|
+
description do
|
45
|
+
"support cipher #{@cipher.to_a}"
|
46
|
+
end
|
47
|
+
|
48
|
+
failure_message do
|
49
|
+
s = "expected to support cipher #{@cipher.to_a}"
|
50
|
+
s += "#{@chain_string}, but did not."
|
51
|
+
s += "\n suppported cipher: #{@supported_cipher.to_a}."
|
52
|
+
s + "\n not suppported cipher: #{@not_supported_cipher.to_a}."
|
53
|
+
end
|
54
|
+
|
55
|
+
failure_message_when_negated do
|
56
|
+
s = "expected not to support cipher #{@cipher.to_a}"
|
57
|
+
s += "#{@chain_string}, but did."
|
58
|
+
s += "\n suppported cipher: #{@supported_cipher.to_a}."
|
59
|
+
s + "\n not suppported cipher: #{@not_supported_cipher.to_a}."
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rspec_ssltls'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :support_protocol do |protocol|
|
5
|
+
match do |dest|
|
6
|
+
fail 'No Argument Error.' unless protocol
|
7
|
+
@protocol = Set.new + [protocol].flatten
|
8
|
+
|
9
|
+
invalid_protocol = RspecSsltls::Util.invalid_ssl_tls_protocol(@protocol)
|
10
|
+
fail "Invalid protocol.#{invalid_protocol.to_a}" if invalid_protocol
|
11
|
+
|
12
|
+
@supported_protocol = Set.new
|
13
|
+
@not_supported_protocol = Set.new
|
14
|
+
uri = URI.parse('https://' + dest)
|
15
|
+
|
16
|
+
@protocol.each do |pr|
|
17
|
+
socket = TCPSocket.open(uri.host, uri.port)
|
18
|
+
ssl_context = OpenSSL::SSL::SSLContext.new(pr)
|
19
|
+
ssl_context.ciphers = ['ALL']
|
20
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
|
21
|
+
ssl_socket.sync_close = true
|
22
|
+
begin
|
23
|
+
ssl_socket.connect
|
24
|
+
@supported_protocol.add(pr) if ssl_socket.ssl_version
|
25
|
+
ssl_socket.close
|
26
|
+
rescue
|
27
|
+
@not_supported_protocol.add(pr)
|
28
|
+
ensure
|
29
|
+
ssl_socket && ssl_socket.close
|
30
|
+
end
|
31
|
+
end
|
32
|
+
(@protocol - @supported_protocol).size == 0
|
33
|
+
end
|
34
|
+
|
35
|
+
description do
|
36
|
+
"support protocol #{@protocol.to_a}"
|
37
|
+
end
|
38
|
+
|
39
|
+
failure_message do
|
40
|
+
s = "expected to support protocol #{@protocol.to_a}, but did not."
|
41
|
+
s += "\n suppported protocol: #{@supported_protocol.to_a}."
|
42
|
+
s + "\n not suppported protocol: #{@not_supported_protocol.to_a}."
|
43
|
+
end
|
44
|
+
|
45
|
+
failure_message_when_negated do
|
46
|
+
s = "expected not to support protocol #{@protocol.to_a}, but did."
|
47
|
+
s += "\n suppported protocol: #{@supported_protocol.to_a}."
|
48
|
+
s + "\n not suppported protocol: #{@not_supported_protocol.to_a}."
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Easily test your SSL/TLS with RSpec.
|
2
|
+
module RspecSsltls
|
3
|
+
# Utility class
|
4
|
+
class Util
|
5
|
+
def self.add_string(target, addition)
|
6
|
+
if target.nil?
|
7
|
+
target = ' ' + addition
|
8
|
+
else
|
9
|
+
target.join(addition, ' ')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.invalid_ssl_tls_protocol(protocol)
|
14
|
+
protocol = Set.new + [protocol] unless protocol.respond_to?(:map)
|
15
|
+
invalid_protocol =
|
16
|
+
(protocol.map { |a| a.to_s } -
|
17
|
+
OpenSSL::SSL::SSLContext::METHODS.map { |a| a.to_s })
|
18
|
+
invalid_protocol.size > 0 ? invalid_protocol : nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec_ssltls/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rspec-ssltls'
|
8
|
+
spec.version = RspecSsltls::VERSION
|
9
|
+
spec.authors = ['OTA Hiroshi']
|
10
|
+
spec.email = ['otahi.pub@gmail.com']
|
11
|
+
spec.summary = %q{Easily test your SSL/TLS with RSpec.}
|
12
|
+
spec.description = %q{Rspec-ssltls is an rspec plugin for easy SSL/TLS testing.}
|
13
|
+
spec.homepage = 'https://github.com/otahi/rspec-ssltls'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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
|
+
spec.add_dependency 'rspec', '>= 2.9'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '>= 1.6'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rubocop', '0.24.1'
|
25
|
+
spec.add_development_dependency 'coveralls', '~> 0.7'
|
26
|
+
spec.add_development_dependency 'byebug', '~> 3.4.0'
|
27
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec_ssltls'
|
3
|
+
|
4
|
+
def stub_ssl_socket(params = nil)
|
5
|
+
allow(TCPSocket).to receive(:open).and_return(nil)
|
6
|
+
allow(OpenSSL::SSL::SSLSocket).to receive(:new) do
|
7
|
+
ssl_socket = double('ssl_socket')
|
8
|
+
allow(ssl_socket).to receive(:method_missing).and_return(nil)
|
9
|
+
params.each_pair do |k, v|
|
10
|
+
allow(ssl_socket).to receive(k).and_return(v)
|
11
|
+
end if params
|
12
|
+
ssl_socket
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# See http://www.ietf.org/rfc/rfc5280.txt 4.1.2.4
|
17
|
+
example_cert_name =
|
18
|
+
OpenSSL::X509::Name.new([%w(C JP),
|
19
|
+
%w(ST Tokyo),
|
20
|
+
%w(O Example\ Co.,\ Ltd.),
|
21
|
+
%w(OU Example\ Div.),
|
22
|
+
%w(CN *.example.com)
|
23
|
+
])
|
24
|
+
example_cert = OpenSSL::X509::Certificate.new
|
25
|
+
example_cert.subject = example_cert_name
|
26
|
+
|
27
|
+
example_ca_cert_name =
|
28
|
+
OpenSSL::X509::Name.new([%w(C US),
|
29
|
+
%w(O Example\ Org.),
|
30
|
+
%w(OU Example\ Org.\ Div.),
|
31
|
+
%w(CN *.example.org)
|
32
|
+
])
|
33
|
+
example_ca_cert = OpenSSL::X509::Certificate.new
|
34
|
+
example_ca_cert.subject = example_ca_cert_name
|
35
|
+
|
36
|
+
describe 'rspec-ssltls matchers' do
|
37
|
+
describe '#have_certificate' do
|
38
|
+
it 'can evalutate having certificate' do
|
39
|
+
stub_ssl_socket(peer_cert: nil)
|
40
|
+
expect('www.example.com:443').not_to have_certificate
|
41
|
+
stub_ssl_socket(peer_cert: example_cert)
|
42
|
+
expect('www.example.com:443').to have_certificate
|
43
|
+
end
|
44
|
+
it 'can evalutate having certificate subject' do
|
45
|
+
stub_ssl_socket(peer_cert: example_cert)
|
46
|
+
expect('www.example.com:443')
|
47
|
+
.to have_certificate.subject(CN: '*.example.com')
|
48
|
+
expect('www.example.com:443')
|
49
|
+
.to have_certificate.subject(CN: '*.example.com',
|
50
|
+
C: 'JP',
|
51
|
+
ST: 'Tokyo',
|
52
|
+
O: 'Example Co., Ltd.',
|
53
|
+
OU: 'Example Div.',
|
54
|
+
CN: '*.example.com'
|
55
|
+
)
|
56
|
+
expect('www.example.com:443')
|
57
|
+
.not_to have_certificate.subject(CN: 'www.example.com')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec_ssltls'
|
3
|
+
|
4
|
+
describe 'rspec-ssltls matchers' do
|
5
|
+
describe '#support_cipher' do
|
6
|
+
it 'can evalutate support cipher' do
|
7
|
+
stub_ssl_socket(cipher: ['DES-CBC3-SHA', 'TLSv1/SSLv3', 168, 168])
|
8
|
+
expect('www.example.com:443')
|
9
|
+
.to support_cipher('DES-CBC3-SHA')
|
10
|
+
|
11
|
+
stub_ssl_socket(cipher: ['AES256-SHA', 'TLSv1/SSLv3', 168, 168])
|
12
|
+
expect('www.example.com:443')
|
13
|
+
.to support_cipher(['AES256-SHA', 'DES-CBC3-SHA'])
|
14
|
+
|
15
|
+
stub_ssl_socket(cipher: nil)
|
16
|
+
expect('www.example.com:443')
|
17
|
+
.not_to support_cipher('AES256-SHA')
|
18
|
+
end
|
19
|
+
it 'can evalutate support cipher specified with protocol' do
|
20
|
+
stub_ssl_socket(cipher: ['AES256-SHA', 'TLSv1/SSLv3', 168, 168])
|
21
|
+
expect('www.example.com:443')
|
22
|
+
.to support_cipher('AES256-SHA').protocol('TLSv1')
|
23
|
+
end
|
24
|
+
|
25
|
+
# show default description
|
26
|
+
it do
|
27
|
+
stub_ssl_socket(cipher: ['DES-CBC3-SHA', 'TLSv1/SSLv3', 168, 168])
|
28
|
+
expect('www.example.com:443')
|
29
|
+
.to support_cipher('DES-CBC3-SHA')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec_ssltls'
|
3
|
+
|
4
|
+
# OpenSSL::SSL::SSLContext::METHODS
|
5
|
+
# :TLSv1, :TLSv1_server, :TLSv1_client,
|
6
|
+
# :TLSv1_2, :TLSv1_2_server, :TLSv1_2_client,
|
7
|
+
# :TLSv1_1, :TLSv1_1_server, :TLSv1_1_client,
|
8
|
+
# :SSLv2, :SSLv2_server, :SSLv2_client,
|
9
|
+
# :SSLv3, :SSLv3_server, :SSLv3_client,
|
10
|
+
# :SSLv23, :SSLv23_server, :SSLv23_client
|
11
|
+
|
12
|
+
describe 'rspec-ssltls matchers' do
|
13
|
+
describe '#support_protocol' do
|
14
|
+
it 'can evalutate support protocol' do
|
15
|
+
stub_ssl_socket(ssl_version: 'TLSv1')
|
16
|
+
expect('www.example.com:443').to support_protocol('TLSv1')
|
17
|
+
expect('www.example.com:443').to support_protocol(:TLSv1)
|
18
|
+
stub_ssl_socket(ssl_version: nil)
|
19
|
+
expect('www.example.com:443').not_to support_protocol('SSLv3')
|
20
|
+
expect('www.example.com:443').not_to support_protocol([:TLSv1, 'SSLv3'])
|
21
|
+
end
|
22
|
+
|
23
|
+
it do
|
24
|
+
# show default description
|
25
|
+
stub_ssl_socket(ssl_version: 'TLSv1')
|
26
|
+
expect('www.example.com:443').to support_protocol('TLSv1')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
require 'simplecov'
|
5
|
+
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
Coveralls::SimpleCov::Formatter
|
9
|
+
]
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter '.bundle/'
|
12
|
+
end
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
15
|
+
|
16
|
+
require 'rspec_ssltls'
|
17
|
+
|
18
|
+
def stub_ssl_socket(params = nil)
|
19
|
+
allow(TCPSocket).to receive(:open).and_return(nil)
|
20
|
+
allow(OpenSSL::SSL::SSLSocket).to receive(:new) do
|
21
|
+
ssl_socket = double('ssl_socket')
|
22
|
+
allow(ssl_socket).to receive(:method_missing).and_return(nil)
|
23
|
+
params.each_pair do |k, v|
|
24
|
+
allow(ssl_socket).to receive(k).and_return(v)
|
25
|
+
end if params
|
26
|
+
ssl_socket
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-ssltls
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- OTA Hiroshi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.24.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.24.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coveralls
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.4.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.4.0
|
97
|
+
description: Rspec-ssltls is an rspec plugin for easy SSL/TLS testing.
|
98
|
+
email:
|
99
|
+
- otahi.pub@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- lib/rspec_ssltls.rb
|
113
|
+
- lib/rspec_ssltls/have_certificate.rb
|
114
|
+
- lib/rspec_ssltls/support_cipher.rb
|
115
|
+
- lib/rspec_ssltls/support_protocol.rb
|
116
|
+
- lib/rspec_ssltls/util.rb
|
117
|
+
- lib/rspec_ssltls/version.rb
|
118
|
+
- rspec-ssltls.gemspec
|
119
|
+
- spec/rspec_ssltls/have_certificate_spec.rb
|
120
|
+
- spec/rspec_ssltls/rspec_ssltls_spec.rb
|
121
|
+
- spec/rspec_ssltls/support_cipher_spec.rb
|
122
|
+
- spec/rspec_ssltls/support_protocol_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
homepage: https://github.com/otahi/rspec-ssltls
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.2.2
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: Easily test your SSL/TLS with RSpec.
|
148
|
+
test_files:
|
149
|
+
- spec/rspec_ssltls/have_certificate_spec.rb
|
150
|
+
- spec/rspec_ssltls/rspec_ssltls_spec.rb
|
151
|
+
- spec/rspec_ssltls/support_cipher_spec.rb
|
152
|
+
- spec/rspec_ssltls/support_protocol_spec.rb
|
153
|
+
- spec/spec_helper.rb
|