Commit 6f978944 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'normalize-import-error-messages' into 'master'

Normalize error message between Gitea and Fogbugz importers

See merge request gitlab-org/gitlab!28802
parents d268d4c0 5342d1a7
......@@ -3,6 +3,8 @@
class Import::GiteaController < Import::GithubController
extend ::Gitlab::Utils::Override
before_action :verify_blocked_uri, only: :status
def new
if session[access_token_key].present? && provider_url.present?
redirect_to status_import_url
......@@ -16,13 +18,7 @@ class Import::GiteaController < Import::GithubController
# Must be defined or it will 404
def status
if blocked_url?
session[access_token_key] = nil
redirect_to new_import_url, alert: _('Specified URL cannot be used.')
else
super
end
super
end
private
......@@ -61,8 +57,8 @@ class Import::GiteaController < Import::GithubController
{ host: provider_url, api_version: 'v1' }
end
def blocked_url?
Gitlab::UrlBlocker.blocked_url?(
def verify_blocked_uri
Gitlab::UrlBlocker.validate!(
provider_url,
{
allow_localhost: allow_local_requests?,
......@@ -70,6 +66,10 @@ class Import::GiteaController < Import::GithubController
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
def allow_local_requests?
......
---
title: Normalize error message between Gitea and Fogbugz importers
merge_request: 28802
author:
type: other
......@@ -19025,9 +19025,6 @@ msgstr ""
msgid "Specific Runners"
msgstr ""
msgid "Specified URL cannot be used."
msgstr ""
msgid "Specified URL cannot be used: \"%{reason}\""
msgstr ""
......
......@@ -42,7 +42,7 @@ describe Import::GiteaController do
get :status, format: :json
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
......
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