Skip to content

Commit 46636ca

Browse files
committed
βŒπŸ”’ Add failing test for STARTTLS stripping
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 e3b0105 commit 46636ca

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
@@ -168,6 +168,43 @@ def test_starttls_stripping_not_ok
168168
assert_equal(CA_FILE, imap.ssl_ctx.ca_file)
169169
assert_equal(OpenSSL::SSL::VERIFY_PEER, imap.ssl_ctx.verify_mode)
170170
end
171+
172+
def test_starttls_stripping_ok_sent_before_response
173+
# to coordinate between threads (better than sleep)
174+
server_to_client, client_to_server = Queue.new, Queue.new
175+
imap = nil
176+
server = create_tcp_server
177+
port = server.addr[1]
178+
start_server do
179+
sock = server.accept
180+
begin
181+
sock.print("* OK test server\r\n")
182+
assert_equal :send_malicious_response, client_to_server.pop
183+
sock.print("RUBY0001 OK hahaha, fooled you!\r\n")
184+
server_to_client << :malicious_response_sent
185+
sock.gets
186+
ensure
187+
sock.close
188+
server.close
189+
end
190+
end
191+
begin
192+
imap = Net::IMAP.new("localhost", :port => port)
193+
client_to_server << :send_malicious_response
194+
assert_equal :malicious_response_sent, server_to_client.pop
195+
sleep 0.010 # to be sure the network buffers have flushed, etc
196+
assert_raise(Net::IMAP::InvalidResponseError) do
197+
imap.starttls(:ca_file => CA_FILE)
198+
end
199+
assert imap.disconnected?
200+
ensure
201+
imap.disconnect if imap && !imap.disconnected?
202+
end
203+
assert_equal false, imap.tls_verified?
204+
assert_equal({ca_file: CA_FILE}, imap.ssl_ctx_params)
205+
assert_equal(CA_FILE, imap.ssl_ctx.ca_file)
206+
assert_equal(OpenSSL::SSL::VERIFY_PEER, imap.ssl_ctx.verify_mode)
207+
end
171208
end
172209

173210
def start_server

0 commit comments

Comments
Β (0)