Commit graph

63 commits

Author SHA1 Message Date
Hiroshi SHIBATA
2a12e4ffec To avoid fd leak with fetch request for SSL server 2024-07-17 17:37:57 +09:00
MSP-Greg
9f4b45fbf7 [ruby/net-http] test_https.rb - fix test_session_reuse_but_expire
5544243c41
2024-07-11 01:22:10 +00:00
git
8c69caa495 * append newline at EOF. [ci skip] 2024-07-10 23:06:20 +00:00
Hiroshi SHIBATA
6428536146 [ruby/net-http] Split test class because TCPServer couldn't accept localhost and 127.0.0.1 both
749a1b3197
2024-07-10 23:06:08 +00:00
Hiroshi SHIBATA
87a45af105 [ruby/net-http] Removed server-side log test
9c16c383ce
2024-07-10 23:06:07 +00:00
Hiroshi SHIBATA
5e6f04abc8 [ruby/net-http] Fix wrong hostname with test_max_version test
f00d198433
2024-07-10 23:06:07 +00:00
Xi Ruoyao
03f8477566 [ruby/net-http] Skip test_session_reuse_but_expire with OpenSSL 3.3
OpenSSL 3.3.0 9 Apr 2024 is also broken.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>

ab525c956d
2024-04-25 08:01:53 +00:00
NARUSE, Yui
64b6a018a3
Fix test session reuse but expire (#9824)
* OpenSSL 3.2.1 30 Jan 2024 is also broken

Import 4506461072 from ruby_3_3 branch
tentatively.
2024-02-07 10:59:59 +09:00
NARUSE, Yui
bc79229be9 Show OpenSSL version in the error message of assert_equal 2024-02-03 19:39:17 +09:00
Nobuyoshi Nakada
1b7376423d
Omit test_session_reuse_but_expire if OpenSSL 3.2.0 2023-11-26 01:18:48 +09:00
Takashi Kokubun
de37b78050 Omit a broken https test on MinGW
This started to reliably fail on MinGW at an irrelevant commit:
1899730212
1900010422
1900561380
1900584459
1900664949
1900710044
1901200064

So this failure is not detecting a new bug. Let's skip this until we fix
this test for MinGW.
2023-11-24 21:43:34 -08:00
Jeremy Evans
3dec5dc346 [ruby/net-http] Force TLS version to 1.2 when using LibreSSL
This comment previously specified TLS 1.2, but actually set the
version to TLS 1.0.  LibreSSL 3.8.1 (included in OpenBSD 7.4)
dropped support for TLS 1.0/1.1 for security reasons, which
broke this test.  Switch the test to use TLS 1.2 as documented
so it will continue to work on OpenBSD 7.4+.

97be4de53a
2023-10-16 20:23:50 +00:00
Karol Bucek
cf73cf5981 [ruby/net-http] Feature detect to make net/http usable with JRuby
Handle missing session_new_cb= and do not call
session_cache_mode=, as JRuby SSL does not support
these methods.

3237ef4d8c
2022-04-20 13:01:08 +09:00
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
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
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
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
Jeremy Evans
85dc570893 [ruby/net-http] Fix SSL session reuse test with LibreSSL 3.2+
5ae9620fbc
2020-08-03 18:56:14 +09:00
Jeremy Evans
20eb9e98b6 [ruby/net-http] Switch invalid server name format
invalid_servername is not a valid name in an SSL request due to
the use of the underscore, and LibreSSL 3.2.0 will raise an
exception for this.  These tests are not testing the allowed
characters in the server name, but how net/http handles cases where
the server name provided does not match the IP address you are
trying to connect to, so I think it's better to just modify the
tests to use a correct format.

While here, fix a typo in a test name, and use better code in the
ensure block so the same test doesn't issue both a failure and an
error.

0e8dc91120
2020-08-03 18:55:44 +09:00
Nobuyoshi Nakada
f08cd708b1
Fixed FD leak 2020-03-04 23:26:57 +09:00
Hiroshi SHIBATA
9cb1ffaa5c
Promote net-http to the default gems.
test/net/http/test_https.rb: rename fixture methods to read_fixture
  because it conflicts with test-unit gem.
2020-02-21 21:21:14 +09:00
Yuta Iwama
be6931f7f7 Add #verify_hostname= and #verify_hostname to skip hostname verification (#2858)
According to https://github.com/ruby/openssl/pull/60,

> Currently an user who wants to do the hostname verification needs to
call SSLSocket#post_connection_check explicitly after the TLS connection
is established.

if an user who wants to skip the hostname verification,
SSLSocket#post_connection_check doesn't need to be called

https://bugs.ruby-lang.org/issues/16555
2020-01-23 17:23:17 +09:00
NARUSE, Yui
af11efd377 fix ipaddr parameter of Net::HTTP.start to support proxy
54072e329c
2019-12-10 19:12:21 +09:00
Yusuke Endoh
660388f6c5 test/net/http/test_https.rb (test_get_SNI_failure): stop proxy settings
Because the test fails under HTTP proxy settings.

20191210T000004Z.fail.html.gz
```
  1) Failure:
TestNetHTTPS#test_get_SNI_failure [/export/home/users/chkbuild/cb-gcc/tmp/build/20191210T000004Z/ruby/test/net/http/test_https.rb:81]:
[OpenSSL::SSL::SSLError] exception expected, not #<Net::HTTPServerException: 403 "Forbidden">.
```

The new SNI feature introduced at 54072e329c may need to be improved for
HTTP proxy environment.
2019-12-10 09:41:33 +09:00
NARUSE, Yui
54072e329c Add ipaddr optional parameter to Net::HTTP#start
to replace the address for TCP/IP connection [Feature #5180]

There're 3 layers of hostname:
* host address for TCP/IP
* TLS server name
* HTTP Host header value
To test DNS round robin or check server certificate from server local,
people sometimes want to connect server with given IP address but keep
TLS server name and HTTP Host header value.

closes [Feature #15215]
closes https://github.com/ruby/ruby/pull/1893
closes https://github.com/ruby/ruby/pull/1977
2019-12-09 20:21:49 +09:00
rhe
33dd5d6970 net/http, net/ftp: skip SSL/TLS session resumption tests
Due to a bug in OpenSSL 1.1.0h[1] (it's only in this specific version;
it was introduced just before the release and is already fixed in their
stable branch), the callback set by SSLContext#session_new_cb= does not
get called for clients, making net/http and net/ftp not attempt session
resumption.

Let's disable the affected test cases for now. Another option would be
to fallback to using SSLSocket#session as we did before r64234. But
since only a single version is affected and hopefully a new stable
version containing the fix will be released in near future, I chose not
to add such workaround code to lib/.

[1] https://github.com/openssl/openssl/pull/5967

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-09 10:00:19 +00:00
rhe
1dfc377ae3 net/http, net/ftp: fix session resumption with TLS 1.3
When TLS 1.3 is in use, the session ticket may not have been sent yet
even though a handshake has finished. Also, the ticket could change if
multiple session ticket messages are sent by the server. Use
SSLContext#session_new_cb instead of calling SSLSocket#session
immediately after a handshake. This way also works with earlier protocol
versions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-08 14:13:55 +00:00
rhe
55953e374d openssl: revert changes in SSLContext#{min,max}_version= in r60310
And adapt a net/http test to their old behavior.  [ruby-core:83491]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60906 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-25 14:12:07 +00:00
naruse
9ba147dce6 OpenSSL may show the different error message
d02211c9da (commitcomment-25119729)
From: MSP-Greg <MSP-Greg@users.noreply.github.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 08:28:05 +00:00
naruse
d02211c9da ignore server side error
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60316 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 16:44:56 +00:00
naruse
b39132e993 Revert "ignore server side error"
This reverts commit r60314.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60315 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 16:44:56 +00:00
naruse
facccd3129 ignore server side error
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 16:43:54 +00:00
naruse
800da42cc6 fic expected error message
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 16:34:34 +00:00
naruse
dcea9198a9 Introduce Net::HTTP#min_version/max_version [Feature #9450]
Set SSL minimum/maximum version.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 16:25:22 +00:00
rhe
df769d9dc9 net/http: don't use OpenSSL::TestUtils from test code
Make test code independent of test/openssl/utils.rb. The development of
openssl library has moved to a separate repository and
OpenSSL::TestUtils may be modified at any time.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56934 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-29 15:48:45 +00:00
naruse
3e92b635fb Add frozen_string_literal: false for all files
When you change this to true, you may need to add more tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16 05:07:31 +00:00
nobu
b392fd5c55 test_https.rb: skip old OpenSSL
* test/net/http/test_https.rb (TestNetHTTPS): also depends on
  test/openssl/utils.rb

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-13 07:08:18 +00:00
usa
bf4b7f3b8c * test/net/http/test_https.rb
(TestNetHTTPS#test_certificate_verify_failure): on Windows,
  Errno::ECONNRESET will be raised when the verify is failure at the
  client side, and it'll be eaten by WEBrick.

* test/open-uri/test_ssl.rb (TestOpenURISSL#test_validation_failure):
  ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-09 17:51:43 +00:00
naruse
d3236ba3b4 add test for r48563
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-26 08:22:27 +00:00
akr
070c310e87 * test/webrick: Store log in an array.
* test/net/http: Ditto.

* test/open-uri: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48341 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-09 11:51:06 +00:00
akr
0babd24827 * test/net/http: Examine webrick log.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48332 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-09 02:49:13 +00:00
naruse
25d3fc8823 suppress warnings
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-05 19:08:26 +00:00
akr
4565cd66ed Close FDs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-30 15:03:34 +00:00
akr
6895e77ffc * test/net/http/utils.rb (spawn_server): Specify zero for port to
avoid reusing an allocated port.

* test/net/http/test_http.rb: Don't specify port here.

* test/net/http/test_https.rb: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-19 12:29:46 +00:00
naruse
b238b5be91 Use 0 as port like #6766 [Bug #6959]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-09-01 20:46:27 +00:00