summaryrefslogtreecommitdiff
path: root/test/uri
diff options
context:
space:
mode:
Diffstat (limited to 'test/uri')
-rw-r--r--test/uri/test_common.rb19
-rw-r--r--test/uri/test_ftp.rb10
-rw-r--r--test/uri/test_generic.rb24
-rw-r--r--test/uri/test_http.rb8
-rw-r--r--test/uri/test_ldap.rb14
-rw-r--r--test/uri/test_parser.rb37
-rw-r--r--test/uri/test_ws.rb8
-rw-r--r--test/uri/test_wss.rb8
8 files changed, 81 insertions, 47 deletions
diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb
index 038f483a83..1df19e6968 100644
--- a/test/uri/test_common.rb
+++ b/test/uri/test_common.rb
@@ -3,10 +3,7 @@ require 'test/unit'
require 'envutil'
require 'uri'
-module URI
-
-
-class TestCommon < Test::Unit::TestCase
+class URI::TestCommon < Test::Unit::TestCase
def setup
end
@@ -112,6 +109,17 @@ class TestCommon < Test::Unit::TestCase
assert_raise(NoMethodError) { Object.new.URI("http://www.ruby-lang.org/") }
end
+ def test_parse_timeout
+ pre = ->(n) {
+ 'https://example.com/dir/' + 'a' * (n * 100) + '/##.jpg'
+ }
+ assert_linear_performance((1..3).map {|i| 10**i}, rehearsal: 1000, pre: pre) do |uri|
+ assert_raise(URI::InvalidURIError) do
+ URI.parse(uri)
+ end
+ end
+ end
+
def test_encode_www_form_component
assert_equal("%00+%21%22%23%24%25%26%27%28%29*%2B%2C-.%2F09%3A%3B%3C%3D%3E%3F%40" \
"AZ%5B%5C%5D%5E_%60az%7B%7C%7D%7E",
@@ -281,6 +289,3 @@ class TestCommon < Test::Unit::TestCase
private
def s(str) str.force_encoding(Encoding::Windows_31J); end
end
-
-
-end
diff --git a/test/uri/test_ftp.rb b/test/uri/test_ftp.rb
index 0eec984db8..f45bb0667c 100644
--- a/test/uri/test_ftp.rb
+++ b/test/uri/test_ftp.rb
@@ -2,10 +2,7 @@
require 'test/unit'
require 'uri/ftp'
-module URI
-
-
-class TestFTP < Test::Unit::TestCase
+class URI::TestFTP < Test::Unit::TestCase
def setup
end
@@ -29,7 +26,7 @@ class TestFTP < Test::Unit::TestCase
end
def test_parse_invalid
- assert_raise(InvalidURIError){URI.parse('ftp:example')}
+ assert_raise(URI::InvalidURIError) {URI.parse('ftp:example')}
end
def test_paths
@@ -62,6 +59,3 @@ class TestFTP < Test::Unit::TestCase
end
end
end
-
-
-end
diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb
index fdb405e396..8209363b82 100644
--- a/test/uri/test_generic.rb
+++ b/test/uri/test_generic.rb
@@ -24,7 +24,19 @@ class URI::TestGeneric < Test::Unit::TestCase
assert_equal "file:///foo", URI("file:///foo").to_s
assert_equal "postgres:///foo", URI("postgres:///foo").to_s
- assert_equal "http:/foo", URI("http:///foo").to_s
+ assert_equal "http:///foo", URI("http:///foo").to_s
+ assert_equal "http:/foo", URI("http:/foo").to_s
+
+ uri = URI('rel_path')
+ assert_equal "rel_path", uri.to_s
+ uri.scheme = 'http'
+ assert_equal "http:rel_path", uri.to_s
+ uri.host = 'h'
+ assert_equal "http://h/rel_path", uri.to_s
+ uri.port = 8080
+ assert_equal "http://h:8080/rel_path", uri.to_s
+ uri.host = nil
+ assert_equal "http::8080/rel_path", uri.to_s
end
def test_parse
@@ -157,6 +169,12 @@ class URI::TestGeneric < Test::Unit::TestCase
assert_equal(nil, url.user)
assert_equal(nil, url.password)
assert_equal(nil, url.userinfo)
+
+ # sec-156615
+ url = URI.parse('http:////example.com')
+ # must be empty string to identify as path-abempty, not path-absolute
+ assert_equal('', url.host)
+ assert_equal('http:////example.com', url.to_s)
end
def test_parse_scheme_with_symbols
@@ -970,6 +988,10 @@ class URI::TestGeneric < Test::Unit::TestCase
end
end
+ def test_split
+ assert_equal [nil, nil, nil, nil, nil, "", nil, nil, nil], URI.split("//")
+ end
+
class CaseInsensitiveEnv
def initialize(h={})
@h = {}
diff --git a/test/uri/test_http.rb b/test/uri/test_http.rb
index 748e90a322..e937b1a26b 100644
--- a/test/uri/test_http.rb
+++ b/test/uri/test_http.rb
@@ -3,10 +3,7 @@ require 'test/unit'
require 'uri/http'
require 'uri/https'
-module URI
-
-
-class TestHTTP < Test::Unit::TestCase
+class URI::TestHTTP < Test::Unit::TestCase
def setup
end
@@ -82,6 +79,3 @@ class TestHTTP < Test::Unit::TestCase
assert_equal('https://a.b.c', URI.parse('https://a.b.c/').origin)
end
end
-
-
-end
diff --git a/test/uri/test_ldap.rb b/test/uri/test_ldap.rb
index 64845e487a..9c4506a357 100644
--- a/test/uri/test_ldap.rb
+++ b/test/uri/test_ldap.rb
@@ -2,10 +2,7 @@
require 'test/unit'
require 'uri/ldap'
-module URI
-
-
-class TestLDAP < Test::Unit::TestCase
+class URI::TestLDAP < Test::Unit::TestCase
def setup
end
@@ -39,7 +36,7 @@ class TestLDAP < Test::Unit::TestCase
# from RFC2255, section 6.
{
'ldap:///o=University%20of%20Michigan,c=US' =>
- ['ldap', nil, URI::LDAP::DEFAULT_PORT,
+ ['ldap', '', URI::LDAP::DEFAULT_PORT,
'o=University%20of%20Michigan,c=US',
nil, nil, nil, nil],
@@ -74,12 +71,12 @@ class TestLDAP < Test::Unit::TestCase
nil, '(int=%5c00%5c00%5c00%5c04)', nil, nil],
'ldap:///??sub??bindname=cn=Manager%2co=Foo' =>
- ['ldap', nil, URI::LDAP::DEFAULT_PORT,
+ ['ldap', '', URI::LDAP::DEFAULT_PORT,
'',
nil, 'sub', nil, 'bindname=cn=Manager%2co=Foo'],
'ldap:///??sub??!bindname=cn=Manager%2co=Foo' =>
- ['ldap', nil, URI::LDAP::DEFAULT_PORT,
+ ['ldap', '', URI::LDAP::DEFAULT_PORT,
'',
nil, 'sub', nil, '!bindname=cn=Manager%2co=Foo'],
}.each do |url2, ary|
@@ -100,6 +97,3 @@ class TestLDAP < Test::Unit::TestCase
assert_raise(URI::InvalidURIError) {URI.parse("ldap:https://example.com")}
end
end
-
-
-end
diff --git a/test/uri/test_parser.rb b/test/uri/test_parser.rb
index f8e9299d09..75c02fe65b 100644
--- a/test/uri/test_parser.rb
+++ b/test/uri/test_parser.rb
@@ -72,4 +72,41 @@ class URI::TestParser < Test::Unit::TestCase
assert_equal("\u3042", p1.unescape('%e3%81%82'.force_encoding(Encoding::US_ASCII)))
assert_equal("\xe3\x83\x90\xe3\x83\x90", p1.unescape("\xe3\x83\x90%e3%83%90"))
end
+
+ def test_split
+ assert_equal(["http", nil, "example.com", nil, nil, "", nil, nil, nil], URI.split("http://example.com"))
+ assert_equal(["http", nil, "[0::0]", nil, nil, "", nil, nil, nil], URI.split("http://[0::0]"))
+ assert_equal([nil, nil, "example.com", nil, nil, "", nil, nil, nil], URI.split("//example.com"))
+ assert_equal([nil, nil, "[0::0]", nil, nil, "", nil, nil, nil], URI.split("//[0::0]"))
+
+ assert_equal(["a", nil, nil, nil, nil, "", nil, nil, nil], URI.split("a:"))
+ assert_raise(URI::InvalidURIError) do
+ URI.parse("::")
+ end
+ assert_raise(URI::InvalidURIError) do
+ URI.parse("foo@example:foo")
+ end
+ end
+
+ def test_rfc2822_parse_relative_uri
+ pre = ->(length) {
+ " " * length + "\0"
+ }
+ parser = URI::RFC2396_Parser.new
+ assert_linear_performance((1..5).map {|i| 10**i}, pre: pre) do |uri|
+ assert_raise(URI::InvalidURIError) do
+ parser.split(uri)
+ end
+ end
+ end
+
+ def test_rfc3986_port_check
+ pre = ->(length) {"\t" * length + "a"}
+ uri = URI.parse("http://my.example.com")
+ assert_linear_performance((1..5).map {|i| 10**i}, pre: pre) do |port|
+ assert_raise(URI::InvalidComponentError) do
+ uri.port = port
+ end
+ end
+ end
end
diff --git a/test/uri/test_ws.rb b/test/uri/test_ws.rb
index 17acb0d9f2..f3918f617c 100644
--- a/test/uri/test_ws.rb
+++ b/test/uri/test_ws.rb
@@ -3,10 +3,7 @@ require 'test/unit'
require 'uri/http'
require 'uri/ws'
-module URI
-
-
-class TestWS < Test::Unit::TestCase
+class URI::TestWS < Test::Unit::TestCase
def setup
end
@@ -66,6 +63,3 @@ class TestWS < Test::Unit::TestCase
end
end
end
-
-
-end
diff --git a/test/uri/test_wss.rb b/test/uri/test_wss.rb
index 2e8b9bc4b7..13a2583059 100644
--- a/test/uri/test_wss.rb
+++ b/test/uri/test_wss.rb
@@ -3,10 +3,7 @@ require 'test/unit'
require 'uri/https'
require 'uri/wss'
-module URI
-
-
-class TestWSS < Test::Unit::TestCase
+class URI::TestWSS < Test::Unit::TestCase
def setup
end
@@ -66,6 +63,3 @@ class TestWSS < Test::Unit::TestCase
end
end
end
-
-
-end