Skip to content

Commit

Permalink
test: Add more Ruby fixture tests for crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
kgilpin committed Aug 2, 2022
1 parent f1111d3 commit 00c1d5f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 768 deletions.
2 changes: 1 addition & 1 deletion packages/scanner/test/fixtures/ruby/fixture/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ source "https://rubygems.org"

gem 'byebug'
gem 'rake'
gem 'appmap', github: 'applandinc/appmap-ruby', branch: 'master'
gem 'appmap', github: 'applandinc/appmap-ruby', branch: 'feat/crypto-algorithm'
gem 'minitest'
4 changes: 2 additions & 2 deletions packages/scanner/test/fixtures/ruby/fixture/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/applandinc/appmap-ruby.git
revision: cda70741cdd594f92863d2c32842c9627af38506
branch: master
revision: 216c45468bdf50251fd8fcfd45849acaf997bd73
branch: feat/crypto-algorithm
specs:
appmap (0.83.4)
activesupport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ def self.encrypt_aes_128_cbc
end

# @label command
def self.encrypt_aes_256_gcm(record_id)
def self.encrypt_aes_256_gcm(record_id, key: nil)
data = "Very, very confidential data"
cipher = OpenSSL::Cipher.new('aes-256-gcm')
cipher.encrypt
key = cipher.random_key
if key
cipher.key = key
else
key = cipher.random_key
end
iv = cipher.random_iv
cipher.auth_data = record_id.to_s

Expand Down
14 changes: 13 additions & 1 deletion packages/scanner/test/fixtures/ruby/fixture/test/crypt_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ def test_crypt_aes_128_cbc
end

def test_crypt_aes_256_gcm
ciphertext = Crypt::Command.encrypt_aes_256_gcm(:record_id)
ciphertext = Crypt::Command.encrypt_aes_256_gcm('test_crypt_aes_256_gcm')
assert_equal 28, ciphertext.length
end

def test_hard_coded_key
key = Base64.decode64 "f9hmz/Sh93xIdpfiU7ja385+1QtLf5GVX4MaJwjqh0E="
ciphertext = Crypt::Command.encrypt_aes_256_gcm('test_hard_coded_key', key: key)
assert_equal 28, ciphertext.length
end

def test_random_key
key = OpenSSL::Random.random_bytes(32)
ciphertext = Crypt::Command.encrypt_aes_256_gcm('test_hard_coded_key', key: key)
assert_equal 28, ciphertext.length
end
end
Loading

0 comments on commit 00c1d5f

Please sign in to comment.