Commit 5342d1a7 authored by Kassio Borges's avatar Kassio Borges

Normalize error message among importers

A similar validation is done in Fogbugz and Gitea importers but the
error message wasn't the same. This commit normalizes the error message
to be the same in both importers.
parent 6c9836c7
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
class Import::GiteaController < Import::GithubController class Import::GiteaController < Import::GithubController
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
before_action :verify_blocked_uri, only: :status
def new def new
if session[access_token_key].present? && provider_url.present? if session[access_token_key].present? && provider_url.present?
redirect_to status_import_url redirect_to status_import_url
...@@ -16,13 +18,7 @@ class Import::GiteaController < Import::GithubController ...@@ -16,13 +18,7 @@ class Import::GiteaController < Import::GithubController
# Must be defined or it will 404 # Must be defined or it will 404
def status def status
if blocked_url? super
session[access_token_key] = nil
redirect_to new_import_url, alert: _('Specified URL cannot be used.')
else
super
end
end end
private private
...@@ -61,8 +57,8 @@ class Import::GiteaController < Import::GithubController ...@@ -61,8 +57,8 @@ class Import::GiteaController < Import::GithubController
{ host: provider_url, api_version: 'v1' } { host: provider_url, api_version: 'v1' }
end end
def blocked_url? def verify_blocked_uri
Gitlab::UrlBlocker.blocked_url?( Gitlab::UrlBlocker.validate!(
provider_url, provider_url,
{ {
allow_localhost: allow_local_requests?, allow_localhost: allow_local_requests?,
...@@ -70,6 +66,10 @@ class Import::GiteaController < Import::GithubController ...@@ -70,6 +66,10 @@ class Import::GiteaController < Import::GithubController
schemes: %w(http https) schemes: %w(http https)
} }
) )
rescue Gitlab::UrlBlocker::BlockedUrlError => e
session[access_token_key] = nil
redirect_to new_import_url, alert: _('Specified URL cannot be used: "%{reason}"') % { reason: e.message }
end end
def allow_local_requests? def allow_local_requests?
......
---
title: Normalize error message between Gitea and Fogbugz importers
merge_request: 28802
author:
type: other
...@@ -19025,9 +19025,6 @@ msgstr "" ...@@ -19025,9 +19025,6 @@ msgstr ""
msgid "Specific Runners" msgid "Specific Runners"
msgstr "" msgstr ""
msgid "Specified URL cannot be used."
msgstr ""
msgid "Specified URL cannot be used: \"%{reason}\"" msgid "Specified URL cannot be used: \"%{reason}\""
msgstr "" msgstr ""
......
...@@ -42,7 +42,7 @@ describe Import::GiteaController do ...@@ -42,7 +42,7 @@ describe Import::GiteaController do
get :status, format: :json get :status, format: :json
expect(controller).to redirect_to(new_import_url) expect(controller).to redirect_to(new_import_url)
expect(flash[:alert]).to eq('Specified URL cannot be used.') expect(flash[:alert]).to eq('Specified URL cannot be used: "Only allowed schemes are http, https"')
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment