Skip to content
代码片段 群组 项目
提交 7637ba0e 编辑于 作者: ankit.panchal's avatar ankit.panchal
浏览文件

Pseudonymise username in urls

上级 c8ae83e6
No related branches found
No related tags found
2 合并请求!3031Merge per-main-jh to main-jh by luzhiyuan,!3030Merge per-main-jh to main-jh
...@@ -4,6 +4,7 @@ module Routing ...@@ -4,6 +4,7 @@ module Routing
module PseudonymizationHelper module PseudonymizationHelper
PSEUDONOMIZED_NAMESPACE = "namespace" PSEUDONOMIZED_NAMESPACE = "namespace"
PSEUDONOMIZED_PROJECT = "project" PSEUDONOMIZED_PROJECT = "project"
PSEUDONOMIZED_USERNAME = "username"
PSEUDONOMIZED_GROUP = "group" PSEUDONOMIZED_GROUP = "group"
PSEUDONOMIZED_ID = "id" PSEUDONOMIZED_ID = "id"
...@@ -38,6 +39,8 @@ def mask_params ...@@ -38,6 +39,8 @@ def mask_params
case key case key
when :project_id when :project_id
[key, "project#{@project&.id}"] [key, "project#{@project&.id}"]
when :username
[key, PSEUDONOMIZED_USERNAME]
when :namespace_id, :group_id when :namespace_id, :group_id
namespace = @group || @project&.namespace namespace = @group || @project&.namespace
[key, "namespace#{namespace&.id}"] [key, "namespace#{namespace&.id}"]
...@@ -72,6 +75,7 @@ def has_maskable_params? ...@@ -72,6 +75,7 @@ def has_maskable_params?
request_params.key?(:group_id) || request_params.key?(:group_id) ||
request_params.key?(:project_id) || request_params.key?(:project_id) ||
request_params.key?(:id) || request_params.key?(:id) ||
request_params.key?(:username) ||
@request.query_string.present? @request.query_string.present?
end end
...@@ -118,6 +122,8 @@ def masked_referrer_url(url) ...@@ -118,6 +122,8 @@ def masked_referrer_url(url)
params[:id] = PSEUDONOMIZED_NAMESPACE params[:id] = PSEUDONOMIZED_NAMESPACE
when 'projects' when 'projects'
params[:id] = PSEUDONOMIZED_PROJECT params[:id] = PSEUDONOMIZED_PROJECT
when 'users'
params[:username] = PSEUDONOMIZED_USERNAME
else else
params[:id] = PSEUDONOMIZED_ID if params[:id] params[:id] = PSEUDONOMIZED_ID if params[:id]
end end
......
...@@ -148,6 +148,29 @@ ...@@ -148,6 +148,29 @@
it_behaves_like 'masked url' it_behaves_like 'masked url'
end end
context 'with username in path parameters' do
let(:masked_url) { "http://localhost/username" }
let(:request) do
double(
:Request,
path_parameters: {
controller: 'users',
action: 'show',
username: 'someuser'
},
protocol: 'http',
host: 'localhost',
query_string: ''
)
end
before do
allow(helper).to receive(:request).and_return(request)
end
it_behaves_like 'masked url'
end
context 'when assignee_username is present' do context 'when assignee_username is present' do
let(:masked_url) { "http://localhost/dashboard/issues?assignee_username=masked_assignee_username" } let(:masked_url) { "http://localhost/dashboard/issues?assignee_username=masked_assignee_username" }
let(:request) do let(:request) do
...@@ -366,6 +389,21 @@ ...@@ -366,6 +389,21 @@
expect(helper.masked_referrer_url(original_url)).to eq(masked_url) expect(helper.masked_referrer_url(original_url)).to eq(masked_url)
end end
end end
context 'with controller for users' do
let(:original_url) { "http://localhost/someuser" }
let(:masked_url) { 'http://localhost/username' }
it 'masks username in the URL for users controller' do
allow(Rails.application.routes).to receive(:recognize_path)
.with(original_url)
.and_return({ controller: 'users', action: 'show', username: 'someuser' })
stub_feature_flags(mask_page_urls: true)
expect(helper.masked_referrer_url(original_url)).to eq(masked_url)
end
end
end end
describe 'masked_query_params' do describe 'masked_query_params' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册