async-rspec 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 71491846f3d0cc9a03b883ddb403ba7d263a8dc5
4
- data.tar.gz: e5dec9b2763165b4420102148272f5c6aedd0985
2
+ SHA256:
3
+ metadata.gz: 4186b47c672f3a320cdebcccf6ba46b40457ad82683883c832b96ba4d6f11ace
4
+ data.tar.gz: 5a7843539aedc0b9f66dca87106f24f9c28f831507be98755e1e839853f81b32
5
5
  SHA512:
6
- metadata.gz: 3b0287ca7aa17d1f27701dd08c4a31647a9dbbb06123fa8f85e76986bd7eb4f948277407fd0394ec462e080c550338d76f3b3fa2c8c8d75a7dd4d8a02b53143c
7
- data.tar.gz: f25107c8161a2ad8e7d74eeb558df43b98e1b268f03b2052681ea8647e48e85ecccd8ff7572d1e8227a62dc73ab352a3a9a2e1b5deb3538a84ff042c345e0e5a
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
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module RSpec
23
- VERSION = "1.1.0"
23
+ VERSION = "1.2.0"
24
24
  end
25
25
  end
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.1.0
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: 2017-06-06 00:00:00.000000000 Z
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.6.10
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.