uringmachine 0.4 → 0.5.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 +4 -4
- data/.github/workflows/test.yml +2 -1
- data/CHANGELOG.md +16 -0
- data/README.md +44 -1
- data/TODO.md +12 -3
- data/examples/bm_snooze.rb +89 -0
- data/examples/bm_sqlite.rb +89 -0
- data/examples/bm_write.rb +56 -0
- data/examples/dns_client.rb +12 -0
- data/examples/http_server.rb +42 -43
- data/examples/pg.rb +85 -0
- data/examples/server_client.rb +64 -0
- data/examples/snooze.rb +44 -0
- data/examples/stream.rb +85 -0
- data/examples/write_dev_null.rb +16 -0
- data/ext/um/extconf.rb +81 -14
- data/ext/um/um.c +468 -414
- data/ext/um/um.h +149 -40
- data/ext/um/um_async_op.c +40 -0
- data/ext/um/um_async_op_class.c +136 -0
- data/ext/um/um_buffer.c +49 -0
- data/ext/um/um_class.c +176 -44
- data/ext/um/um_const.c +174 -9
- data/ext/um/um_ext.c +8 -0
- data/ext/um/um_mutex_class.c +47 -0
- data/ext/um/um_op.c +89 -111
- data/ext/um/um_queue_class.c +58 -0
- data/ext/um/um_ssl.c +850 -0
- data/ext/um/um_ssl.h +22 -0
- data/ext/um/um_ssl_class.c +138 -0
- data/ext/um/um_sync.c +273 -0
- data/ext/um/um_utils.c +1 -1
- data/lib/uringmachine/dns_resolver.rb +84 -0
- data/lib/uringmachine/ssl/context_builder.rb +96 -0
- data/lib/uringmachine/ssl.rb +394 -0
- data/lib/uringmachine/version.rb +1 -1
- data/lib/uringmachine.rb +27 -3
- data/supressions/ruby.supp +71 -0
- data/test/helper.rb +6 -0
- data/test/test_async_op.rb +119 -0
- data/test/test_ssl.rb +155 -0
- data/test/test_um.rb +464 -47
- data/uringmachine.gemspec +3 -2
- data/vendor/liburing/.gitignore +5 -0
- data/vendor/liburing/CHANGELOG +1 -0
- data/vendor/liburing/configure +32 -0
- data/vendor/liburing/examples/Makefile +1 -0
- data/vendor/liburing/examples/reg-wait.c +159 -0
- data/vendor/liburing/liburing.spec +1 -1
- data/vendor/liburing/src/include/liburing/io_uring.h +48 -2
- data/vendor/liburing/src/include/liburing.h +28 -2
- data/vendor/liburing/src/int_flags.h +10 -3
- data/vendor/liburing/src/liburing-ffi.map +13 -2
- data/vendor/liburing/src/liburing.map +9 -0
- data/vendor/liburing/src/queue.c +25 -16
- data/vendor/liburing/src/register.c +73 -4
- data/vendor/liburing/src/setup.c +46 -18
- data/vendor/liburing/src/setup.h +6 -0
- data/vendor/liburing/test/Makefile +7 -0
- data/vendor/liburing/test/cmd-discard.c +427 -0
- data/vendor/liburing/test/fifo-nonblock-read.c +69 -0
- data/vendor/liburing/test/file-exit-unreg.c +48 -0
- data/vendor/liburing/test/io_uring_passthrough.c +2 -0
- data/vendor/liburing/test/io_uring_register.c +13 -2
- data/vendor/liburing/test/napi-test.c +1 -1
- data/vendor/liburing/test/no-mmap-inval.c +1 -1
- data/vendor/liburing/test/read-mshot-empty.c +2 -0
- data/vendor/liburing/test/read-mshot-stdin.c +121 -0
- data/vendor/liburing/test/read-mshot.c +6 -0
- data/vendor/liburing/test/recvsend_bundle.c +2 -2
- data/vendor/liburing/test/reg-fd-only.c +1 -1
- data/vendor/liburing/test/reg-wait.c +251 -0
- data/vendor/liburing/test/regbuf-clone.c +458 -0
- data/vendor/liburing/test/resize-rings.c +643 -0
- data/vendor/liburing/test/rsrc_tags.c +1 -1
- data/vendor/liburing/test/sqpoll-sleep.c +39 -8
- data/vendor/liburing/test/sqwait.c +136 -0
- data/vendor/liburing/test/sync-cancel.c +8 -1
- data/vendor/liburing/test/timeout.c +13 -8
- metadata +52 -8
- data/examples/http_server_multishot.rb +0 -57
- data/examples/http_server_simpler.rb +0 -34
data/test/test_ssl.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
__END__
|
4
|
+
|
5
|
+
require 'uringmachine/ssl'
|
6
|
+
require 'openssl'
|
7
|
+
require 'localhost'
|
8
|
+
|
9
|
+
class TestSSLContext < Minitest::Test
|
10
|
+
|
11
|
+
if false
|
12
|
+
def test_raises_with_invalid_keystore_file
|
13
|
+
ctx = UM::SSL::Context.new
|
14
|
+
|
15
|
+
exception = assert_raises(ArgumentError) { ctx.keystore = "/no/such/keystore" }
|
16
|
+
assert_equal("Keystore file '/no/such/keystore' does not exist", exception.message)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_raises_with_unreadable_keystore_file
|
20
|
+
ctx = UM::SSL::Context.new
|
21
|
+
|
22
|
+
File.stub(:exist?, true) do
|
23
|
+
File.stub(:readable?, false) do
|
24
|
+
exception = assert_raises(ArgumentError) { ctx.keystore = "/unreadable/keystore" }
|
25
|
+
assert_equal("Keystore file '/unreadable/keystore' is not readable", exception.message)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
else
|
30
|
+
def test_raises_with_invalid_key_file
|
31
|
+
ctx = UM::SSL::Context.new
|
32
|
+
|
33
|
+
exception = assert_raises(ArgumentError) { ctx.key = "/no/such/key" }
|
34
|
+
assert_equal("Key file '/no/such/key' does not exist", exception.message)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_raises_with_unreadable_key_file
|
38
|
+
ctx = UM::SSL::Context.new
|
39
|
+
|
40
|
+
File.stub(:exist?, true) do
|
41
|
+
File.stub(:readable?, false) do
|
42
|
+
exception = assert_raises(ArgumentError) { ctx.key = "/unreadable/key" }
|
43
|
+
assert_equal("Key file '/unreadable/key' is not readable", exception.message)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_raises_with_invalid_cert_file
|
49
|
+
ctx = UM::SSL::Context.new
|
50
|
+
|
51
|
+
exception = assert_raises(ArgumentError) { ctx.cert = "/no/such/cert" }
|
52
|
+
assert_equal("Cert file '/no/such/cert' does not exist", exception.message)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_raises_with_unreadable_cert_file
|
56
|
+
ctx = UM::SSL::Context.new
|
57
|
+
|
58
|
+
File.stub(:exist?, true) do
|
59
|
+
File.stub(:readable?, false) do
|
60
|
+
exception = assert_raises(ArgumentError) { ctx.key = "/unreadable/cert" }
|
61
|
+
assert_equal("Key file '/unreadable/cert' is not readable", exception.message)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_raises_with_invalid_key_pem
|
67
|
+
ctx = UM::SSL::Context.new
|
68
|
+
|
69
|
+
exception = assert_raises(ArgumentError) { ctx.key_pem = nil }
|
70
|
+
assert_equal("'key_pem' is not a String", exception.message)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_raises_with_unreadable_ca_file
|
74
|
+
ctx = UM::SSL::Context.new
|
75
|
+
|
76
|
+
File.stub(:exist?, true) do
|
77
|
+
File.stub(:readable?, false) do
|
78
|
+
exception = assert_raises(ArgumentError) { ctx.ca = "/unreadable/cert" }
|
79
|
+
assert_equal("ca file '/unreadable/cert' is not readable", exception.message)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_raises_with_invalid_cert_pem
|
85
|
+
ctx = UM::SSL::Context.new
|
86
|
+
|
87
|
+
exception = assert_raises(ArgumentError) { ctx.cert_pem = nil }
|
88
|
+
assert_equal("'cert_pem' is not a String", exception.message)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_raises_with_invalid_key_password_command
|
92
|
+
ctx = UM::SSL::Context.new
|
93
|
+
ctx.key_password_command = '/unreadable/decrypt_command'
|
94
|
+
|
95
|
+
assert_raises(Errno::ENOENT) { ctx.key_password }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class TestSSLServer < UMBaseTest
|
101
|
+
def setup
|
102
|
+
super
|
103
|
+
@port = assign_port
|
104
|
+
@ssl_ctx = create_ssl_ctx
|
105
|
+
end
|
106
|
+
|
107
|
+
def create_ssl_ctx
|
108
|
+
authority = Localhost::Authority.fetch
|
109
|
+
authority.server_context
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_ssl_accept
|
113
|
+
server_fd = machine.socket(UM::AF_INET, UM::SOCK_STREAM, 0, 0)
|
114
|
+
machine.bind(server_fd, '127.0.0.1', @port)
|
115
|
+
res = machine.listen(server_fd, 5)
|
116
|
+
assert_equal 0, res
|
117
|
+
assert_equal 0, machine.pending_count
|
118
|
+
|
119
|
+
fd = nil
|
120
|
+
sock = nil
|
121
|
+
|
122
|
+
reply = nil
|
123
|
+
t = Thread.new do
|
124
|
+
p 21
|
125
|
+
sleep 0.1
|
126
|
+
p 22
|
127
|
+
sock = TCPSocket.new('127.0.0.1', @port)
|
128
|
+
p 23
|
129
|
+
sleep 0.1
|
130
|
+
p 24
|
131
|
+
client = OpenSSL::SSL::SSLSocket.new(sock)
|
132
|
+
p 25
|
133
|
+
client.connect
|
134
|
+
p 26
|
135
|
+
client.write('foobar')
|
136
|
+
p 27
|
137
|
+
reply = client.read(8192)
|
138
|
+
p 28
|
139
|
+
end
|
140
|
+
|
141
|
+
p 11
|
142
|
+
fd = machine.accept(server_fd)
|
143
|
+
p 12
|
144
|
+
sock = machine.ssl_accept(fd, @ssl_ctx)
|
145
|
+
msg = +''
|
146
|
+
p 13
|
147
|
+
ret = sock.recv(msg, 8192)
|
148
|
+
p 14
|
149
|
+
sock.send("Hello: #{msg} (#{ret})", 0)
|
150
|
+
p 15
|
151
|
+
machine.close(fd)
|
152
|
+
|
153
|
+
assert_equal 'Hello: foobar (6)', reply
|
154
|
+
end
|
155
|
+
end
|