Commit graph

481 commits

Author SHA1 Message Date
Jeremy Evans
7529c53891 [ruby/net-http] Do not set SNI hostname if connecting to IP address
RFC 6066, section 3, explicitly disallows the use of an IP address
as an SNI server name.  So check if the connection is being made
to an IP address using the resolv regexps, and do not set an SNI
hostname in that case.

Recent changes to LibreSSL make it more strictly follow RFC 6066,
resulting an s.hostname= raising an error if passed an IP address.
When such verions of LibreSSL are used, this change not only fixes
the net/http tests, it also fixes tests for webrick and open-uri,
which both make SSL connections to 127.0.0.1 using net/http in
their tests.

Avoid warning in the openssl extension by unsetting
@ssl_context.verify_hostname if connecting to an IP address.
Make changes so that the post_connection_check still happens
when connecting to an IP address, which is necessary to keep
checking that the certificate returned includes the IP address,
which one of the tests depends on.

Revert the previous change that modified the regexp used for
checking the error message.

fa68e64bee
2022-02-03 05:10:21 +09:00
Kazuhiro NISHIYAMA
549af505c5 [ruby/net-http] Remove redundant MJIT condition
ref da0f67c038

dbeb5f1c8f
2022-01-17 17:11:27 +09:00
Kazuhiro NISHIYAMA
b9b6377401 [ruby/net-http] Fix unescaped . in Regexp
Use `include?` instead.

05022744a9
2022-01-14 08:16:37 +09:00
Hiroshi SHIBATA
9b3dcf193c [ruby/net-http] Use omit instead of skip for test-unit
843d4548de
2022-01-11 21:45:34 +09:00
Jeremy Evans
67612dadbc [ruby/net-http] Handle invalid use of IP addresses in SNI
Server Name Indication does not allow IP addresses (RFC 6066, section 3:
`Literal IPv4 and IPv6 addresses are not permitted in "HostName".`).

Recent versions of LibreSSL enforce this restriction, which raises
when setting the hostname to an IP address (s.hostname=), before
attempting to setup the SSL connection.

Since the certificate used in the test is already for localhost,
we cannot connect to localhost.  However, as all the test does is
check for a specific exception, just modify the regexp used so it
handles both cases.

6ab399db45
2022-01-04 08:25:58 +09:00
Takashi Kokubun
1a63468831
Prepare for removing RubyVM::JIT (#5262) 2021-12-13 23:07:46 -08:00
Jeremy Evans
fceaa6886b Sync test_http_request.rb after fix to net-http 2021-11-15 09:31:44 -08:00
Jeremy Evans
f1c3fc273d [ruby/net-http] Fix tests after change to allow HEAD to send Accept-Encoding
ca7bb8c51c
2021-11-16 02:21:57 +09:00
Koichi Sasada
b5531adf41 quick fix for test_initialize_HEAD
52ab9bbee9 makes a failure.

```
  1) Failure:
HTTPRequestTest#test_initialize_HEAD [/tmp/ruby/v3/src/trunk/test/net/http/test_http_request.rb:53]:
<{"accept"=>["*/*"], "user-agent"=>["Ruby"]}> expected but was
<{"accept-encoding"=>["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],
 "accept"=>["*/*"],
 "user-agent"=>["Ruby"]}>.
```

I'm not sure it is correct, so please review later.
2021-11-11 18:04:00 +09:00
Kazuki Yamaguchi
5f2c4e344d [ruby/net-http] Reset keep_alive timer on new connection
The last_communicated timestamp is for HTTP persistent connection, to
decide whether the current TCP connection may be reused for the
subsequent requests or not. Naturally, the timer must be reset if the
connection is recreated since it is no longer relevant.

0a013de42d
2021-11-04 20:44:04 +09:00
Hiroshi SHIBATA
2bc85766c0
[ruby/net-http] Use omit instead of skip for test-unit
5bb14fd3bc
2021-09-11 10:25:34 +09:00
Hiroshi SHIBATA
f8ad51dd9a Fix test failure of 60b02db516 with Windows 2021-07-29 20:54:54 +09:00
Miguel Teixeira
60b02db516 [ruby/net-http] Enforce write timeout when body_stream is used
The existing implementation of `Net::HTTP#write_timeout` relies on
`Net::BefferedIO` to trigger the `Net::WriteTimeout` error. This commit
changes `send_request_with_body_stream` to remove the optimization that
was making `Net::HTTP#write_timeout` not work when `body_stream` is
used.

Open issue:
https://bugs.ruby-lang.org/issues/17933

a0fab1ab52
2021-07-29 15:53:54 +09:00
Hiroshi SHIBATA
be2e2b4805 Promote net-smtp to the bundled gems 2021-05-27 14:42:11 +09:00
Hiroshi SHIBATA
aa9726f7b9 Promote net-pop to the bundled gems 2021-05-27 14:42:11 +09:00
Hiroshi SHIBATA
d5bc6b2337 Promote net-imap to the bundled gems 2021-05-27 14:42:11 +09:00
Hiroshi SHIBATA
e49c998d1e Promote net-ftp to the bundled gems 2021-05-27 14:42:11 +09:00
Kazuki Yamaguchi
364044e090 [ruby/net-http] Do not require stringio
It is not used in net/http library code since commit 15ccd0118c13
(r36473 in ruby svn trunk, 2012).

require's in test suite are also cleaned up.

996d18a43f
2021-05-06 15:58:41 +09:00
nicholas a. evans
337c0e312b
[ruby/net-imap] Move UTF7 & datetime formatting to net/imap/data_encoding
Partially implements #10.

0d43c5e856
2021-05-06 15:20:34 +09:00
nicholas a. evans
912f39b2c3
[ruby/net-imap] Update AUTH=PLAIN to be a little closer to RFC4616
* Add authzid support
* must not contain NULL chars
* improve rdoc

a587fc71b7
2021-05-06 15:20:34 +09:00
MSP-Greg
370949aad6 test/net/ftp/test_ftp.rb - fix intermittent MinGW failure
Fixes intermittent error as below:

[242/838] 5316=test_ftp
#<Thread:0x0000020aa8733f20 D:/a/ruby/ruby/src/test/net/ftp/test_ftp.rb:2532 run> terminated with exception (report_on_exception is true):
D:/a/ruby/ruby/src/tool/lib/minitest/unit.rb:199:in `assert': Expected #<Errno::ECONNRESET: An existing connection was forcibly closed by the remote host.> to be nil. (MiniTest::Assertion)
	from D:/a/ruby/ruby/src/tool/lib/test/unit/core_assertions.rb:504:in `assert'
	from D:/a/ruby/ruby/src/tool/lib/minitest/unit.rb:299:in `assert_nil'
	from D:/a/ruby/ruby/src/test/net/ftp/test_ftp.rb:430:in `ensure in block in test_list_read_timeout_exceeded'
	from D:/a/ruby/ruby/src/test/net/ftp/test_ftp.rb:431:in `block in test_list_read_timeout_exceeded'
	from D:/a/ruby/ruby/src/test/net/ftp/test_ftp.rb:2539:in `block in create_ftp_server'
D:/a/ruby/ruby/src/test/net/ftp/test_ftp.rb:426:in `write': An existing connection was forcibly closed by the remote host. (Errno::ECONNRESET)
	from D:/a/ruby/ruby/src/test/net/ftp/test_ftp.rb:426:in `print'
	from D:/a/ruby/ruby/src/test/net/ftp/test_ftp.rb:426:in `block (2 levels) in test_list_read_timeout_exceeded'
	from D:/a/ruby/ruby/src/test/net/ftp/test_ftp.rb:420:in `each'
	from D:/a/ruby/ruby/src/test/net/ftp/test_ftp.rb:420:in `each_with_index'
	from D:/a/ruby/ruby/src/test/net/ftp/test_ftp.rb:420:in `block in test_list_read_timeout_exceeded'
	from D:/a/ruby/ruby/src/test/net/ftp/test_ftp.rb:2539:in `block in create_ftp_server'
2021-05-05 08:49:16 +12:00
Yusuke Endoh
113ddf4d1d test/net/imap/test_imap.rb: wait a moment before socket is closed
to try to suppress a failure on Solaris. This is the same as
19504d115d

20210504T070007Z.fail.html.gz
```
  1) Error:
IMAPTest#test_idle_done_not_during_idle:
Errno::EINVAL: Invalid argument - connect(2) for [::1]:33839
    /export/home/chkbuild/chkbuild-sunc/tmp/build/20210504T070007Z/ruby/.ext/common/socket.rb:1214:in `__connect_nonblock'
    /export/home/chkbuild/chkbuild-sunc/tmp/build/20210504T070007Z/ruby/.ext/common/socket.rb:1214:in `connect_nonblock'
    /export/home/chkbuild/chkbuild-sunc/tmp/build/20210504T070007Z/ruby/.ext/common/socket.rb:56:in `connect_internal'
    /export/home/chkbuild/chkbuild-sunc/tmp/build/20210504T070007Z/ruby/.ext/common/socket.rb:137:in `connect'
    /export/home/chkbuild/chkbuild-sunc/tmp/build/20210504T070007Z/ruby/.ext/common/socket.rb:642:in `block in tcp'
    /export/home/chkbuild/chkbuild-sunc/tmp/build/20210504T070007Z/ruby/.ext/common/socket.rb:227:in `each'
    /export/home/chkbuild/chkbuild-sunc/tmp/build/20210504T070007Z/ruby/.ext/common/socket.rb:227:in `foreach'
    /export/home/chkbuild/chkbuild-sunc/tmp/build/20210504T070007Z/ruby/.ext/common/socket.rb:632:in `tcp'
    /export/home/chkbuild/chkbuild-sunc/tmp/build/20210504T070007Z/ruby/lib/net/imap.rb:1223:in `tcp_socket'
    /export/home/chkbuild/chkbuild-sunc/tmp/build/20210504T070007Z/ruby/lib/net/imap.rb:1180:in `initialize'
    /export/home/chkbuild/chkbuild-sunc/tmp/build/20210504T070007Z/ruby/test/net/imap/test_imap.rb:289:in `new'
    /export/home/chkbuild/chkbuild-sunc/tmp/build/20210504T070007Z/ruby/test/net/imap/test_imap.rb:289:in `test_idle_done_not_during_idle'
```
2021-05-04 19:03:26 +09:00
MSP-Greg
5a42ef496a Fix test/net/http/test_https.rb host naming for Windows 2021-05-04 08:53:58 +09:00
Nobuyoshi Nakada
14ee263505
Workaround failures on Windows 2021-05-04 00:59:29 +09:00
Yusuke Endoh
19504d115d test/net/smtp/test_smtp.rb: wait a moment before socket is closed
On Solaris, Socket.tcp seems to fail with EINVAL if the server closes
the connection immediately after accpeted. I think this is a bug of
Socket.tcp, but seems difficult to fix soon.

20210429T100007Z.fail.html.gz
```
  1) Failure:
Net::TestSMTP#test_eof_error_backtrace [/export/home/chkbuild/chkbuild-sunc/tmp/build/20210429T100007Z/ruby/test/net/smtp/test_smtp.rb:193]:
[ruby-core:78550] [Bug #13018].
[EOFError] exception expected, not #<Net::ReadTimeout: Net::ReadTimeout>.
```
2021-04-30 01:36:04 +09:00
Lukas Eipert
842f00f452 [ruby/net-http] Decode user and password from env configured proxy
If someone sets an env variable defining a http_proxy, containing a
username / password with percent-encoded characters, then the resulting
base64 encoded auth header will be wrong.

For example, suppose a username is `Y\X` and the password is `R%S] ?X`.
Properly URL encoded the proxy url would be:

    http://Y%5CX:R%25S%5D%20%3FX@proxy.example:8000

The resulting proxy auth header should be: `WVxYOlIlU10gP1g=`, but the
getters defined by ruby StdLib `URI` return a username `Y%5CX` and
password `R%25S%5D%20%3FX`, resulting in `WSU1Q1g6UiUyNVMlNUQlMjAlM0ZY`.
As a result the proxy will deny the request.

Please note that this is my first contribution to the ruby ecosystem, to
standard lib especially and I am not a ruby developer.

References:

- https://gitlab.com/gitlab-org/gitlab/-/issues/289836
- https://bugs.ruby-lang.org/projects/ruby-master/repository/trunk/revisions/58461
- https://bugs.ruby-lang.org/issues/17542

e57d4f38aa
2021-04-28 11:01:23 +09:00
Yusuke Endoh
734557498f test/net/ftp/test_ftp.rb: Use RubyVM::JIT instead of RubyVM::MJIT 2021-04-28 09:10:58 +09:00
Yusuke Endoh
8e2ac2140d test/net/ftp/test_ftp.rb: reduce the size of a long response
"9" * 999999999 (about 1 GB) was too large for some CI servers.
This commit changes the size to 999999 (about 1 MB).

20210427T141707Z.fail.html.gz
20210427T145408Z.fail.html.gz
2021-04-28 03:12:48 +09:00
Yusuke Endoh
fe11031b67 test/net/ftp/test_ftp.rb: remove unused variable 2021-04-28 02:27:58 +09:00
Shugo Maeda
2670509ebb [ruby/net-ftp] Add test cases
865232bb2a
2021-04-27 21:22:42 +09:00
Shugo Maeda
4ae27d8075
[ruby/net-ftp] Reduce resource cosumption of Net::FTP::TIME_PARSER
Reported by Alexandr Savca as a DoS vulnerability, but Net::FTP is a
client library and the impact of the issue is low, so I have decided
to fix it as a normal issue.
Based on patch by nobu.

a93af636f8
2021-04-27 21:21:33 +09:00
Jeremy Evans
990baec411 [ruby/net-ftp] Close the passive connection data socket if there is an error setting up the transfer
Previously, the connection leaked in this case.  This uses
begin/ensure and checking for an error in the ensure block.

An alternative approach would be to not even perform the
connection until after the RETR (or other) command has been
sent.  However, I'm not sure all FTP servers support that.
The current behavior is:

* Send (PASV/EPSV)
* Connect to the host/port returned in 227/229 reply
* Send (RETR/other command)

Changing it to connect after the RETR could break things.
FTP servers might expect that the client has already
connected before sending the RETR.  The alternative
approach is more likely to introduce backwards compatibility
issues, compared to the begin/ensure approach taken here.

Fixes Ruby Bug 17027

6e8535f076
2021-04-27 21:21:00 +09:00
Hiroshi SHIBATA
fb819d9331 [ruby/net-ftp] Re-apply 827e471d438fdec1ae329afb5912b8e06d534823
3ca80368c4
2021-04-27 21:19:14 +09:00
Hiroshi SHIBATA
674760316c
Merge net-imap-0.2.0 2021-04-22 14:37:45 +09:00
Kazuhiro NISHIYAMA
9de68a5221
Fix a warning
```
.../ruby/test/net/http/test_httpresponse.rb:81: warning: constant RubyVM::MJIT is deprecated
```
2021-01-23 10:52:17 +09:00
Nobuyoshi Nakada
d961f14df3 [ruby/net-http] RubyVM::MJIT is deprecated, prefer RubyVM::JIT now
abc6ea1877
2021-01-21 20:50:23 +09:00
Takashi Kokubun
e1fee7f949
Rename RubyVM::MJIT to RubyVM::JIT
because the name "MJIT" is an internal code name, it's inconsistent with
--jit while they are related to each other, and I want to discourage future
JIT implementation-specific (e.g. MJIT-specific) APIs by this rename.

[Feature #17490]
2021-01-13 22:46:51 -08:00
Takashi Kokubun
15c129d087
Try increasing SMTP's read_timeout for --jit-wait
for random hangs like:
http://ci.rvm.jp/results/trunk-mjit-wait@phosphorus-docker/3302796
http://ci.rvm.jp/results/trunk-mjit-wait@phosphorus-docker/3302188
http://ci.rvm.jp/results/trunk-mjit-wait@phosphorus-docker/3301293
2020-12-29 22:02:48 -08:00
Nobuyoshi Nakada
c7530f0d56
Wait testing/helper threads to terminate 2020-12-13 13:39:57 +09:00
Benoit Daloze
b4ec4a41c2 Guard all accesses to RubyVM::MJIT with defined?(RubyVM::MJIT) &&
* Otherwise those tests, etc cannot run on alternative Ruby implementations.
2020-12-04 16:45:54 +01:00
MSP-Greg
64926d5007 test/net/smtp - use TCPSocket when UNIXSocket unavailable 2020-11-18 08:13:10 +09:00
Hiroshi SHIBATA
0683912db8 Skip tests related TLS with Windows platform. 2020-11-17 18:05:15 +09:00
Hiroshi SHIBATA
cada6d85d0
Import net-smtp-0.2.0 from https://github.com/ruby/net-smtp 2020-11-17 14:17:45 +09:00
Yusuke Endoh
b271bd73e0 test/net/smtp/test_smtp.rb: Stop io leaks
`make test-all` was very noisy by warnings like

```
Leaked file descriptor: Net::TestSMTP#test_start_with_position_argument: 6 : #<TCPSocket:fd 6, AF_INET, 127.0.0.1, 43770>
```
2020-09-26 00:20:06 +09:00
Yusuke Endoh
0c611d7f4f test/net/http/test_https.rb: The test logic was buggy
The expected certs must be `[CA_CERT, SERVER_CERT]` before 1.1.1g and
`[SERVER_CERT]` after 1.1.1h.
2020-09-24 19:39:51 +09:00
Yusuke Endoh
1917afa34b test/net/http/test_https.rb: the order of verify_callback seems to vary
... depending upon the environment.
2020-09-24 19:34:16 +09:00
Yusuke Endoh
07786edd66 test/net/http/test_https.rb: Stop the error due to openssl 1.1.1h
On some environments that uses OpenSSL 1.1.1h, the two tests now fail.

20200924T062352Z.fail.html.gz
1159288773

```
  1) Failure:
TestNetHTTPS#test_get [/data/data/com.termux/files/home/cb/tmp/build/20200924T062352Z/ruby/test/net/http/test_https.rb:47]:
<"0\x82\x03\xED0\x82\x02\xD5\xA0\x03..."> expected but was
<"0\x82\x03\xE30\x82\x02\xCB\xA0\x03...">.
```

Not sure why, but verify_callback now seems to receive only SERVER_CERT
but not CA_CERT.
It would be good to investigate the issue furthermore, but tentatively,
I want to stop the failures.
2020-09-24 19:20:17 +09:00
TOMITA Masahiro
141404e898 [ruby/net-smtp] Net::SMTP.start arguments are keyword arguments
The helo argument is not important, but the helo argument must be
specified to specify the user and secret arguments.
If helo, user, secret, and authtype arguments are keyword arguments,
it is not necessary to specify the helo argument.

269774deac
2020-09-14 17:23:41 +09:00
TOMITA Masahiro
888e04ae05 [ruby/net-smtp] TLS should not check the host name by default.
In tlsconnect(), the host name is checked when
@ssl_context.verify_mode is not OpenSSL::SSL::VERIFY_NONE, but the
verify_mode of @ssl_context generated by default is nil.

bde75a15b5
2020-09-14 17:22:35 +09:00
Jeremy Evans
85dc570893 [ruby/net-http] Fix SSL session reuse test with LibreSSL 3.2+
5ae9620fbc
2020-08-03 18:56:14 +09:00