"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "keystone/tests/unit/receipt/test_fernet_provider.py" between
keystone-16.0.1.tar.gz and keystone-17.0.0.tar.gz

About: OpenStack Keystone (Core Service: Identity) provides an authentication and authorization service for other OpenStack services. Provides a catalog of endpoints for all OpenStack services.
The "Ussuri" series (latest release).

test_fernet_provider.py  (keystone-16.0.1):test_fernet_provider.py  (keystone-17.0.0)
skipping to change at line 16 skipping to change at line 16
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import base64 import base64
import datetime import datetime
import hashlib import hashlib
import mock
import os import os
from unittest import mock
import uuid import uuid
from oslo_utils import timeutils from oslo_utils import timeutils
import six
from keystone.common import fernet_utils from keystone.common import fernet_utils
from keystone.common import provider_api from keystone.common import provider_api
from keystone.common import utils from keystone.common import utils
import keystone.conf import keystone.conf
from keystone import exception from keystone import exception
from keystone.identity.backends import resource_options as ro from keystone.identity.backends import resource_options as ro
from keystone.receipt.providers import fernet from keystone.receipt.providers import fernet
from keystone.receipt import receipt_formatters from keystone.receipt import receipt_formatters
from keystone.tests import unit from keystone.tests import unit
skipping to change at line 122 skipping to change at line 121
receipt_id receipt_id
) )
class TestReceiptFormatter(unit.TestCase): class TestReceiptFormatter(unit.TestCase):
def test_restore_padding(self): def test_restore_padding(self):
# 'a' will result in '==' padding, 'aa' will result in '=' padding, and # 'a' will result in '==' padding, 'aa' will result in '=' padding, and
# 'aaa' will result in no padding. # 'aaa' will result in no padding.
binary_to_test = [b'a', b'aa', b'aaa'] binary_to_test = [b'a', b'aa', b'aaa']
for binary in binary_to_test: for binary in binary_to_test:
# base64.urlsafe_b64encode takes six.binary_type and returns # base64.urlsafe_b64encode takes bytes and returns
# six.binary_type. # bytes.
encoded_string = base64.urlsafe_b64encode(binary) encoded_string = base64.urlsafe_b64encode(binary)
encoded_string = encoded_string.decode('utf-8') encoded_string = encoded_string.decode('utf-8')
# encoded_string is now six.text_type. # encoded_string is now str.
encoded_str_without_padding = encoded_string.rstrip('=') encoded_str_without_padding = encoded_string.rstrip('=')
self.assertFalse(encoded_str_without_padding.endswith('=')) self.assertFalse(encoded_str_without_padding.endswith('='))
encoded_str_with_padding_restored = ( encoded_str_with_padding_restored = (
receipt_formatters.ReceiptFormatter.restore_padding( receipt_formatters.ReceiptFormatter.restore_padding(
encoded_str_without_padding) encoded_str_without_padding)
) )
self.assertEqual(encoded_string, encoded_str_with_padding_restored) self.assertEqual(encoded_string, encoded_str_with_padding_restored)
class TestPayloads(unit.TestCase): class TestPayloads(unit.TestCase):
skipping to change at line 159 skipping to change at line 158
actual_time = timeutils.parse_isotime(actual) actual_time = timeutils.parse_isotime(actual)
# the granularity of timestamp string is microseconds and it's only the # the granularity of timestamp string is microseconds and it's only the
# last digit in the representation that's different, so use a delta # last digit in the representation that's different, so use a delta
# just above nanoseconds. # just above nanoseconds.
return self.assertCloseEnoughForGovernmentWork(exp_time, actual_time, return self.assertCloseEnoughForGovernmentWork(exp_time, actual_time,
delta=1e-05) delta=1e-05)
def test_strings_can_be_converted_to_bytes(self): def test_strings_can_be_converted_to_bytes(self):
s = token_provider.random_urlsafe_str() s = token_provider.random_urlsafe_str()
self.assertIsInstance(s, six.text_type) self.assertIsInstance(s, str)
b = receipt_formatters.ReceiptPayload.random_urlsafe_str_to_bytes(s) b = receipt_formatters.ReceiptPayload.random_urlsafe_str_to_bytes(s)
self.assertIsInstance(b, six.binary_type) self.assertIsInstance(b, bytes)
def test_uuid_hex_to_byte_conversions(self): def test_uuid_hex_to_byte_conversions(self):
payload_cls = receipt_formatters.ReceiptPayload payload_cls = receipt_formatters.ReceiptPayload
expected_hex_uuid = uuid.uuid4().hex expected_hex_uuid = uuid.uuid4().hex
uuid_obj = uuid.UUID(expected_hex_uuid) uuid_obj = uuid.UUID(expected_hex_uuid)
expected_uuid_in_bytes = uuid_obj.bytes expected_uuid_in_bytes = uuid_obj.bytes
actual_uuid_in_bytes = payload_cls.convert_uuid_hex_to_bytes( actual_uuid_in_bytes = payload_cls.convert_uuid_hex_to_bytes(
expected_hex_uuid) expected_hex_uuid)
self.assertEqual(expected_uuid_in_bytes, actual_uuid_in_bytes) self.assertEqual(expected_uuid_in_bytes, actual_uuid_in_bytes)
skipping to change at line 260 skipping to change at line 259
"""Create a "thumbprint" of the current key repository. """Create a "thumbprint" of the current key repository.
Because key files are renamed, this produces a hash of the contents of Because key files are renamed, this produces a hash of the contents of
the key files, ignoring their filenames. the key files, ignoring their filenames.
The resulting signature can be used, for example, to ensure that you The resulting signature can be used, for example, to ensure that you
have a unique set of keys after you perform a key rotation (taking a have a unique set of keys after you perform a key rotation (taking a
static set of keys, and simply shuffling them, would fail such a test). static set of keys, and simply shuffling them, would fail such a test).
""" """
# Load the keys into a list, keys is list of six.text_type. # Load the keys into a list, keys is list of str.
key_utils = fernet_utils.FernetUtils( key_utils = fernet_utils.FernetUtils(
CONF.fernet_receipts.key_repository, CONF.fernet_receipts.key_repository,
CONF.fernet_receipts.max_active_keys, CONF.fernet_receipts.max_active_keys,
'fernet_receipts' 'fernet_receipts'
) )
keys = key_utils.load_keys() keys = key_utils.load_keys()
# Sort the list of keys by the keys themselves (they were previously # Sort the list of keys by the keys themselves (they were previously
# sorted by filename). # sorted by filename).
keys.sort() keys.sort()
# Create the thumbprint using all keys in the repository. # Create the thumbprint using all keys in the repository.
signature = hashlib.sha1() signature = hashlib.sha1()
for key in keys: for key in keys:
# Need to convert key to six.binary_type for update. # Need to convert key to bytes for update.
signature.update(key.encode('utf-8')) signature.update(key.encode('utf-8'))
return signature.hexdigest() return signature.hexdigest()
def assertRepositoryState(self, expected_size): def assertRepositoryState(self, expected_size):
"""Validate the state of the key repository.""" """Validate the state of the key repository."""
self.assertEqual(expected_size, self.key_repository_size) self.assertEqual(expected_size, self.key_repository_size)
self.assertUniqueRepositoryState() self.assertUniqueRepositoryState()
def assertUniqueRepositoryState(self): def assertUniqueRepositoryState(self):
"""Ensure that the current key repo state has not been seen before.""" """Ensure that the current key repo state has not been seen before."""
 End of changes. 9 change blocks. 
9 lines changed or deleted 8 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)