async-rspec 1.1.0 → 1.2.0
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 +5 -5
- data/lib/async/rspec/ssl.rb +158 -0
- data/lib/async/rspec/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4186b47c672f3a320cdebcccf6ba46b40457ad82683883c832b96ba4d6f11ace
|
4
|
+
data.tar.gz: 5a7843539aedc0b9f66dca87106f24f9c28f831507be98755e1e839853f81b32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7380969198beb4a1cd5398136bdebc9d4942103eeefed2cb1fcdad5b4c6be81592333dd20b5613711bd11a3d0d6deec9b26dd9f36d20a4ed0f6ceb36bd319076
|
7
|
+
data.tar.gz: d7944d2dc3f14bf60f52d4fca2ff040d647d64cdafc2088abf65f789bf7815c55b655a7027dd012822cbcfe1f473e9f419d43730232b0cb1b0b55793f42f1759
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'openssl'
|
22
|
+
|
23
|
+
module Async
|
24
|
+
module RSpec
|
25
|
+
module SSL
|
26
|
+
module CertificateAuthority
|
27
|
+
end
|
28
|
+
|
29
|
+
module ValidCertificate
|
30
|
+
end
|
31
|
+
|
32
|
+
module InvalidCertificate
|
33
|
+
end
|
34
|
+
|
35
|
+
module VerifiedContexts
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
RSpec.shared_context SSL::CertificateAuthority do
|
40
|
+
# This key size is generally considered insecure, but it's fine for testing.
|
41
|
+
let(:certificate_authority_key) {OpenSSL::PKey::RSA.new(1024)}
|
42
|
+
let(:certificate_authority_name) {OpenSSL::X509::Name.parse("O=Test/CN=localhost")}
|
43
|
+
|
44
|
+
# The certificate authority is used for signing and validating the certificate which is used for communciation:
|
45
|
+
let(:certificate_authority) do
|
46
|
+
certificate = OpenSSL::X509::Certificate.new
|
47
|
+
|
48
|
+
certificate.subject = certificate_authority_name
|
49
|
+
# We use the same issuer as the subject, which makes this certificate self-signed:
|
50
|
+
certificate.issuer = certificate_authority_name
|
51
|
+
|
52
|
+
certificate.public_key = certificate_authority_key.public_key
|
53
|
+
|
54
|
+
certificate.serial = 1
|
55
|
+
certificate.version = 2
|
56
|
+
|
57
|
+
certificate.not_before = Time.now
|
58
|
+
certificate.not_after = Time.now + 3600
|
59
|
+
|
60
|
+
extension_factory = OpenSSL::X509::ExtensionFactory.new()
|
61
|
+
extension_factory.subject_certificate = certificate
|
62
|
+
extension_factory.issuer_certificate = certificate
|
63
|
+
certificate.add_extension extension_factory.create_extension("basicConstraints", "CA:TRUE", true)
|
64
|
+
certificate.add_extension extension_factory.create_extension("keyUsage", "keyCertSign, cRLSign", true)
|
65
|
+
certificate.add_extension extension_factory.create_extension("subjectKeyIdentifier", "hash")
|
66
|
+
certificate.add_extension extension_factory.create_extension("authorityKeyIdentifier", "keyid:always", false)
|
67
|
+
|
68
|
+
certificate.sign certificate_authority_key, OpenSSL::Digest::SHA256.new
|
69
|
+
end
|
70
|
+
|
71
|
+
let(:certificate_store) do
|
72
|
+
# The certificate store which is used for validating the server certificate:
|
73
|
+
OpenSSL::X509::Store.new.tap do |certificates|
|
74
|
+
certificates.add_cert(certificate_authority)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
RSpec.shared_context SSL::ValidCertificate do
|
80
|
+
include_context SSL::CertificateAuthority
|
81
|
+
|
82
|
+
# The private key to use on the server side:
|
83
|
+
let(:key) {OpenSSL::PKey::RSA.new(1024)}
|
84
|
+
let(:certificate_name) {OpenSSL::X509::Name.parse("O=Test/CN=localhost")}
|
85
|
+
|
86
|
+
# The certificate used for actual communication:
|
87
|
+
let(:certificate) do
|
88
|
+
certificate = OpenSSL::X509::Certificate.new
|
89
|
+
certificate.subject = certificate_name
|
90
|
+
certificate.issuer = certificate_authority.subject
|
91
|
+
|
92
|
+
certificate.public_key = key.public_key
|
93
|
+
|
94
|
+
certificate.serial = 2
|
95
|
+
certificate.version = 2
|
96
|
+
|
97
|
+
certificate.not_before = Time.now
|
98
|
+
certificate.not_after = Time.now + 3600
|
99
|
+
|
100
|
+
extension_factory = OpenSSL::X509::ExtensionFactory.new()
|
101
|
+
extension_factory.subject_certificate = certificate
|
102
|
+
extension_factory.issuer_certificate = certificate_authority
|
103
|
+
certificate.add_extension extension_factory.create_extension("keyUsage", "digitalSignature", true)
|
104
|
+
certificate.add_extension extension_factory.create_extension("subjectKeyIdentifier", "hash")
|
105
|
+
|
106
|
+
certificate.sign certificate_authority_key, OpenSSL::Digest::SHA256.new
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
RSpec.shared_context SSL::InvalidCertificate do
|
111
|
+
include_context SSL::CertificateAuthority
|
112
|
+
|
113
|
+
# The private key to use on the server side:
|
114
|
+
let(:key) {OpenSSL::PKey::RSA.new(1024)}
|
115
|
+
let(:invalid_key) {OpenSSL::PKey::RSA.new(1024)}
|
116
|
+
let(:certificate_name) {OpenSSL::X509::Name.parse("O=Test/CN=localhost")}
|
117
|
+
|
118
|
+
# The certificate used for actual communication:
|
119
|
+
let(:certificate) do
|
120
|
+
certificate = OpenSSL::X509::Certificate.new
|
121
|
+
certificate.subject = certificate_name
|
122
|
+
certificate.issuer = certificate_authority.subject
|
123
|
+
|
124
|
+
certificate.public_key = key.public_key
|
125
|
+
|
126
|
+
certificate.serial = 2
|
127
|
+
certificate.version = 2
|
128
|
+
|
129
|
+
certificate.not_before = Time.now - 3600
|
130
|
+
certificate.not_after = Time.now
|
131
|
+
|
132
|
+
extension_factory = OpenSSL::X509::ExtensionFactory.new()
|
133
|
+
extension_factory.subject_certificate = certificate
|
134
|
+
extension_factory.issuer_certificate = certificate_authority
|
135
|
+
certificate.add_extension extension_factory.create_extension("keyUsage", "digitalSignature", true)
|
136
|
+
certificate.add_extension extension_factory.create_extension("subjectKeyIdentifier", "hash")
|
137
|
+
|
138
|
+
certificate.sign invalid_key, OpenSSL::Digest::SHA256.new
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
RSpec.shared_context SSL::VerifiedContexts do
|
143
|
+
let(:server_context) do
|
144
|
+
OpenSSL::SSL::SSLContext.new.tap do |context|
|
145
|
+
context.cert = certificate
|
146
|
+
context.key = key
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
let(:client_context) do
|
151
|
+
OpenSSL::SSL::SSLContext.new.tap do |context|
|
152
|
+
context.cert_store = certificate_store
|
153
|
+
context.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
data/lib/async/rspec/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- lib/async/rspec/leaks.rb
|
99
99
|
- lib/async/rspec/profile.rb
|
100
100
|
- lib/async/rspec/reactor.rb
|
101
|
+
- lib/async/rspec/ssl.rb
|
101
102
|
- lib/async/rspec/version.rb
|
102
103
|
homepage: https://github.com/socketry/async-rspec
|
103
104
|
licenses: []
|
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
119
|
version: '0'
|
119
120
|
requirements: []
|
120
121
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.7.2
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: Helpers for writing specs against the async gem.
|