knapsack_pro 0.31.0 → 0.32.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 897d3324c8c5701fb4508d0382716c3bbbe6ed0c
4
- data.tar.gz: 6ebf2904dde98152e80e12dfd855e5080f41233a
3
+ metadata.gz: f61f4cbac8cf4737c994517d3d2b720b43e31dc0
4
+ data.tar.gz: 8e78bb42b3cf42aae6ff29cbaac9bbadc059c005
5
5
  SHA512:
6
- metadata.gz: 9c23494c6858da7833fea766e2f3de502967150219657b3b35cb1fc6b4eb0481bbc6062a76c0a0944092d2b70585443cc3d99954d3a11eed676cba12d01c743d
7
- data.tar.gz: f89bf84f3194baacf28b3396ed701d20a2b83d22ece58d2debd8cae591d599ec85605f39b5d9884d9c79e321de04b7d789751924f9a6db20ccbd75374e012730
6
+ metadata.gz: b03f01778fa3c20735b54c71631b0beeb74658fdef67ab8247aa325aef55de0268ef6ede238a6d75733f3f4ccd74df734769b974c2dca2616a412830f015165e
7
+ data.tar.gz: 30fcb16188e7e2c72fcfeaa1038775fa9f54f5ffb84ba8ababed6883637ce9b8e4e04f4f2c91f7015e94629437fd4b167f075f3fd026edb834b1f019a7e6664b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  * TODO
4
4
 
5
+ ### 0.32.0
6
+
7
+ * Add encryption for branch names
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/30
10
+
11
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v0.31.0...v0.32.0
12
+
5
13
  ### 0.31.0
6
14
 
7
15
  * Add supported for log levels `fatal` and `error` by `KNAPSACK_PRO_LOG_LEVEL` environment variable.
data/README.md CHANGED
@@ -88,6 +88,8 @@ The knapsack_pro has also [queue mode](#queue-mode) to get most optimal test sui
88
88
  - [Test file names encryption](#test-file-names-encryption)
89
89
  - [How to enable test file names encryption?](#how-to-enable-test-file-names-encryption)
90
90
  - [How to debug test file names?](#how-to-debug-test-file-names)
91
+ - [How to enable branch names encryption?](#how-to-enable-branch-names-encryption)
92
+ - [How to debug branch names?](#how-to-debug-branch-names)
91
93
  - [Supported CI providers](#supported-ci-providers)
92
94
  - [Info for CircleCI users](#info-for-circleci-users)
93
95
  - [Info for Travis users](#info-for-travis-users)
@@ -513,7 +515,7 @@ This is optional way of using knapsack_pro when you don't want to add it to `Gem
513
515
  ### Test file names encryption
514
516
 
515
517
  knapsack_pro gem collects information about you test file names and time execution. Those data are stored on KnapsackPro.com server.
516
- If your test file names are sensitive data then you can encrypt the names before sending them to KnapsackPro.com API.
518
+ If your test file names or branch names are sensitive data then you can encrypt the names before sending them to KnapsackPro.com API.
517
519
 
518
520
  By default, encryption is disabled because knapsack_pro can use your test files names to prepare better test suite split when the time execution data are not yet collected on KnapsackPro.com server.
519
521
  When you will enable test file names encryption then your first test suite split may be less optimal than it could be.
@@ -523,23 +525,45 @@ Each test file name is generated with `Digest::SHA2.hexdigest` method and 64 cha
523
525
  Before you enable test file encryption please ensure you are using fresh API key. You should not use the same API key for encrypted and non encrypted test suite.
524
526
  You can generate API key for your test suite in [your dashboard](https://knapsackpro.com).
525
527
 
526
- #### How to enable test file names encryption?
527
-
528
- First you need to add environment variable `KNAPSACK_PRO_TEST_FILES_ENCRYPTED=true` to your CI server.
529
-
530
- Next step is to generate salt which will be used to encrypt test file names.
528
+ Next step is to generate salt which will be used to encrypt test files or branch names.
531
529
 
532
530
  $ bundle exec rake knapsack_pro:salt
533
531
 
534
532
  Add to your CI server generated environment variable `KNAPSACK_PRO_SALT`.
535
533
 
534
+ #### How to enable test file names encryption?
535
+
536
+ You need to add environment variable `KNAPSACK_PRO_TEST_FILES_ENCRYPTED=true` to your CI server.
537
+
536
538
  #### How to debug test file names?
537
539
 
538
- If you need to check what is the encryption hash for particular test file your can check that with the rake task:
540
+ If you need to check what is the encryption hash for particular test file you can check that with the rake task:
539
541
 
540
542
  $ KNAPSACK_PRO_SALT=xxx bundle exec rake knapsack_pro:encrypted_test_file_names[rspec]
541
543
 
542
- You can pass the name of test runner like rspec, minitest, cucumber, spinach as argument to rake task.
544
+ You can pass the name of test runner like `rspec`, `minitest`, `cucumber`, `spinach` as argument to rake task.
545
+
546
+ #### How to enable branch names encryption?
547
+
548
+ You need to add environment variable `KNAPSACK_PRO_BRANCH_ENCRYPTED=true` to your CI server.
549
+
550
+ Note: there are a few branch names that won't be encrypted because we use them as fallback branches on Knapsack Pro API side to determine time execution for test files during split for newly created branches.
551
+
552
+ * develop
553
+ * development
554
+ * dev
555
+ * master
556
+ * staging
557
+
558
+ #### How to debug branch names?
559
+
560
+ If you need to check what is the encryption hash for particular branch then use the rake task:
561
+
562
+ # show all local branches and respective hashes
563
+ $ KNAPSACK_PRO_SALT=xxx bundle exec rake knapsack_pro:encrypted_branch_names
564
+
565
+ # show hash for branch provided as argument to rake task
566
+ $ KNAPSACK_PRO_SALT=xxx bundle exec rake knapsack_pro:encrypted_branch_names[not-encrypted-branch-name]
543
567
 
544
568
  ### Supported CI providers
545
569
 
data/lib/knapsack_pro.rb CHANGED
@@ -55,6 +55,7 @@ require_relative 'knapsack_pro/runners/spinach_runner'
55
55
  require_relative 'knapsack_pro/runners/queue/base_runner'
56
56
  require_relative 'knapsack_pro/runners/queue/rspec_runner'
57
57
  require_relative 'knapsack_pro/crypto/encryptor'
58
+ require_relative 'knapsack_pro/crypto/branch_encryptor'
58
59
  require_relative 'knapsack_pro/crypto/decryptor'
59
60
  require_relative 'knapsack_pro/crypto/digestor'
60
61
 
@@ -29,10 +29,14 @@ module KnapsackPro
29
29
  KnapsackPro::Crypto::Encryptor.call(test_files)
30
30
  end
31
31
 
32
+ def encrypted_branch
33
+ KnapsackPro::Crypto::BranchEncryptor.call(repository_adapter.branch)
34
+ end
35
+
32
36
  def build_action
33
37
  KnapsackPro::Client::API::V1::BuildDistributions.subset(
34
38
  commit_hash: repository_adapter.commit_hash,
35
- branch: repository_adapter.branch,
39
+ branch: encrypted_branch,
36
40
  node_total: ci_node_total,
37
41
  node_index: ci_node_index,
38
42
  test_files: encrypted_test_files,
@@ -75,6 +75,14 @@ module KnapsackPro
75
75
  test_files_encrypted == 'true'
76
76
  end
77
77
 
78
+ def branch_encrypted
79
+ ENV['KNAPSACK_PRO_BRANCH_ENCRYPTED']
80
+ end
81
+
82
+ def branch_encrypted?
83
+ branch_encrypted == 'true'
84
+ end
85
+
78
86
  def salt
79
87
  required_env('KNAPSACK_PRO_SALT')
80
88
  end
@@ -0,0 +1,31 @@
1
+ module KnapsackPro
2
+ module Crypto
3
+ class BranchEncryptor
4
+ NON_ENCRYPTABLE_BRANCHES = %w(develop development dev master staging)
5
+
6
+ def self.call(branch)
7
+ if KnapsackPro::Config::Env.branch_encrypted?
8
+ new(branch).call
9
+ else
10
+ branch
11
+ end
12
+ end
13
+
14
+ def initialize(branch)
15
+ @branch = branch
16
+ end
17
+
18
+ def call
19
+ if NON_ENCRYPTABLE_BRANCHES.include?(branch)
20
+ branch
21
+ else
22
+ Digestor.salt_hexdigest(branch)[0..6]
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :branch
29
+ end
30
+ end
31
+ end
@@ -1,7 +1,6 @@
1
1
  module KnapsackPro
2
2
  module Crypto
3
3
  class Decryptor
4
- class MissingEncryptedTestFileError < StandardError; end
5
4
  class TooManyEncryptedTestFilesError < StandardError; end
6
5
 
7
6
  def self.call(test_files, encrypted_test_files)
@@ -1,9 +1,9 @@
1
1
  module KnapsackPro
2
2
  module Crypto
3
3
  class Digestor
4
- def self.salt_hexdigest(path)
4
+ def self.salt_hexdigest(str_to_encrypt)
5
5
  salt = KnapsackPro::Config::Env.salt
6
- str = salt + path
6
+ str = salt + str_to_encrypt
7
7
  Digest::SHA2.hexdigest(str)
8
8
  end
9
9
  end
@@ -32,11 +32,15 @@ module KnapsackPro
32
32
  KnapsackPro::Crypto::Encryptor.call(test_files)
33
33
  end
34
34
 
35
+ def encrypted_branch
36
+ KnapsackPro::Crypto::BranchEncryptor.call(repository_adapter.branch)
37
+ end
38
+
35
39
  def build_action(can_initialize_queue)
36
40
  KnapsackPro::Client::API::V1::Queues.queue(
37
41
  can_initialize_queue: can_initialize_queue,
38
42
  commit_hash: repository_adapter.commit_hash,
39
- branch: repository_adapter.branch,
43
+ branch: encrypted_branch,
40
44
  node_total: ci_node_total,
41
45
  node_index: ci_node_index,
42
46
  node_build_id: ci_node_build_id,
@@ -45,9 +45,10 @@ module KnapsackPro
45
45
  repository_adapter = KnapsackPro::RepositoryAdapterInitiator.call
46
46
  test_files = KnapsackPro::Utils.unsymbolize(test_files)
47
47
  encrypted_test_files = KnapsackPro::Crypto::Encryptor.call(test_files)
48
+ encrypted_branch = KnapsackPro::Crypto::BranchEncryptor.call(repository_adapter.branch)
48
49
  action = KnapsackPro::Client::API::V1::BuildSubsets.create(
49
50
  commit_hash: repository_adapter.commit_hash,
50
- branch: repository_adapter.branch,
51
+ branch: encrypted_branch,
51
52
  node_total: KnapsackPro::Config::Env.ci_node_total,
52
53
  node_index: KnapsackPro::Config::Env.ci_node_index,
53
54
  test_files: encrypted_test_files,
@@ -8,6 +8,10 @@ module KnapsackPro
8
8
  def branch
9
9
  raise NotImplementedError
10
10
  end
11
+
12
+ def branches
13
+ raise NotImplementedError
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -9,6 +9,11 @@ module KnapsackPro
9
9
  `git -C "#{working_dir}" rev-parse --abbrev-ref HEAD`.strip
10
10
  end
11
11
 
12
+ def branches
13
+ str_branches = `git rev-parse --abbrev-ref --branches`
14
+ str_branches.split("\n")
15
+ end
16
+
12
17
  private
13
18
 
14
19
  def working_dir
@@ -1,3 +1,3 @@
1
1
  module KnapsackPro
2
- VERSION = '0.31.0'
2
+ VERSION = '0.32.0'
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'knapsack_pro'
2
+
3
+ namespace :knapsack_pro do
4
+ task :encrypted_branch_names, [:branch] do |_, args|
5
+ branch = args[:branch]
6
+
7
+ branches =
8
+ if branch
9
+ [branch]
10
+ else
11
+ KnapsackPro::RepositoryAdapters::GitAdapter.new.branches
12
+ end
13
+
14
+ branches.each do |branch_name|
15
+ encrypted_branch = KnapsackPro::Crypto::BranchEncryptor.new(branch_name).call
16
+
17
+ puts "branch: #{branch_name}"
18
+ puts "encrypted branch: #{encrypted_branch}"
19
+ puts
20
+ end
21
+ end
22
+ end
@@ -22,10 +22,13 @@ describe KnapsackPro::Allocator do
22
22
  encrypted_test_files = double
23
23
  expect(KnapsackPro::Crypto::Encryptor).to receive(:call).with(test_files).and_return(encrypted_test_files)
24
24
 
25
+ encrypted_branch = double
26
+ expect(KnapsackPro::Crypto::BranchEncryptor).to receive(:call).with(repository_adapter.branch).and_return(encrypted_branch)
27
+
25
28
  action = double
26
29
  expect(KnapsackPro::Client::API::V1::BuildDistributions).to receive(:subset).with({
27
30
  commit_hash: repository_adapter.commit_hash,
28
- branch: repository_adapter.branch,
31
+ branch: encrypted_branch,
29
32
  node_total: ci_node_total,
30
33
  node_index: ci_node_index,
31
34
  test_files: encrypted_test_files,
@@ -302,6 +302,40 @@ describe KnapsackPro::Config::Env do
302
302
  end
303
303
  end
304
304
 
305
+ describe '.branch_encrypted' do
306
+ subject { described_class.branch_encrypted }
307
+
308
+ context 'when ENV exists' do
309
+ let(:branch_encrypted) { 'true' }
310
+ before { stub_const("ENV", { 'KNAPSACK_PRO_BRANCH_ENCRYPTED' => branch_encrypted }) }
311
+ it { should eq branch_encrypted }
312
+ end
313
+
314
+ context "when ENV doesn't exist" do
315
+ it { should be_nil }
316
+ end
317
+ end
318
+
319
+ describe '.branch_encrypted?' do
320
+ subject { described_class.branch_encrypted? }
321
+
322
+ before do
323
+ expect(described_class).to receive(:branch_encrypted).and_return(branch_encrypted)
324
+ end
325
+
326
+ context 'when enabled' do
327
+ let(:branch_encrypted) { 'true' }
328
+
329
+ it { should be true }
330
+ end
331
+
332
+ context 'when disabled' do
333
+ let(:branch_encrypted) { nil }
334
+
335
+ it { should be false }
336
+ end
337
+ end
338
+
305
339
  describe '.salt' do
306
340
  subject { described_class.salt }
307
341
 
@@ -0,0 +1,53 @@
1
+ describe KnapsackPro::Crypto::BranchEncryptor do
2
+ let(:branch) { 'feature-branch' }
3
+ let(:encryptor) { described_class.new(branch) }
4
+
5
+ describe '.call' do
6
+ subject { described_class.call(branch) }
7
+
8
+ before do
9
+ expect(KnapsackPro::Config::Env).to receive(:branch_encrypted?).and_return(branch_encrypted?)
10
+ end
11
+
12
+ context 'when branch encrypted flag enabled' do
13
+ let(:branch_encrypted?) { true }
14
+ let(:encryptor) { instance_double(described_class) }
15
+
16
+ it do
17
+ expect(described_class).to receive(:new).with(branch).and_return(encryptor)
18
+ result = double
19
+ expect(encryptor).to receive(:call).and_return(result)
20
+
21
+ expect(subject).to eq result
22
+ end
23
+ end
24
+
25
+ context 'when test files encrypted flag disabled' do
26
+ let(:branch_encrypted?) { false }
27
+
28
+ it { should eq branch }
29
+ end
30
+ end
31
+
32
+ describe '#call' do
33
+ subject { encryptor.call }
34
+
35
+ context 'when encryptable branch name' do
36
+ let(:branch) { 'feature-branch' }
37
+
38
+ before do
39
+ expect(KnapsackPro::Config::Env).to receive(:salt).at_least(1).and_return('123')
40
+ end
41
+
42
+ it { should eq '49e5bb1' }
43
+ end
44
+
45
+ described_class::NON_ENCRYPTABLE_BRANCHES.each do |branch_name|
46
+ context "when non encryptable branch name: #{branch_name}" do
47
+ let(:branch) { branch_name }
48
+
49
+ it { should eq branch_name }
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,8 +1,8 @@
1
1
  describe KnapsackPro::Crypto::Digestor do
2
2
  describe '.salt_hexdigest' do
3
- let(:path) { 'a_spec.rb' }
3
+ let(:str_to_encrypt) { 'a_spec.rb' }
4
4
 
5
- subject { described_class.salt_hexdigest(path) }
5
+ subject { described_class.salt_hexdigest(str_to_encrypt) }
6
6
 
7
7
  before do
8
8
  expect(KnapsackPro::Config::Env).to receive(:salt).at_least(1).and_return('123')
@@ -25,11 +25,14 @@ describe KnapsackPro::QueueAllocator do
25
25
  encrypted_test_files = double
26
26
  expect(KnapsackPro::Crypto::Encryptor).to receive(:call).with(test_files).and_return(encrypted_test_files)
27
27
 
28
+ encrypted_branch = double
29
+ expect(KnapsackPro::Crypto::BranchEncryptor).to receive(:call).with(repository_adapter.branch).and_return(encrypted_branch)
30
+
28
31
  action = double
29
32
  expect(KnapsackPro::Client::API::V1::Queues).to receive(:queue).with(
30
33
  can_initialize_queue: can_initialize_queue,
31
34
  commit_hash: repository_adapter.commit_hash,
32
- branch: repository_adapter.branch,
35
+ branch: encrypted_branch,
33
36
  node_total: ci_node_total,
34
37
  node_index: ci_node_index,
35
38
  node_build_id: ci_node_build_id,
@@ -89,6 +89,9 @@ describe KnapsackPro::Report do
89
89
  encrypted_test_files = double
90
90
  expect(KnapsackPro::Crypto::Encryptor).to receive(:call).with(unsymbolize_test_files).and_return(encrypted_test_files)
91
91
 
92
+ encrypted_branch = double
93
+ expect(KnapsackPro::Crypto::BranchEncryptor).to receive(:call).with(repository_adapter.branch).and_return(encrypted_branch)
94
+
92
95
  node_total = double
93
96
  node_index = double
94
97
  expect(KnapsackPro::Config::Env).to receive(:ci_node_total).and_return(node_total)
@@ -97,7 +100,7 @@ describe KnapsackPro::Report do
97
100
  action = double
98
101
  expect(KnapsackPro::Client::API::V1::BuildSubsets).to receive(:create).with({
99
102
  commit_hash: commit_hash,
100
- branch: branch,
103
+ branch: encrypted_branch,
101
104
  node_total: node_total,
102
105
  node_index: node_index,
103
106
  test_files: encrypted_test_files,
@@ -24,4 +24,11 @@ describe KnapsackPro::RepositoryAdapters::GitAdapter do
24
24
  it { should_not be_nil }
25
25
  it { should eq circle_branch } if ENV['CIRCLE_BRANCH']
26
26
  end
27
+
28
+ describe '#branches' do
29
+ subject { described_class.new.branches }
30
+
31
+ it { expect(subject.include?('master')).to be true }
32
+ it { expect(subject.include?(circle_branch)).to be true } if ENV['CIRCLE_BRANCH']
33
+ end
27
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knapsack_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.0
4
+ version: 0.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-08 00:00:00.000000000 Z
11
+ date: 2017-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -240,6 +240,7 @@ files:
240
240
  - lib/knapsack_pro/config/ci/travis.rb
241
241
  - lib/knapsack_pro/config/env.rb
242
242
  - lib/knapsack_pro/config/env_generator.rb
243
+ - lib/knapsack_pro/crypto/branch_encryptor.rb
243
244
  - lib/knapsack_pro/crypto/decryptor.rb
244
245
  - lib/knapsack_pro/crypto/digestor.rb
245
246
  - lib/knapsack_pro/crypto/encryptor.rb
@@ -269,6 +270,7 @@ files:
269
270
  - lib/knapsack_pro/utils.rb
270
271
  - lib/knapsack_pro/version.rb
271
272
  - lib/tasks/cucumber.rake
273
+ - lib/tasks/encrypted_branch_names.rake
272
274
  - lib/tasks/encrypted_test_file_names.rake
273
275
  - lib/tasks/install.rake
274
276
  - lib/tasks/minitest.rake
@@ -304,6 +306,7 @@ files:
304
306
  - spec/knapsack_pro/config/ci/travis_spec.rb
305
307
  - spec/knapsack_pro/config/env_generator_spec.rb
306
308
  - spec/knapsack_pro/config/env_spec.rb
309
+ - spec/knapsack_pro/crypto/branch_encryptor_spec.rb
307
310
  - spec/knapsack_pro/crypto/decryptor_spec.rb
308
311
  - spec/knapsack_pro/crypto/digestor_spec.rb
309
312
  - spec/knapsack_pro/crypto/encryptor_spec.rb
@@ -397,6 +400,7 @@ test_files:
397
400
  - spec/knapsack_pro/config/ci/travis_spec.rb
398
401
  - spec/knapsack_pro/config/env_generator_spec.rb
399
402
  - spec/knapsack_pro/config/env_spec.rb
403
+ - spec/knapsack_pro/crypto/branch_encryptor_spec.rb
400
404
  - spec/knapsack_pro/crypto/decryptor_spec.rb
401
405
  - spec/knapsack_pro/crypto/digestor_spec.rb
402
406
  - spec/knapsack_pro/crypto/encryptor_spec.rb