From 1f597136de444d437b1d6ed614fd928dd04c06dc Mon Sep 17 00:00:00 2001 From: ngala Date: Tue, 16 Apr 2024 14:19:03 +0530 Subject: [PATCH] Update default pages auth-redirect-uri when namespace-in-path is enabled Related: https://gitlab.com/gitlab-org/gitlab/-/issues/452459+ Changelog: fixed --- .../gitlab-pages/libraries/gitlab_pages.rb | 7 +++- .../gitlab-pages/recipes/gitlab-pages_spec.rb | 38 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/files/gitlab-cookbooks/gitlab-pages/libraries/gitlab_pages.rb b/files/gitlab-cookbooks/gitlab-pages/libraries/gitlab_pages.rb index 42ad84756..c1ad9a724 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