Skip to content

Commit

Permalink
Use fabricator for transferred files
Browse files Browse the repository at this point in the history
  • Loading branch information
lkleisa committed Jul 12, 2023
1 parent 750c17e commit 6527c02
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
16 changes: 14 additions & 2 deletions spec/controllers/api/teams_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,13 @@
it 'Receive method gets called to encrypt transferred encryptable' do
login_as(:bob)

prepare_transferred_encryptable(bob, alice, Crypto::Symmetric::Aes256iv)
Fabricate(
:transferred_file,
id_sender: alice.id,
receiver_inbox_folder: bob.inbox_folder,
receiver_pk: bob.public_key,
encryption_algorithm: Crypto::Symmetric::Aes256
)

expect_any_instance_of(EncryptableTransfer)
.to receive(:receive)
Expand All @@ -444,7 +450,13 @@
it 'Receive method to encrypt transferred encryptable dont get called on recent algorithm' do
login_as(:bob)

prepare_transferred_encryptable(bob, alice, Crypto::Symmetric::Aes256iv)
Fabricate(
:transferred_file,
id_sender: alice.id,
receiver_inbox_folder: bob.inbox_folder,
receiver_pk: bob.public_key,
encryption_algorithm: Crypto::Symmetric::Aes256iv
)

expect_any_instance_of(EncryptableTransfer)
.not_to receive(:receive)
Expand Down
23 changes: 23 additions & 0 deletions spec/fabricators/encryptables/credentials_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,26 @@
encryptable.encrypt(attrs[:team_password])
end
end

Fabricator(:transferred_file, from: 'Encryptable::File') do
transient :id_sender, :receiver_inbox_folder, :receiver_pk, :encryption_algorithm

name { Faker::File.file_name }
cleartext_file { Faker::Hacker.say_something_smart }
folder { |attrs| attrs[:receiver_inbox_folder] }
sender_id { |attrs| attrs[:id_sender] }
type { Encryptable::File }

before_create do |encryptable, attrs|
transfer_password = attrs[:encryption_algorithm].random_key

encrypted_transfer_password = Crypto::Rsa.encrypt(
transfer_password,
attrs[:receiver_pk]
)

encryptable.encrypted_transfer_password = Base64.encode64(encrypted_transfer_password)
encryptable.encrypt(transfer_password, Crypto::Symmetric::Aes256iv)

end
end
22 changes: 0 additions & 22 deletions spec/support/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,6 @@ def legacy_encrypt_private_key(private_key, password)
encrypted_private_key
end

def prepare_transferred_encryptable(bob, alice, encryption_algorithm)
encryptable_file = Encryptable::File.new(name: 'file',
folder_id: bob.inbox_folder.id,
cleartext_file: file_fixture('test_file.txt').read,
content_type: 'text/plain')

transfer_password = encryption_algorithm.random_key

encryptable_file.encrypt(transfer_password)

encrypted_transfer_password = Crypto::Rsa.encrypt(
transfer_password,
bob.public_key
)
encryptable_file.encrypted_transfer_password = Base64.encode64(encrypted_transfer_password)
encryptable_file.sender_id = alice.id
encryptable_file.folder = bob.inbox_folder
encryptable_file.save!

encryptable_file
end

def enable_openid_connect
allow_any_instance_of(AuthConfig)
.to receive(:settings_file)
Expand Down

0 comments on commit 6527c02

Please sign in to comment.