File: ssl.rb

package info (click to toggle)
ruby-async-http 0.94.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 916 kB
  • sloc: ruby: 5,224; javascript: 40; makefile: 4
file content (56 lines) | stat: -rw-r--r-- 1,388 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2018-2025, by Samuel Williams.

require "async/http/server"
require "async/http/client"
require "async/http/endpoint"

require "sus/fixtures/async"
require "sus/fixtures/openssl"
require "sus/fixtures/async/http"

describe Async::HTTP::Server do
	include Sus::Fixtures::Async::HTTP::ServerContext
	include Sus::Fixtures::OpenSSL::ValidCertificateContext
	
	with "application layer protocol negotiation" do
		let(:server_context) do
			OpenSSL::SSL::SSLContext.new.tap do |context|
				context.cert = certificate
				
				context.alpn_select_cb = lambda do |protocols|
					protocols.last
				end
				
				context.key = key
			end
		end
		
		let(:client_context) do
			OpenSSL::SSL::SSLContext.new.tap do |context|
				context.cert_store = certificate_store
				
				context.alpn_protocols = ["h2", "http/1.1"]
				
				context.verify_mode = OpenSSL::SSL::VERIFY_PEER
			end
		end
		
		def make_server_endpoint(bound_endpoint)
			::IO::Endpoint::SSLEndpoint.new(super, ssl_context: server_context)
		end
		
		def make_client_endpoint(bound_endpoint)
			::IO::Endpoint::SSLEndpoint.new(super, ssl_context: client_context)
		end
		
		it "client can get a resource via https" do
			response = client.get("/")
			
			expect(response).to be(:success?)
			expect(response.read).to be == "Hello World!"
		end
	end
end