Skip to content

Commit 0e4e4a4

Browse files
mattsb42-awspraus
authored andcommitted
add unit test for CryptoConfig.with_item
1 parent 95cff49 commit 0e4e4a4

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

test/unit/encrypted/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Dummy stub to make linters work better."""

test/unit/encrypted/test_encrypted.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Unit tests for ``dynamodb_encryption_sdk.encrypted``."""
14+
import pytest
15+
16+
from dynamodb_encryption_sdk.encrypted import CryptoConfig
17+
from dynamodb_encryption_sdk.structures import AttributeActions, EncryptionContext
18+
from ..unit_test_utils import wrapped_cmp # noqa pylint: disable=unused-import
19+
20+
pytestmark = [pytest.mark.unit, pytest.mark.local]
21+
22+
23+
def test_with_item(wrapped_cmp):
24+
config = CryptoConfig(
25+
materials_provider=wrapped_cmp,
26+
encryption_context=EncryptionContext(attributes={}),
27+
attribute_actions=AttributeActions()
28+
)
29+
item = {
30+
'test': 'item',
31+
'with': 'some data'
32+
}
33+
new_config = config.with_item(item)
34+
35+
assert config.encryption_context.attributes == {}
36+
assert new_config.encryption_context.attributes == item

test/unit/material_providers/test_aws_kms.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from mock import MagicMock, sentinel
1616

1717
import boto3
18-
from boto3.dynamodb.types import Binary
1918
import botocore
2019
from moto import mock_kms
2120
import pytest

test/unit/unit_test_utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Helper utilities for unit tests."""
14+
import pytest
15+
16+
from dynamodb_encryption_sdk.delegated_keys.jce import JceNameLocalDelegatedKey
17+
from dynamodb_encryption_sdk.material_providers.wrapped import WrappedCryptographicMaterialsProvider
18+
19+
20+
@pytest.fixture
21+
def wrapped_cmp():
22+
wrapping_key = JceNameLocalDelegatedKey.generate('AES', 256)
23+
signing_key = JceNameLocalDelegatedKey.generate('HmacSHA512', 256)
24+
cmp = WrappedCryptographicMaterialsProvider(
25+
signing_key=signing_key,
26+
wrapping_key=wrapping_key,
27+
unwrapping_key=wrapping_key
28+
)
29+
return cmp

0 commit comments

Comments
 (0)