Skip to content

Commit

Permalink
Merge pull request #202 from KnapsackPro/mask-user-seats
Browse files Browse the repository at this point in the history
Mask user seats data instead of hashing it
  • Loading branch information
shadre authored Jun 8, 2023
2 parents b144ae8 + 7f7c9c9 commit f90909f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/knapsack_pro/client/api/v1/build_distributions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lib/knapsack_pro/client/api/v1/queues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions lib/knapsack_pro/config/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/knapsack_pro/client/api/v1/build_distributions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions spec/knapsack_pro/client/api/v1/queues_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
18 changes: 11 additions & 7 deletions spec/knapsack_pro/config/env_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit f90909f

Please sign in to comment.