spec/async/io/ssl_socket_spec.rb in async-io-1.1.0 vs spec/async/io/ssl_socket_spec.rb in async-io-1.2.0
- old
+ new
@@ -18,30 +18,20 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
require 'async/io/ssl_socket'
+require 'async/rspec/ssl'
+
RSpec.describe Async::Reactor do
include_context Async::RSpec::Leaks
+ include_context Async::RSpec::SSL::VerifiedContexts
- let(:ssl_client_params) do
- {
- ca_file: File.expand_path(certificate_authority_key_file, __dir__)
- }
- end
-
- let(:ssl_server_params) do
- {
- cert: OpenSSL::X509::Certificate.new(File.read(server_cert_file)),
- key: OpenSSL::PKey::RSA.new(File.read(server_key_file))
- }
- end
-
# Shared port for localhost network tests.
let(:endpoint) {Async::IO::Endpoint.tcp("localhost", 6779, reuse_port: true)}
- let(:server_endpoint) {Async::IO::SecureEndpoint.new(endpoint, ssl_params: ssl_server_params)}
- let(:client_endpoint) {Async::IO::SecureEndpoint.new(endpoint, ssl_params: ssl_client_params)}
+ let(:server_endpoint) {Async::IO::SecureEndpoint.new(endpoint, ssl_context: server_context)}
+ let(:client_endpoint) {Async::IO::SecureEndpoint.new(endpoint, ssl_context: client_context)}
let(:data) {"The quick brown fox jumped over the lazy dog."}
around(:each) do |example|
# Accept a single incoming connection and then finish.
@@ -65,13 +55,11 @@
end
end
describe "#connect" do
context "with a trusted certificate" do
- let(:certificate_authority_key_file) {File.expand_path("ssl/trusted-ca.crt", __dir__)}
- let(:server_cert_file) {File.expand_path("ssl/trusted-cert.crt", __dir__)}
- let(:server_key_file) {File.expand_path("ssl/trusted-cert.key", __dir__)}
+ include_context Async::RSpec::SSL::ValidCertificate
it "should start server and send data" do
subject.async do
client_endpoint.connect do |client|
client.write(data)
@@ -80,12 +68,10 @@
end
end
end
context "with an untrusted certificate" do
- let(:certificate_authority_key_file) {File.expand_path("ssl/trusted-ca.crt", __dir__)}
- let(:server_cert_file) {File.expand_path("ssl/untrusted-cert.crt", __dir__)}
- let(:server_key_file) {File.expand_path("ssl/untrusted-cert.key", __dir__)}
+ include_context Async::RSpec::SSL::InvalidCertificate
it "should fail to connect" do
subject.async do
expect do
client_endpoint.connect