Commit e865251e authored by Ash McKenzie's avatar Ash McKenzie

Rename HTTPHelper#host to #internal_api_endpoint

parent dd4bd1d7
......@@ -35,7 +35,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
params[:user_id] = actor.gsub("user-", "")
end
url = "#{host}/allowed"
url = "#{internal_api_endpoint}/allowed"
resp = post(url, params)
if resp.code == '200'
......@@ -52,7 +52,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
def discover(key)
key_id = key.gsub("key-", "")
resp = get("#{host}/discover?key_id=#{key_id}")
resp = get("#{internal_api_endpoint}/discover?key_id=#{key_id}")
JSON.parse(resp.body) rescue nil
end
......@@ -62,7 +62,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
key_id: key.gsub('key-', '')
}
resp = post("#{host}/lfs_authenticate", params)
resp = post("#{internal_api_endpoint}/lfs_authenticate", params)
if resp.code == '200'
GitlabLfsAuthentication.build_from_json(resp.body)
......@@ -70,14 +70,14 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
end
def broadcast_message
resp = get("#{host}/broadcast_message")
resp = get("#{internal_api_endpoint}/broadcast_message")
JSON.parse(resp.body) rescue {}
end
def merge_request_urls(gl_repository, repo_path, changes)
changes = changes.join("\n") unless changes.is_a?(String)
changes = changes.encode('UTF-8', 'ASCII', invalid: :replace, replace: '')
url = "#{host}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}"
url = "#{internal_api_endpoint}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}"
url += "&gl_repository=#{URI.escape(gl_repository)}" if gl_repository
resp = get(url)
......@@ -91,11 +91,11 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
end
def check
get("#{host}/check", read_timeout: CHECK_TIMEOUT)
get("#{internal_api_endpoint}/check", read_timeout: CHECK_TIMEOUT)
end
def authorized_key(key)
resp = get("#{host}/authorized_keys?key=#{URI.escape(key, '+/=')}")
resp = get("#{internal_api_endpoint}/authorized_keys?key=#{URI.escape(key, '+/=')}")
JSON.parse(resp.body) if resp.code == "200"
rescue
nil
......@@ -103,7 +103,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
def two_factor_recovery_codes(key)
key_id = key.gsub('key-', '')
resp = post("#{host}/two_factor_recovery_codes", key_id: key_id)
resp = post("#{internal_api_endpoint}/two_factor_recovery_codes", key_id: key_id)
JSON.parse(resp.body) if resp.code == '200'
rescue
......@@ -112,7 +112,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
def notify_post_receive(gl_repository, repo_path)
params = { gl_repository: gl_repository, project: repo_path }
resp = post("#{host}/notify_post_receive", params)
resp = post("#{internal_api_endpoint}/notify_post_receive", params)
resp.code == '200'
rescue
......@@ -125,7 +125,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
identifier: identifier,
changes: changes
}
resp = post("#{host}/post_receive", params)
resp = post("#{internal_api_endpoint}/post_receive", params)
raise NotFound if resp.code == '404'
......@@ -133,7 +133,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
end
def pre_receive(gl_repository)
resp = post("#{host}/pre_receive", gl_repository: gl_repository)
resp = post("#{internal_api_endpoint}/pre_receive", gl_repository: gl_repository)
raise NotFound if resp.code == '404'
......
......@@ -11,7 +11,7 @@ module HTTPHelper
"#{config.gitlab_url}/api/v4"
end
def host
def internal_api_endpoint
"#{base_api_endpoint}/internal"
end
......
......@@ -5,14 +5,14 @@ require_relative '../lib/gitlab_access_status'
describe GitlabNet, vcr: true do
let(:gitlab_net) { GitlabNet.new }
let(:changes) { ['0000000000000000000000000000000000000000 92d0970eefd7acb6d548878925ce2208cfe2d2ec refs/heads/branch4'] }
let(:host) { 'http://localhost:3000/api/v4/internal' }
let(:internal_api_endpoint) { 'http://localhost:3000/api/v4/internal' }
let(:project) { 'gitlab-org/gitlab-test.git' }
let(:key) { 'key-1' }
let(:key2) { 'key-2' }
let(:secret) { "0a3938d9d95d807e94d937af3a4fbbea\n" }
before do
gitlab_net.stub(:host).and_return(host)
gitlab_net.stub(:internal_api_endpoint).and_return(internal_api_endpoint)
gitlab_net.stub(:secret_token).and_return(secret)
end
......@@ -68,7 +68,7 @@ describe GitlabNet, vcr: true do
lfs_access = gitlab_net.lfs_authenticate(key, project)
lfs_access.username.should == 'root'
lfs_access.lfs_token.should == 'Hyzhyde_wLUeyUQsR3tHGTG8eNocVQm4ssioTEsBSdb6KwCSzQ'
lfs_access.repository_http_path.should == URI.join(host.sub('api/v4', ''), project).to_s
lfs_access.repository_http_path.should == URI.join(internal_api_endpoint.sub('api/v4', ''), project).to_s
end
end
end
......@@ -100,13 +100,13 @@ describe GitlabNet, vcr: true do
let(:encoded_changes) { "123456%20789012%20refs/heads/test%0A654321%20210987%20refs/tags/tag" }
it "sends the given arguments as encoded URL parameters" do
gitlab_net.should_receive(:get).with("#{host}/merge_request_urls?project=#{project}&changes=#{encoded_changes}&gl_repository=#{gl_repository}")
gitlab_net.should_receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}&gl_repository=#{gl_repository}")
gitlab_net.merge_request_urls(gl_repository, project, changes)
end
it "omits the gl_repository parameter if it's nil" do
gitlab_net.should_receive(:get).with("#{host}/merge_request_urls?project=#{project}&changes=#{encoded_changes}")
gitlab_net.should_receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}")
gitlab_net.merge_request_urls(nil, project, changes)
end
......@@ -361,12 +361,12 @@ describe GitlabNet, vcr: true do
it("uses API version 4") { should end_with("api/v4") }
end
describe :host do
describe :internal_api_endpoint do
let(:net) { GitlabNet.new }
subject { net.send :host }
subject { net.send :internal_api_endpoint }
it { should include(net.send(:config).gitlab_url) }
it("uses API version 4") { should include("api/v4") }
it("uses API version 4") { should end_with("api/v4/internal") }
end
describe :http_client_for do
......
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