Commit 8b871c33 authored by George Koltsov's avatar George Koltsov Committed by Matthias Käppler

Allow Bulk Import to use relative GitLab URL

 - Instead of reconstructing a URL user provided
   for bulk import, use it as is in order to allow
   GitLab instances that live on relative URLs
   to work

Changelog: fixed
parent 236d14b6
......@@ -87,7 +87,7 @@ class Import::BulkImportsController < ApplicationController
def client
@client ||= BulkImports::Clients::HTTP.new(
uri: session[url_key],
url: session[url_key],
token: session[access_token_key],
per_page: params[:per_page],
page: params[:page]
......
......@@ -9,7 +9,7 @@ module BulkImports
@relation = relation
@entity = @pipeline_tracker.entity
@configuration = @entity.bulk_import.configuration
@client = Clients::HTTP.new(uri: @configuration.url, token: @configuration.access_token)
@client = Clients::HTTP.new(url: @configuration.url, token: @configuration.access_token)
end
def started?
......
......@@ -55,7 +55,7 @@ module BulkImports
def http_client
@http_client ||= BulkImports::Clients::HTTP.new(
uri: configuration.url,
url: configuration.url,
token: configuration.access_token
)
end
......
......@@ -25,7 +25,7 @@ module BulkImports
def http_client(configuration)
@client ||= Clients::HTTP.new(
uri: configuration.url,
url: configuration.url,
token: configuration.access_token
)
end
......
......@@ -7,8 +7,8 @@ module BulkImports
DEFAULT_PAGE = 1
DEFAULT_PER_PAGE = 30
def initialize(uri:, token:, page: DEFAULT_PAGE, per_page: DEFAULT_PER_PAGE, api_version: API_VERSION)
@uri = URI.parse(uri)
def initialize(url:, token:, page: DEFAULT_PAGE, per_page: DEFAULT_PER_PAGE, api_version: API_VERSION)
@url = url
@token = token&.strip
@page = page
@per_page = per_page
......@@ -120,12 +120,8 @@ module BulkImports
raise(::BulkImports::Error, e)
end
def base_uri
@base_uri ||= "#{@uri.scheme}://#{@uri.host}:#{@uri.port}"
end
def api_url
Gitlab::Utils.append_path(base_uri, "/api/#{@api_version}")
Gitlab::Utils.append_path(@url, "/api/#{@api_version}")
end
end
end
......
......@@ -25,7 +25,7 @@ module BulkImports
def http_client(configuration)
@http_client ||= BulkImports::Clients::HTTP.new(
uri: configuration.url,
url: configuration.url,
token: configuration.access_token,
per_page: 100
)
......
......@@ -18,7 +18,7 @@ module BulkImports
def http_client(configuration)
@http_client ||= BulkImports::Clients::HTTP.new(
uri: configuration.url,
url: configuration.url,
token: configuration.access_token,
per_page: 100
)
......
......@@ -51,7 +51,7 @@ RSpec.describe Import::BulkImportsController do
end
describe 'GET status' do
let(:client) { BulkImports::Clients::HTTP.new(uri: 'http://gitlab.example', token: 'token') }
let(:client) { BulkImports::Clients::HTTP.new(url: 'http://gitlab.example', token: 'token') }
describe 'serialized group data' do
let(:client_response) do
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe BulkImports::Clients::HTTP do
include ImportSpecHelper
let(:uri) { 'http://gitlab.example' }
let(:url) { 'http://gitlab.example' }
let(:token) { 'token' }
let(:resource) { 'resource' }
let(:version) { "#{BulkImport::MINIMUM_GITLAB_MAJOR_VERSION}.0.0" }
......@@ -14,11 +14,11 @@ RSpec.describe BulkImports::Clients::HTTP do
before do
allow(Gitlab::HTTP).to receive(:get)
.with('http://gitlab.example:80/api/v4/version', anything)
.with('http://gitlab.example/api/v4/version', anything)
.and_return(version_response)
end
subject { described_class.new(uri: uri, token: token) }
subject { described_class.new(url: url, token: token) }
shared_examples 'performs network request' do
it 'performs network request' do
......@@ -54,7 +54,7 @@ RSpec.describe BulkImports::Clients::HTTP do
include_examples 'performs network request' do
let(:expected_args) do
[
'http://gitlab.example:80/api/v4/resource',
'http://gitlab.example/api/v4/resource',
hash_including(
follow_redirects: false,
query: {
......@@ -104,7 +104,7 @@ RSpec.describe BulkImports::Clients::HTTP do
private
def stub_http_get(path, query, response)
uri = "http://gitlab.example:80/api/v4/#{path}"
uri = "http://gitlab.example/api/v4/#{path}"
params = {
follow_redirects: false,
headers: {
......@@ -124,7 +124,7 @@ RSpec.describe BulkImports::Clients::HTTP do
include_examples 'performs network request' do
let(:expected_args) do
[
'http://gitlab.example:80/api/v4/resource',
'http://gitlab.example/api/v4/resource',
hash_including(
body: {},
follow_redirects: false,
......@@ -144,7 +144,7 @@ RSpec.describe BulkImports::Clients::HTTP do
include_examples 'performs network request' do
let(:expected_args) do
[
'http://gitlab.example:80/api/v4/resource',
'http://gitlab.example/api/v4/resource',
hash_including(
follow_redirects: false,
headers: {
......@@ -160,7 +160,7 @@ RSpec.describe BulkImports::Clients::HTTP do
describe '#stream' do
it 'performs network request with stream_body option' do
expected_args = [
'http://gitlab.example:80/api/v4/resource',
'http://gitlab.example/api/v4/resource',
hash_including(
stream_body: true,
headers: {
......@@ -183,4 +183,20 @@ RSpec.describe BulkImports::Clients::HTTP do
expect { subject.get(resource) }.to raise_error(::BulkImports::Error, "Unsupported GitLab Version. Minimum Supported Gitlab Version #{BulkImport::MINIMUM_GITLAB_MAJOR_VERSION}.")
end
end
context 'when url is relative' do
let(:url) { 'http://website.example/gitlab' }
before do
allow(Gitlab::HTTP).to receive(:get)
.with('http://website.example/gitlab/api/v4/version', anything)
.and_return(version_response)
end
it 'performs network request to a relative gitlab url' do
expect(Gitlab::HTTP).to receive(:get).with('http://website.example/gitlab/api/v4/resource', anything).and_return(response_double)
subject.get(resource)
end
end
end
......@@ -6,7 +6,7 @@ RSpec.describe BulkImports::ExportRequestWorker do
let_it_be(:bulk_import) { create(:bulk_import) }
let_it_be(:config) { create(:bulk_import_configuration, bulk_import: bulk_import) }
let_it_be(:entity) { create(:bulk_import_entity, source_full_path: 'foo/bar', bulk_import: bulk_import) }
let_it_be(:version_url) { 'https://gitlab.example:443/api/v4/version' }
let_it_be(:version_url) { 'https://gitlab.example/api/v4/version' }
let(:response_double) { double(code: 200, success?: true, parsed_response: {}) }
let(:job_args) { [entity.id] }
......
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