2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2003-10-05 02:09:26 -04:00
|
|
|
require 'test/unit'
|
2003-10-04 00:02:16 -04:00
|
|
|
require 'uri/ftp'
|
2003-10-05 02:09:26 -04:00
|
|
|
|
2003-10-04 00:02:16 -04:00
|
|
|
module URI
|
|
|
|
|
2003-10-05 02:09:26 -04:00
|
|
|
|
|
|
|
class TestFTP < Test::Unit::TestCase
|
2003-10-04 00:02:16 -04:00
|
|
|
def setup
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_parse
|
|
|
|
url = URI.parse('ftp://user:pass@host.com/abc/def')
|
|
|
|
assert_kind_of(URI::FTP, url)
|
|
|
|
|
|
|
|
exp = [
|
|
|
|
'ftp',
|
2009-03-05 22:56:38 -05:00
|
|
|
'user:pass', 'host.com', URI::FTP.default_port,
|
2005-09-07 12:07:43 -04:00
|
|
|
'abc/def', nil,
|
2003-10-04 00:02:16 -04:00
|
|
|
]
|
2003-10-05 02:09:26 -04:00
|
|
|
ary = [
|
|
|
|
url.scheme, url.userinfo, url.host, url.port,
|
|
|
|
url.path, url.opaque
|
|
|
|
]
|
2003-10-04 00:02:16 -04:00
|
|
|
assert_equal(exp, ary)
|
|
|
|
|
|
|
|
assert_equal('user', url.user)
|
|
|
|
assert_equal('pass', url.password)
|
|
|
|
end
|
|
|
|
|
2012-08-29 20:22:11 -04:00
|
|
|
def test_parse_invalid
|
|
|
|
assert_raise(InvalidURIError){URI.parse('ftp:example')}
|
|
|
|
end
|
|
|
|
|
2005-09-07 12:07:43 -04:00
|
|
|
def test_paths
|
2009-03-05 22:56:38 -05:00
|
|
|
# If you think what's below is wrong, please read RubyForge bug 2055,
|
2005-09-07 12:07:43 -04:00
|
|
|
# RFC 1738 section 3.2.2, and RFC 2396.
|
|
|
|
u = URI.parse('ftp://ftp.example.com/foo/bar/file.ext')
|
|
|
|
assert(u.path == 'foo/bar/file.ext')
|
|
|
|
u = URI.parse('ftp://ftp.example.com//foo/bar/file.ext')
|
|
|
|
assert(u.path == '/foo/bar/file.ext')
|
|
|
|
u = URI.parse('ftp://ftp.example.com/%2Ffoo/bar/file.ext')
|
|
|
|
assert(u.path == '/foo/bar/file.ext')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assemble
|
|
|
|
# uri/ftp is conservative and uses the older RFC 1738 rules, rather than
|
|
|
|
# assuming everyone else has implemented RFC 2396.
|
2009-03-05 22:56:38 -05:00
|
|
|
uri = URI::FTP.build(['user:password', 'ftp.example.com', nil,
|
2005-09-07 12:07:43 -04:00
|
|
|
'/path/file.zip', 'i'])
|
2009-03-05 22:56:38 -05:00
|
|
|
assert(uri.to_s ==
|
2005-09-07 12:07:43 -04:00
|
|
|
'ftp://user:password@ftp.example.com/%2Fpath/file.zip;type=i')
|
|
|
|
end
|
|
|
|
|
2003-10-04 00:02:16 -04:00
|
|
|
def test_select
|
|
|
|
assert_equal(['ftp', 'a.b.c', 21], URI.parse('ftp://a.b.c/').select(:scheme, :host, :port))
|
|
|
|
u = URI.parse('ftp://a.b.c/')
|
2003-10-05 02:09:26 -04:00
|
|
|
ary = u.component.collect {|c| u.send(c)}
|
|
|
|
assert_equal(ary, u.select(*u.component))
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(ArgumentError) do
|
2003-10-04 00:02:16 -04:00
|
|
|
u.select(:scheme, :host, :not_exist, :port)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-10-05 02:09:26 -04:00
|
|
|
|
2003-10-04 00:02:16 -04:00
|
|
|
end
|