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 @@
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,14 +18,8 @@ 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
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