Remove unnecessary option to not require host in SafeURI

Fixes #10414
This commit is contained in:
Rob Bavey 2019-02-07 12:38:56 -05:00
parent ef8bbefcf1
commit f3917efcb8
2 changed files with 2 additions and 40 deletions

View file

@ -14,7 +14,7 @@ class LogStash::Util::SafeURI
attr_reader :uri
public
def initialize(arg, requires_host=true)
def initialize(arg)
@uri = case arg
when String
arg = "//#{arg}" if HOSTNAME_PORT_REGEX.match(arg)
@ -26,7 +26,7 @@ class LogStash::Util::SafeURI
else
raise ArgumentError, "Expected a string, java.net.URI, or URI, got a #{arg.class} creating a URL"
end
raise ArgumentError, "URI is not valid - host is not specified" if requires_host && @uri.host.nil?
raise ArgumentError, "URI is not valid - host is not specified" if @uri.host.nil?
end
def to_s

View file

@ -71,44 +71,6 @@ module LogStash module Util
end
end
end
context 'when host is not required' do
MALFORMED_URIS = ['http:/user:pass@localhost:9600', 'http:/localhost', 'http:/localhost:9600', 'h;localhost', 'http:://localhost']
context 'malformed uris via string' do
MALFORMED_URIS.each do |arg|
it "#{arg}: should not raise an error" do
expect{LogStash::Util::SafeURI.new(arg, false)}.not_to raise_error
end
end
end
context 'malformed uris via java.net.URI' do
MALFORMED_URIS.each do |arg|
it "#{arg}: should not raise an error" do
java_uri = java.net.URI.new(arg)
expect{LogStash::Util::SafeURI.new(java_uri, false)}.not_to raise_error
end
end
end
context 'malformed uris via Ruby URI' do
MALFORMED_URIS.each do |arg|
it "#{arg}: should not raise an error" do
ruby_uri = URI.parse(arg)
expect{LogStash::Util::SafeURI.new(ruby_uri, false)}.not_to raise_error
end
end
end
context 'uris with a valid host' do
['http://user:pass@notlocalhost:9600', 'http://notlocalhost', 'https://notlocalhost:9600', '//notlocalhost', 'notlocalhost', 'notlocalhost:9200'].each do |arg|
it "#{arg}: should resolve host correctly" do
expect(LogStash::Util::SafeURI.new(arg, false).host).to eq('notlocalhost')
end
end
end
end
end
end
end end