Fix Import::UrlController#validate errors
The Import::UrlController#validate controller raises a 500 error when an invalid URL is provided to the controller.
Example of invalid URLs:
-
file://example.com
- HTTParty::UnsupportedURIScheme -
ssh://example.com
- HTTParty::UnsupportedURIScheme -
éxample.com
- URI::InvalidURIError -
http:example.com
- ArgumentError
Error 1 - URI::InvalidURIError
https://sentry.gitlab.net/gitlab/gitlabcom/issues/4035546
URI::InvalidURIError: bad URI(is not URI?): [FILTERED]
lib/gitlab/patch/uri.rb:10:in `parse'
super
lib/gitlab/http.rb:49:in `perform_request'
return httparty_perform_request(http_method, path, options_with_timeouts, &block)
lib/gitlab/http.rb:75:in `try_get'
self.get(path, options, &block)
app/services/import/validate_remote_git_endpoint_service.rb:33:in `execute'
Gitlab::HTTP.try_get(url, stream_body: true, follow_redirects: false, basic_auth: auth) do |fragment|
app/controllers/import/url_controller.rb:8:in `validate'
result = Import::ValidateRemoteGitEndpointService.new(validate_params).execute
...
(159 additional frame(s) were not displayed)
Error 2 - HTTParty::UnsupportedURIScheme
https://sentry.gitlab.net/gitlab/gitlabcom/issues/4036386
HTTParty::UnsupportedURIScheme: 'ssh://[FILTER].git/info/refs?service=git-upload-pack' Must be HTTP, HTTPS or Generic
from httparty (0.20.0) lib/httparty/request.rb:118:in `uri'
from httparty (0.20.0) lib/httparty/request.rb:227:in `setup_raw_request'
from httparty (0.20.0) lib/httparty/request.rb:148:in `perform'
from httparty (0.20.0) lib/httparty.rb:613:in `perform_request'
from lib/gitlab/http.rb:49:in `perform_request'
from httparty (0.20.0) lib/httparty.rb:527:in `get'
from lib/gitlab/http.rb:75:in `try_get'
from app/services/import/validate_remote_git_endpoint_service.rb:33:in `execute'
from app/controllers/import/url_controller.rb:8:in `validate'
from actionpack (6.1.6.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
from actionpack (6.1.6.1) lib/abstract_controller/base.rb:228:in `process_action'
from actionpack (6.1.6.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
from actionpack (6.1.6.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
from activesupport (6.1.6.1) lib/active_support/callbacks.rb:117:in `block in run_callbacks'
from ee/lib/gitlab/ip_address_state.rb:10:in `with'
from ee/app/controllers/ee/application_controller.rb:46:in `set_current_ip_address'
from activesupport (6.1.6.1) lib/active_support/callbacks.rb:126:in `block in run_callbacks'
from app/controllers/application_controller.rb:534:in `set_current_admin'
from activesupport (6.1.6.1) lib/active_support/callbacks.rb:126:in `block in run_callbacks'
from lib/gitlab/session.rb:11:in `with_session'
from app/controllers/application_controller.rb:525:in `set_session_storage'
from activesupport (6.1.6.1) lib/active_support/callbacks.rb:126:in `block in run_callbacks'
from lib/gitlab/i18n.rb:107:in `with_locale'
from lib/gitlab/i18n.rb:113:in `with_user_locale'
from app/controllers/application_controller.rb:513:in `set_locale'
Context
The Import::UrlController#validate
was introduced in #331805 (closed) to validate the repo presence when importing the repo by URL
How to reproduce the error
Edited by Rodrigo Tomonari