From 0c29faddec85173a6753da33dac1b35a7bd5bddd Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Sun, 10 Apr 2022 15:44:51 +0300 Subject: [PATCH] Simplify tests --- src/borg/testsuite/crypto.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/borg/testsuite/crypto.py b/src/borg/testsuite/crypto.py index 5dac74f5f..fd0a57e77 100644 --- a/src/borg/testsuite/crypto.py +++ b/src/borg/testsuite/crypto.py @@ -11,7 +11,6 @@ from ..crypto.low_level import hkdf_hmac_sha512 from ..crypto.low_level import AES, hmac_sha256 from ..crypto.key import KeyfileKey, UnsupportedKeyFormatError, RepoKey, FlexiKey -from ..helpers.passphrase import Passphrase from ..helpers import msgpack from ..constants import KEY_ALGORITHMS @@ -260,7 +259,7 @@ def test_hkdf_hmac_sha512_5(self): assert okm == bytes.fromhex('1407d46013d98bc6decefcfee55f0f90b0c7f63d68eb1a80eaf07e953cfc0a3a5240a155d6e4daa965bb') -def test_decrypt_key_file_argon2_aes256_ctr_hmac_sha256(monkeypatch): +def test_decrypt_key_file_argon2_aes256_ctr_hmac_sha256(): plain = b'hello' # echo -n "hello, pass phrase" | argon2 saltsaltsaltsalt -id -t 1 -k 8 -p 1 -l 64 -r key = bytes.fromhex('d07cc7f9cfb483303e0b9fec176b2a9c559bb70c3a9fb0d5f9c0c23527cd09570212449f09f8cd28c1a41b73fa0098e889c3f2642e87c392e51f95d70d248d9d') @@ -282,16 +281,14 @@ def test_decrypt_key_file_argon2_aes256_ctr_hmac_sha256(monkeypatch): 'algorithm': 'argon2 aes256-ctr hmac-sha256', 'data': envelope, }) - monkeypatch.setenv('BORG_PASSPHRASE', "hello, pass phrase") - passphrase = Passphrase.new() key = KeyfileKey(None) - decrypted = key.decrypt_key_file(encrypted, passphrase) + decrypted = key.decrypt_key_file(encrypted, "hello, pass phrase") assert decrypted == plain -def test_decrypt_key_file_pbkdf2_sha256_aes256_ctr_hmac_sha256(monkeypatch): +def test_decrypt_key_file_pbkdf2_sha256_aes256_ctr_hmac_sha256(): plain = b'hello' salt = b'salt'*4 passphrase = "hello, pass phrase" @@ -313,10 +310,8 @@ def test_decrypt_key_file_pbkdf2_sha256_aes256_ctr_hmac_sha256(monkeypatch): assert decrypted == plain -def test_decrypt_key_file_unsupported_algorithm(monkeypatch): +def test_decrypt_key_file_unsupported_algorithm(): """We will add more algorithms in the future. We should raise a helpful error.""" - monkeypatch.setenv('BORG_PASSPHRASE', "hello, pass phrase") - passphrase = Passphrase.new() key = KeyfileKey(None) encrypted = msgpack.packb({ 'algorithm': 'THIS ALGORITHM IS NOT SUPPORTED', @@ -324,20 +319,18 @@ def test_decrypt_key_file_unsupported_algorithm(monkeypatch): }) with pytest.raises(UnsupportedKeyFormatError): - key.decrypt_key_file(encrypted, passphrase) + key.decrypt_key_file(encrypted, "hello, pass phrase") -def test_decrypt_key_file_v2_is_unsupported(monkeypatch): +def test_decrypt_key_file_v2_is_unsupported(): """There may eventually be a version 2 of the format. For now we should raise a helpful error.""" - monkeypatch.setenv('BORG_PASSPHRASE', "hello, pass phrase") - passphrase = Passphrase.new() key = KeyfileKey(None) encrypted = msgpack.packb({ 'version': 2, }) with pytest.raises(UnsupportedKeyFormatError): - key.decrypt_key_file(encrypted, passphrase) + key.decrypt_key_file(encrypted, "hello, pass phrase") @pytest.mark.parametrize('cli_argument, expected_algorithm', KEY_ALGORITHMS.items())