Skip to content

Commit d579e71

Browse files
committed
Changes in one_kms_cmk and made random plaintext static
1 parent 47b70ff commit d579e71

6 files changed

+29
-14
lines changed

examples/src/one_kms_cmk.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Copyright 2019 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+
"""Example showing basic encryption and decryption using one KMS CMK of a value already in memory."""
114
import aws_encryption_sdk
215

316

@@ -17,9 +30,7 @@ def encrypt_decrypt(key_arn, source_plaintext, botocore_session=None):
1730
)
1831

1932
# Decrypt the encrypted message using the AWS Encryption SDK. It returns the decrypted message and the header
20-
plaintext, decrypted_message_header = aws_encryption_sdk.decrypt(
21-
source=ciphertext, key_provider=kms_key_provider
22-
)
33+
plaintext, decrypted_message_header = aws_encryption_sdk.decrypt(source=ciphertext, key_provider=kms_key_provider)
2334

2435
# Check if the original message and the decrypted message are the same
2536
assert source_plaintext == plaintext

examples/test/examples_test_utils.py

+4
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@
1717
os.environ["AWS_ENCRYPTION_SDK_EXAMPLES_TESTING"] = "yes"
1818
sys.path.extend([os.sep.join([os.path.dirname(__file__), "..", "..", "test", "integration"])])
1919

20+
static_plaintext = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent non feugiat leo. Aenean iaculis tellus ut velit consectetur, quis convallis orci eleifend. Sed eu dictum sapien. Nulla facilisi. Suspendisse potenti. Proin vehicula vehicula maximus. Donec varius et elit vel rutrum. Nulla lacinia neque turpis, quis consequat orci pharetra et. Etiam consequat ullamcorper mauris. Vivamus molestie mollis mauris a gravida. Curabitur sed bibendum nisl.'
21+
static_plaintext = str.encode(static_plaintext)
22+
2023
from integration_test_utils import get_cmk_arn # noqa pylint: disable=unused-import,import-error
24+

examples/test/test_i_basic_encryption.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818

1919
from ..src.basic_encryption import cycle_string
2020
from .examples_test_utils import get_cmk_arn
21+
from .examples_test_utils import static_plaintext
2122

2223

2324
pytestmark = [pytest.mark.examples]
2425

2526

2627
def test_cycle_string():
27-
plaintext = os.urandom(1024)
28+
plaintext = static_plaintext
2829
cmk_arn = get_cmk_arn()
2930
cycle_string(key_arn=cmk_arn, source_plaintext=plaintext, botocore_session=botocore.session.Session())

examples/test/test_i_basic_file_encryption_with_multiple_providers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from ..src.basic_file_encryption_with_multiple_providers import cycle_file
2121
from .examples_test_utils import get_cmk_arn
22+
from .examples_test_utils import static_plaintext
2223

2324

2425
pytestmark = [pytest.mark.examples]
@@ -28,7 +29,7 @@ def test_cycle_file():
2829
cmk_arn = get_cmk_arn()
2930
handle, filename = tempfile.mkstemp()
3031
with open(filename, "wb") as f:
31-
f.write(os.urandom(1024))
32+
f.write(static_plaintext)
3233
try:
3334
new_files = cycle_file(
3435
key_arn=cmk_arn, source_plaintext_filename=filename, botocore_session=botocore.session.Session()

examples/test/test_i_basic_file_encryption_with_raw_key_provider.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import pytest
1818

1919
from ..src.basic_file_encryption_with_raw_key_provider import cycle_file
20+
from .examples_test_utils import static_plaintext
2021

2122

2223
pytestmark = [pytest.mark.examples]
@@ -25,7 +26,7 @@
2526
def test_cycle_file():
2627
handle, filename = tempfile.mkstemp()
2728
with open(filename, "wb") as f:
28-
f.write(os.urandom(1024))
29+
f.write(static_plaintext)
2930
try:
3031
new_files = cycle_file(source_plaintext_filename=filename)
3132
for f in new_files:

examples/test/test_i_one_kms_cmk.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License"). You
44
# may not use this file except in compliance with the License. A copy of
@@ -10,24 +10,21 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""Unit test suite for the Strings examples in the AWS-hosted documentation."""
13+
"""Unit test suite for the encryption and decryption using one KMS CMK example."""
1414
import os
1515

1616
import botocore.session
1717
import pytest
1818

1919
from ..src.one_kms_cmk import encrypt_decrypt
2020
from .examples_test_utils import get_cmk_arn
21+
from .examples_test_utils import static_plaintext
2122

2223

2324
pytestmark = [pytest.mark.examples]
2425

2526

2627
def test_one_kms_cmk():
27-
plaintext = os.urandom(1024)
28+
plaintext = static_plaintext
2829
cmk_arn = get_cmk_arn()
29-
encrypt_decrypt(
30-
key_arn=cmk_arn,
31-
source_plaintext=plaintext,
32-
botocore_session=botocore.session.Session(),
33-
)
30+
encrypt_decrypt(key_arn=cmk_arn, source_plaintext=plaintext, botocore_session=botocore.session.Session())

0 commit comments

Comments
 (0)