-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathtest_identifiers.py
65 lines (54 loc) · 2.44 KB
/
test_identifiers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Unit test suite for aws_encryption_sdk.identifiers"""
from mock import Mock
import pytest
from aws_encryption_sdk.exceptions import InvalidAlgorithmError
from aws_encryption_sdk.identifiers import Algorithm, EncryptionSuite, KDFSuite
@pytest.mark.parametrize('check_algorithm, safe_to_cache', (
(Algorithm.AES_128_GCM_IV12_TAG16, False),
(Algorithm.AES_192_GCM_IV12_TAG16, False),
(Algorithm.AES_256_GCM_IV12_TAG16, False),
(Algorithm.AES_128_GCM_IV12_TAG16_HKDF_SHA256, True),
(Algorithm.AES_192_GCM_IV12_TAG16_HKDF_SHA256, True),
(Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA256, True),
(Algorithm.AES_128_GCM_IV12_TAG16_HKDF_SHA256_ECDSA_P256, True),
(Algorithm.AES_192_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384, True),
(Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384, True)
))
def test_algorithm_safe_to_cache(check_algorithm, safe_to_cache):
if safe_to_cache:
assert check_algorithm.safe_to_cache()
else:
assert not check_algorithm.safe_to_cache()
@pytest.mark.parametrize('suite', [suite for suite in EncryptionSuite])
def test_encryption_suite_invalid_kdf(suite):
mock_kdf = Mock()
mock_kdf.input_length.return_value = 1
with pytest.raises(InvalidAlgorithmError) as excinfo:
suite.valid_kdf(mock_kdf)
excinfo.match(r'Invalid Algorithm definition: data_key_len must not be greater than kdf_input_len')
def build_valid_kdf_checks():
checks = []
for suite in EncryptionSuite:
checks.append((suite, KDFSuite.NONE, True))
checks.append((suite, KDFSuite.HKDF_SHA256, True))
checks.append((suite, KDFSuite.HKDF_SHA384, True))
return checks
@pytest.mark.parametrize('encryption, kdf, expected', build_valid_kdf_checks())
def test_encryption_suite_valid_kdf(encryption, kdf, expected):
actual = encryption.valid_kdf(kdf)
if expected:
assert actual
else:
assert not actual