From 7f7c9c9a18465200a692df83423a8c2ce054236d Mon Sep 17 00:00:00 2001 From: shadre Date: Thu, 8 Jun 2023 14:02:49 +0200 Subject: [PATCH] Mask user seats data instead of hashing it --- .../client/api/v1/build_distributions.rb | 2 +- lib/knapsack_pro/client/api/v1/queues.rb | 2 +- lib/knapsack_pro/config/env.rb | 5 +++-- .../client/api/v1/build_distributions_spec.rb | 8 ++++---- spec/knapsack_pro/client/api/v1/queues_spec.rb | 10 +++++----- spec/knapsack_pro/config/env_spec.rb | 18 +++++++++++------- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/knapsack_pro/client/api/v1/build_distributions.rb b/lib/knapsack_pro/client/api/v1/build_distributions.rb index 34d6a1e5..3283a1b3 100644 --- a/lib/knapsack_pro/client/api/v1/build_distributions.rb +++ b/lib/knapsack_pro/client/api/v1/build_distributions.rb @@ -15,7 +15,7 @@ def subset(args) :node_total => args.fetch(:node_total), :node_index => args.fetch(:node_index), :ci_build_id => KnapsackPro::Config::Env.ci_node_build_id, - :user_seat => KnapsackPro::Config::Env.user_seat_hash, + :user_seat => KnapsackPro::Config::Env.masked_user_seat, } unless request_hash[:cache_read_attempt] diff --git a/lib/knapsack_pro/client/api/v1/queues.rb b/lib/knapsack_pro/client/api/v1/queues.rb index 5b68100a..4e7c5461 100644 --- a/lib/knapsack_pro/client/api/v1/queues.rb +++ b/lib/knapsack_pro/client/api/v1/queues.rb @@ -16,7 +16,7 @@ def queue(args) :node_total => args.fetch(:node_total), :node_index => args.fetch(:node_index), :node_build_id => KnapsackPro::Config::Env.ci_node_build_id, - :user_seat => KnapsackPro::Config::Env.user_seat_hash, + :user_seat => KnapsackPro::Config::Env.masked_user_seat, } if request_hash[:can_initialize_queue] && !request_hash[:attempt_connect_to_queue] diff --git a/lib/knapsack_pro/config/env.rb b/lib/knapsack_pro/config/env.rb index 31c9d36d..1604a2ac 100644 --- a/lib/knapsack_pro/config/env.rb +++ b/lib/knapsack_pro/config/env.rb @@ -64,9 +64,10 @@ def user_seat ci_env_for(:user_seat) end - def user_seat_hash + def masked_user_seat return unless user_seat - Digest::SHA2.hexdigest(user_seat) + + user_seat.gsub(/(?<=\w{2})[a-zA-Z]/, "*") end def test_file_pattern diff --git a/spec/knapsack_pro/client/api/v1/build_distributions_spec.rb b/spec/knapsack_pro/client/api/v1/build_distributions_spec.rb index 6aea43f6..7a3b0eb8 100644 --- a/spec/knapsack_pro/client/api/v1/build_distributions_spec.rb +++ b/spec/knapsack_pro/client/api/v1/build_distributions_spec.rb @@ -6,7 +6,7 @@ let(:node_total) { double } let(:node_index) { double } let(:ci_build_id) { double } - let(:user_seat_hash) { double } + let(:masked_user_seat) { double } let(:test_files) { double } subject do @@ -23,7 +23,7 @@ before do expect(KnapsackPro::Config::Env).to receive(:fixed_test_suite_split).and_return(fixed_test_suite_split) expect(KnapsackPro::Config::Env).to receive(:ci_node_build_id).and_return(ci_build_id) - expect(KnapsackPro::Config::Env).to receive(:user_seat_hash).and_return(user_seat_hash) + expect(KnapsackPro::Config::Env).to receive(:masked_user_seat).and_return(masked_user_seat) end context 'when cache_read_attempt=true' do @@ -42,7 +42,7 @@ node_total: node_total, node_index: node_index, ci_build_id: ci_build_id, - user_seat: user_seat_hash, + user_seat: masked_user_seat, } }).and_return(action) expect(subject).to eq action @@ -65,7 +65,7 @@ node_total: node_total, node_index: node_index, ci_build_id: ci_build_id, - user_seat: user_seat_hash, + user_seat: masked_user_seat, test_files: test_files } }).and_return(action) diff --git a/spec/knapsack_pro/client/api/v1/queues_spec.rb b/spec/knapsack_pro/client/api/v1/queues_spec.rb index 2238f3d1..cb0fe941 100644 --- a/spec/knapsack_pro/client/api/v1/queues_spec.rb +++ b/spec/knapsack_pro/client/api/v1/queues_spec.rb @@ -7,7 +7,7 @@ let(:node_index) { double } let(:test_files) { double } let(:node_build_id) { double } - let(:user_seat_hash) { double } + let(:masked_user_seat) { double } subject do described_class.queue( @@ -24,7 +24,7 @@ before do expect(KnapsackPro::Config::Env).to receive(:fixed_queue_split).and_return(fixed_queue_split) expect(KnapsackPro::Config::Env).to receive(:ci_node_build_id).and_return(node_build_id) - expect(KnapsackPro::Config::Env).to receive(:user_seat_hash).and_return(user_seat_hash) + expect(KnapsackPro::Config::Env).to receive(:masked_user_seat).and_return(masked_user_seat) end context 'when can_initialize_queue=true and attempt_connect_to_queue=true' do @@ -45,7 +45,7 @@ node_total: node_total, node_index: node_index, node_build_id: node_build_id, - user_seat: user_seat_hash, + user_seat: masked_user_seat, } }).and_return(action) expect(subject).to eq action @@ -70,7 +70,7 @@ node_total: node_total, node_index: node_index, node_build_id: node_build_id, - user_seat: user_seat_hash, + user_seat: masked_user_seat, test_files: test_files } }).and_return(action) @@ -96,7 +96,7 @@ node_total: node_total, node_index: node_index, node_build_id: node_build_id, - user_seat: user_seat_hash, + user_seat: masked_user_seat, } }).and_return(action) expect(subject).to eq action diff --git a/spec/knapsack_pro/config/env_spec.rb b/spec/knapsack_pro/config/env_spec.rb index c6430025..c3274597 100644 --- a/spec/knapsack_pro/config/env_spec.rb +++ b/spec/knapsack_pro/config/env_spec.rb @@ -207,22 +207,26 @@ end end - describe '.user_seat_hash' do - subject { described_class.user_seat_hash } + describe '.masked_seat_hash' do + subject { described_class.masked_user_seat } before do expect(described_class).to receive(:user_seat).at_least(1).and_return(user_seat) end - context 'when the user seat has a value' do + context 'when the user seat is a name' do let(:user_seat) { 'John Doe' } - it 'returns a SHA256 hash for the user seat' do - expect(subject).to eq '6cea57c2fb6cbc2a40411135005760f241fffc3e5e67ab99882726431037f908' - end + it { expect(subject).to eq 'Jo** Do*' } + end + + context 'when the user seat is an e-mail' do + let(:user_seat) { 'john.doe@example.com' } + + it { expect(subject).to eq 'jo**.do*@ex*****.co*' } end - context 'when the user seat has no value' do + context 'when the user seat is nil' do let(:user_seat) { nil } it { expect(subject).to be_nil }