mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-25 17:27:31 +00:00
Simplify tests
This commit is contained in:
parent
6cf5ae4ca1
commit
0c29faddec
1 changed files with 7 additions and 14 deletions
|
@ -11,7 +11,6 @@
|
||||||
from ..crypto.low_level import hkdf_hmac_sha512
|
from ..crypto.low_level import hkdf_hmac_sha512
|
||||||
from ..crypto.low_level import AES, hmac_sha256
|
from ..crypto.low_level import AES, hmac_sha256
|
||||||
from ..crypto.key import KeyfileKey, UnsupportedKeyFormatError, RepoKey, FlexiKey
|
from ..crypto.key import KeyfileKey, UnsupportedKeyFormatError, RepoKey, FlexiKey
|
||||||
from ..helpers.passphrase import Passphrase
|
|
||||||
from ..helpers import msgpack
|
from ..helpers import msgpack
|
||||||
from ..constants import KEY_ALGORITHMS
|
from ..constants import KEY_ALGORITHMS
|
||||||
|
|
||||||
|
@ -260,7 +259,7 @@ def test_hkdf_hmac_sha512_5(self):
|
||||||
assert okm == bytes.fromhex('1407d46013d98bc6decefcfee55f0f90b0c7f63d68eb1a80eaf07e953cfc0a3a5240a155d6e4daa965bb')
|
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'
|
plain = b'hello'
|
||||||
# echo -n "hello, pass phrase" | argon2 saltsaltsaltsalt -id -t 1 -k 8 -p 1 -l 64 -r
|
# echo -n "hello, pass phrase" | argon2 saltsaltsaltsalt -id -t 1 -k 8 -p 1 -l 64 -r
|
||||||
key = bytes.fromhex('d07cc7f9cfb483303e0b9fec176b2a9c559bb70c3a9fb0d5f9c0c23527cd09570212449f09f8cd28c1a41b73fa0098e889c3f2642e87c392e51f95d70d248d9d')
|
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',
|
'algorithm': 'argon2 aes256-ctr hmac-sha256',
|
||||||
'data': envelope,
|
'data': envelope,
|
||||||
})
|
})
|
||||||
monkeypatch.setenv('BORG_PASSPHRASE', "hello, pass phrase")
|
|
||||||
passphrase = Passphrase.new()
|
|
||||||
key = KeyfileKey(None)
|
key = KeyfileKey(None)
|
||||||
|
|
||||||
decrypted = key.decrypt_key_file(encrypted, passphrase)
|
decrypted = key.decrypt_key_file(encrypted, "hello, pass phrase")
|
||||||
|
|
||||||
assert decrypted == plain
|
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'
|
plain = b'hello'
|
||||||
salt = b'salt'*4
|
salt = b'salt'*4
|
||||||
passphrase = "hello, pass phrase"
|
passphrase = "hello, pass phrase"
|
||||||
|
@ -313,10 +310,8 @@ def test_decrypt_key_file_pbkdf2_sha256_aes256_ctr_hmac_sha256(monkeypatch):
|
||||||
assert decrypted == plain
|
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."""
|
"""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)
|
key = KeyfileKey(None)
|
||||||
encrypted = msgpack.packb({
|
encrypted = msgpack.packb({
|
||||||
'algorithm': 'THIS ALGORITHM IS NOT SUPPORTED',
|
'algorithm': 'THIS ALGORITHM IS NOT SUPPORTED',
|
||||||
|
@ -324,20 +319,18 @@ def test_decrypt_key_file_unsupported_algorithm(monkeypatch):
|
||||||
})
|
})
|
||||||
|
|
||||||
with pytest.raises(UnsupportedKeyFormatError):
|
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."""
|
"""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)
|
key = KeyfileKey(None)
|
||||||
encrypted = msgpack.packb({
|
encrypted = msgpack.packb({
|
||||||
'version': 2,
|
'version': 2,
|
||||||
})
|
})
|
||||||
|
|
||||||
with pytest.raises(UnsupportedKeyFormatError):
|
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())
|
@pytest.mark.parametrize('cli_argument, expected_algorithm', KEY_ALGORITHMS.items())
|
||||||
|
|
Loading…
Reference in a new issue