From 3802006436d6834ee0a8052b22773cb65c4447b5 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Sun, 11 Mar 2018 22:38:29 +0100 Subject: Respect the protocol in `expose_url` When https is configured in the URL, also use that, and do not set it to http. Closes gitlab-org/gitlab-ee#5217 --- .../api/helpers/related_resources_helpers_spec.rb | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 spec/lib/api/helpers/related_resources_helpers_spec.rb (limited to 'spec') diff --git a/spec/lib/api/helpers/related_resources_helpers_spec.rb b/spec/lib/api/helpers/related_resources_helpers_spec.rb new file mode 100644 index 00000000000..b918301f1cb --- /dev/null +++ b/spec/lib/api/helpers/related_resources_helpers_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe API::Helpers::RelatedResourcesHelpers do + subject(:helpers) do + Class.new.include(described_class).new + end + + describe '#expose_url' do + let(:path) { '/api/v4/awesome_endpoint' } + subject(:url) { helpers.expose_url(path) } + + def stub_default_url_options(protocol: 'http', host: 'example.com', port: nil) + expect(Gitlab::Application.routes).to receive(:default_url_options) + .and_return(protocol: protocol, host: host, port: port) + end + + it 'respects the protocol if it is HTTP' do + stub_default_url_options(protocol: 'http') + + is_expected.to start_with('http://') + end + + it 'respects the protocol if it is HTTPS' do + stub_default_url_options(protocol: 'https') + + is_expected.to start_with('https://') + end + + it 'accepts port to be nil' do + stub_default_url_options(port: nil) + + is_expected.to start_with('http://example.com/') + end + + it 'includes port if provided' do + stub_default_url_options(port: 8080) + + is_expected.to start_with('http://example.com:8080/') + end + end +end -- cgit v1.2.1