Sha256: bb5a78504c3011477bd3bf3c7dd7c7e5c67d2171199dd5a4984b2b711abbdf7a

Contents?: true

Size: 1.57 KB

Versions: 24

Compression:

Stored size: 1.57 KB

Contents

module KnapsackPro
  module Crypto
    class Decryptor
      class MissingEncryptedTestFileError < StandardError; end
      class TooManyEncryptedTestFilesError < StandardError; end

      def self.call(test_files, encrypted_test_files)
        if KnapsackPro::Config::Env.test_files_encrypted?
          new(test_files, encrypted_test_files).call
        else
          # those test files are not encrypted
          encrypted_test_files
        end
      end

      def initialize(test_files, encrypted_test_files)
        @test_files = test_files
        @encrypted_test_files = encrypted_test_files
      end

      def call
        decrypted_test_files = []

        test_files.each do |test_file|
          encrypted_path = Digestor.salt_hexdigest(test_file['path'])
          encrypted_test_file = find_encrypted_test_file(encrypted_path)
          next if encrypted_test_file.nil?

          decrypted_test_file = encrypted_test_file.dup
          decrypted_test_file['path'] = test_file['path']

          decrypted_test_files << decrypted_test_file
        end

        decrypted_test_files
      end

      private

      attr_reader :test_files,
        :encrypted_test_files

      def find_encrypted_test_file(encrypted_path)
        test_files = encrypted_test_files.select do |t|
          t['path'] == encrypted_path
        end

        if test_files.size == 1
          test_files.first
        elsif test_files.size > 1
          raise TooManyEncryptedTestFilesError.new("Found more than one encrypted test file for encrypted path #{encrypted_path}")
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
knapsack_pro-0.31.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.30.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.29.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.28.1 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.28.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.27.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.26.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.25.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.24.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.23.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.22.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.21.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.20.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.19.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.18.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.17.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.16.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.15.2 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.15.1 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-0.15.0 lib/knapsack_pro/crypto/decryptor.rb