Skip to content

Commit a530fa7

Browse files
committed
🍒 pick 46636ca: ❌🔒 Add failing test for STARTTLS stripping [backport #664]
I'm putting this in its own commit to simplify testing across backports. Also, I'm taking a "belt-and-suspenders" approach, and I'm going to test that either of the two fixes passes the tests.
1 parent 6bf02ae commit a530fa7

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

test/net/imap/test_imap.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,43 @@ def test_starttls_stripping
153153
assert_equal(CA_FILE, imap.ssl_ctx.ca_file)
154154
assert_equal(OpenSSL::SSL::VERIFY_PEER, imap.ssl_ctx.verify_mode)
155155
end
156+
157+
def test_starttls_stripping_ok_sent_before_response
158+
# to coordinate between threads (better than sleep)
159+
server_to_client, client_to_server = Queue.new, Queue.new
160+
imap = nil
161+
server = create_tcp_server
162+
port = server.addr[1]
163+
start_server do
164+
sock = server.accept
165+
begin
166+
sock.print("* OK test server\r\n")
167+
assert_equal :send_malicious_response, client_to_server.pop
168+
sock.print("RUBY0001 OK hahaha, fooled you!\r\n")
169+
server_to_client << :malicious_response_sent
170+
sock.gets
171+
ensure
172+
sock.close
173+
server.close
174+
end
175+
end
176+
begin
177+
imap = Net::IMAP.new("localhost", :port => port)
178+
client_to_server << :send_malicious_response
179+
assert_equal :malicious_response_sent, server_to_client.pop
180+
sleep 0.010 # to be sure the network buffers have flushed, etc
181+
assert_raise(Net::IMAP::InvalidResponseError) do
182+
imap.starttls(:ca_file => CA_FILE)
183+
end
184+
assert imap.disconnected?
185+
ensure
186+
imap.disconnect if imap && !imap.disconnected?
187+
end
188+
assert_equal false, imap.tls_verified?
189+
assert_equal({ca_file: CA_FILE}, imap.ssl_ctx_params)
190+
assert_equal(CA_FILE, imap.ssl_ctx.ca_file)
191+
assert_equal(OpenSSL::SSL::VERIFY_PEER, imap.ssl_ctx.verify_mode)
192+
end
156193
end
157194

158195
def start_server

0 commit comments

Comments
 (0)