Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36919 - Add URL validation to HTTP Proxy URL field. #9903

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/controllers/http_proxies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def edit
end

def test_connection
http_proxy = HttpProxy.new(http_proxy_params)
http_proxy = HttpProxy.new({name: 'dummy'}.update(http_proxy_params))
unless http_proxy.valid?
raise Foreman::Exception, http_proxy.errors.full_messages.join(', ')
end

http_proxy.test_connection(params[:test_url])

render :json => {:status => 'success', :message => _("HTTP Proxy connection successful.")}, :status => :ok
Expand Down
18 changes: 18 additions & 0 deletions test/controllers/http_proxies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,22 @@ def test_update_location_and_organization
assert_includes @model.reload.locations.pluck(:id), location_id
assert_includes @model.reload.organizations.pluck(:id), organization_id
end

def test_test_connection_success
controller = HttpProxiesController.new
controller.stubs(:http_proxy_params).returns({ url: 'https://some_url'})
controller.stubs(:params).returns({test_url: "https://some.where.com"})
RestClient::Request.stubs(:execute).returns(['example', 1])
controller.expects(:render).with(:json => {:status => "success", :message => "HTTP Proxy connection successful."}, :status => :ok)
controller.test_connection
end

def test_test_connection_failure
controller = HttpProxiesController.new
controller.stubs(:http_proxy_params).returns({ url: 'https://some_url'})
controller.stubs(:params).returns({test_url: "https://some.where.com"})
RestClient::Request.stubs(:execute).raises(StandardError.new('some error'))
controller.expects(:render).with(:json => {:status => 'failure', :message => "some error"}, :status => :unprocessable_entity)
controller.test_connection
end
end
Loading