Sha256: 20a694f7d20512666c8930a2ee12d507917568d1ecd4a7fb241454eb92067b38

Contents?: true

Size: 1.54 KB

Versions: 25

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

module KnapsackPro
  module Crypto
    class Decryptor
      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

25 entries across 25 versions & 1 rubygems

Version Path
knapsack_pro-7.14.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.13.1 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.13.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.12.1 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.12.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.11.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.10.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.9.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.8.2 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.8.1 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.8.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.7.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.6.2 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.6.1 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.6.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.1.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.0.1 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-7.0.0 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-6.0.4 lib/knapsack_pro/crypto/decryptor.rb
knapsack_pro-6.0.3 lib/knapsack_pro/crypto/decryptor.rb