Skip to content

Commit f96ab6c

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 2068d46 commit f96ab6c

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

test/net/imap/test_imap.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,40 @@ def test_starttls_stripping
113113
imap
114114
end
115115
end
116+
117+
def test_starttls_stripping_ok_sent_before_response
118+
# to coordinate between threads (better than sleep)
119+
server_to_client, client_to_server = Queue.new, Queue.new
120+
imap = nil
121+
server = create_tcp_server
122+
port = server.addr[1]
123+
start_server do
124+
sock = server.accept
125+
begin
126+
sock.print("* OK test server\r\n")
127+
assert_equal :send_malicious_response, client_to_server.pop
128+
sock.print("RUBY0001 OK hahaha, fooled you!\r\n")
129+
server_to_client << :malicious_response_sent
130+
sock.gets
131+
ensure
132+
sock.close
133+
server.close
134+
end
135+
end
136+
begin
137+
imap = Net::IMAP.new("localhost", :port => port)
138+
client_to_server << :send_malicious_response
139+
assert_equal :malicious_response_sent, server_to_client.pop
140+
sleep 0.010 # to be sure the network buffers have flushed, etc
141+
assert_raise(Net::IMAP::InvalidResponseError) do
142+
imap.starttls(:ca_file => CA_FILE)
143+
end
144+
assert imap.disconnected?
145+
ensure
146+
imap.disconnect if imap && !imap.disconnected?
147+
end
148+
assert imap.disconnected?
149+
end
116150
end
117151

118152
def start_server

0 commit comments

Comments
 (0)