diff --git a/files/gitlab-cookbooks/gitlab-pages/libraries/gitlab_pages.rb b/files/gitlab-cookbooks/gitlab-pages/libraries/gitlab_pages.rb index 2af6ead1b..49a1c96e1 100644 --- a/files/gitlab-cookbooks/gitlab-pages/libraries/gitlab_pages.rb +++ b/files/gitlab-cookbooks/gitlab-pages/libraries/gitlab_pages.rb @@ -89,7 +89,12 @@ module GitlabPages pages_uri = URI(Gitlab['pages_external_url'].to_s) parsed_port = [80, 443].include?(pages_uri.port) ? "" : ":#{pages_uri.port}" - Gitlab['gitlab_pages']['auth_redirect_uri'] = pages_uri.scheme + '://projects.' + pages_uri.host + parsed_port + '/auth' + + Gitlab['gitlab_pages']['auth_redirect_uri'] = if Gitlab['gitlab_pages']['namespace_in_path'] + "#{pages_uri.scheme}://#{pages_uri.host}#{parsed_port}/projects/auth" + else + "#{pages_uri.scheme}://projects.#{pages_uri.host}#{parsed_port}/auth" + end end def authorize_with_gitlab diff --git a/spec/chef/cookbooks/gitlab-pages/recipes/gitlab-pages_spec.rb b/spec/chef/cookbooks/gitlab-pages/recipes/gitlab-pages_spec.rb index 838664bef..42d023b6e 100644 --- a/spec/chef/cookbooks/gitlab-pages/recipes/gitlab-pages_spec.rb +++ b/spec/chef/cookbooks/gitlab-pages/recipes/gitlab-pages_spec.rb @@ -169,6 +169,44 @@ RSpec.describe 'gitlab::gitlab-pages' do chef_run end end + + context 'when namespace in path is enabled' do + before do + stub_gitlab_rb( + pages_external_url: 'https://pages.example.com', + gitlab_pages: { + access_control: true, + namespace_in_path: true, + } + ) + end + + it 'renders pages config file with default auth-redirect-uri' do + expect(chef_run).to render_file("/var/opt/gitlab/gitlab-pages/gitlab-pages-config").with_content { |content| + expect(content).to match(%r{auth-redirect-uri=https://pages.example.com/projects/auth}) + expect(content).to match(%r{namespace-in-path=true}) + } + end + end + + context 'with custom port and namespace in path is enabled' do + before do + stub_gitlab_rb( + pages_external_url: 'https://pages.example.com:8443', + gitlab_pages: { + access_control: true, + namespace_in_path: true, + } + ) + end + + it 'renders pages config file with default auth-redirect-uri' do + expect(chef_run).to render_file("/var/opt/gitlab/gitlab-pages/gitlab-pages-config").with_content { |content| + expect(content).to match(%r{auth-redirect-uri=https://pages.example.com:8443/projects/auth}) + expect(content).to match(%r{namespace-in-path=true}) + } + end + end end context 'with custom port' do