mirror of https://github.com/OpenKMIP/PyKMIP.git
Updating the AttributeValue factory
This change updates the AttributeValue factory, removing and streamlining code. Support for several basic primitive attributes are added in addition to a redesigned test suite for the factory.
This commit is contained in:
parent
94646337c3
commit
b0bab4b8bc
|
@ -13,26 +13,9 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from kmip.core.enums import AttributeType
|
||||
from kmip.core.enums import Tags
|
||||
|
||||
from kmip.core.primitives import DateTime
|
||||
|
||||
from kmip.core.attributes import ApplicationSpecificInformation
|
||||
from kmip.core.attributes import ContactInformation
|
||||
from kmip.core.attributes import CryptographicAlgorithm
|
||||
from kmip.core.attributes import CryptographicLength
|
||||
from kmip.core.attributes import CryptographicUsageMask
|
||||
from kmip.core.attributes import CryptographicParameters
|
||||
from kmip.core.attributes import CustomAttribute
|
||||
from kmip.core.attributes import Digest
|
||||
from kmip.core.attributes import Name
|
||||
from kmip.core.attributes import ObjectGroup
|
||||
from kmip.core.attributes import UniqueIdentifier
|
||||
from kmip.core.attributes import ObjectType
|
||||
from kmip.core.attributes import OperationPolicyName
|
||||
from kmip.core.attributes import HashingAlgorithm
|
||||
|
||||
from kmip.core import attributes
|
||||
from kmip.core import enums
|
||||
from kmip.core import primitives
|
||||
from kmip.core import utils
|
||||
|
||||
|
||||
|
@ -40,184 +23,138 @@ class AttributeValueFactory(object):
|
|||
|
||||
def create_attribute_value(self, name, value):
|
||||
# Switch on the name of the attribute
|
||||
if name is AttributeType.UNIQUE_IDENTIFIER:
|
||||
value = self._create_unique_identifier(value)
|
||||
elif name is AttributeType.NAME:
|
||||
value = self._create_name(value)
|
||||
elif name is AttributeType.OBJECT_TYPE:
|
||||
value = self._create_object_type(value)
|
||||
elif name is AttributeType.CRYPTOGRAPHIC_ALGORITHM:
|
||||
value = self._create_cryptographic_algorithm(value)
|
||||
elif name is AttributeType.CRYPTOGRAPHIC_LENGTH:
|
||||
value = self._create_cryptographic_length(value)
|
||||
elif name is AttributeType.CRYPTOGRAPHIC_PARAMETERS:
|
||||
value = self._create_cryptographic_parameters(value)
|
||||
elif name is AttributeType.CRYPTOGRAPHIC_DOMAIN_PARAMETERS:
|
||||
value = self._create_cryptographic_domain_parameters(value)
|
||||
elif name is AttributeType.CERTIFICATE_TYPE:
|
||||
value = self._create_certificate_type(value)
|
||||
elif name is AttributeType.CERTIFICATE_LENGTH:
|
||||
value = self._create_certificate_length(value)
|
||||
elif name is AttributeType.X_509_CERTIFICATE_IDENTIFIER:
|
||||
value = self._create_x_509_certificate_identifier(value)
|
||||
elif name is AttributeType.X_509_CERTIFICATE_SUBJECT:
|
||||
value = self._create_x_509_certificate_subject(value)
|
||||
elif name is AttributeType.X_509_CERTIFICATE_ISSUER:
|
||||
value = self._create_x_509_certificate_issuer(value)
|
||||
elif name is AttributeType.CERTIFICATE_IDENTIFIER:
|
||||
value = self._create_certificate_identifier(value)
|
||||
elif name is AttributeType.CERTIFICATE_SUBJECT:
|
||||
value = self._create_certificate_subject(value)
|
||||
elif name is AttributeType.CERTIFICATE_ISSUER:
|
||||
value = self._create_certificate_issuer(value)
|
||||
elif name is AttributeType.DIGITAL_SIGNATURE_ALGORITHM:
|
||||
value = self._create_digital_signature_algorithm(value)
|
||||
elif name is AttributeType.DIGEST:
|
||||
value = self._create_digest()
|
||||
elif name is AttributeType.OPERATION_POLICY_NAME:
|
||||
value = self._create_operation_policy_name(value)
|
||||
elif name is AttributeType.CRYPTOGRAPHIC_USAGE_MASK:
|
||||
value = self._create_cryptographic_usage_mask(value)
|
||||
elif name is AttributeType.LEASE_TIME:
|
||||
value = self._create_lease_time(value)
|
||||
elif name is AttributeType.USAGE_LIMITS:
|
||||
value = self._create_usage_limits(value)
|
||||
elif name is AttributeType.STATE:
|
||||
value = self._create_state(value)
|
||||
elif name is AttributeType.INITIAL_DATE:
|
||||
value = self._create_initial_date(value)
|
||||
elif name is AttributeType.ACTIVATION_DATE:
|
||||
value = self._create_activation_date(value)
|
||||
elif name is AttributeType.PROCESS_START_DATE:
|
||||
value = self._create_process_start_date(value)
|
||||
elif name is AttributeType.PROTECT_STOP_DATE:
|
||||
value = self._create_protect_stop_date(value)
|
||||
elif name is AttributeType.DEACTIVATION_DATE:
|
||||
value = self._create_deactivation_date(value)
|
||||
elif name is AttributeType.DESTROY_DATE:
|
||||
value = self._create_destroy_date(value)
|
||||
elif name is AttributeType.COMPROMISE_OCCURRENCE_DATE:
|
||||
value = self._create_compromise_occurrence_date(value)
|
||||
elif name is AttributeType.COMPROMISE_DATE:
|
||||
value = self._create_compromise_date(value)
|
||||
elif name is AttributeType.REVOCATION_REASON:
|
||||
value = self._create_revocation_reason(value)
|
||||
elif name is AttributeType.ARCHIVE_DATE:
|
||||
value = self._create_archive_date(value)
|
||||
elif name is AttributeType.OBJECT_GROUP:
|
||||
value = self._create_object_group(value)
|
||||
elif name is AttributeType.FRESH:
|
||||
value = self._create_fresh(value)
|
||||
elif name is AttributeType.LINK:
|
||||
value = self._create_link(value)
|
||||
elif name is AttributeType.APPLICATION_SPECIFIC_INFORMATION:
|
||||
value = self._create_application_specific_information(value)
|
||||
elif name is AttributeType.CONTACT_INFORMATION:
|
||||
value = self._create_contact_information(value)
|
||||
elif name is AttributeType.LAST_CHANGE_DATE:
|
||||
value = self._create_last_change_date(value)
|
||||
elif name is AttributeType.CUSTOM_ATTRIBUTE:
|
||||
value = self._create_custom_attribute(value)
|
||||
if name is enums.AttributeType.UNIQUE_IDENTIFIER:
|
||||
return attributes.UniqueIdentifier(value)
|
||||
elif name is enums.AttributeType.NAME:
|
||||
return self._create_name(value)
|
||||
elif name is enums.AttributeType.OBJECT_TYPE:
|
||||
return attributes.ObjectType()
|
||||
elif name is enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM:
|
||||
return attributes.CryptographicAlgorithm(value)
|
||||
elif name is enums.AttributeType.CRYPTOGRAPHIC_LENGTH:
|
||||
return self._create_cryptographic_length(value)
|
||||
elif name is enums.AttributeType.CRYPTOGRAPHIC_PARAMETERS:
|
||||
return self._create_cryptographic_parameters(value)
|
||||
elif name is enums.AttributeType.CRYPTOGRAPHIC_DOMAIN_PARAMETERS:
|
||||
raise NotImplementedError()
|
||||
elif name is enums.AttributeType.CERTIFICATE_TYPE:
|
||||
raise NotImplementedError()
|
||||
elif name is enums.AttributeType.CERTIFICATE_LENGTH:
|
||||
return primitives.Integer(value, enums.Tags.CERTIFICATE_LENGTH)
|
||||
elif name is enums.AttributeType.X_509_CERTIFICATE_IDENTIFIER:
|
||||
raise NotImplementedError()
|
||||
elif name is enums.AttributeType.X_509_CERTIFICATE_SUBJECT:
|
||||
raise NotImplementedError()
|
||||
elif name is enums.AttributeType.X_509_CERTIFICATE_ISSUER:
|
||||
raise NotImplementedError()
|
||||
elif name is enums.AttributeType.CERTIFICATE_IDENTIFIER:
|
||||
raise NotImplementedError()
|
||||
elif name is enums.AttributeType.CERTIFICATE_SUBJECT:
|
||||
raise NotImplementedError()
|
||||
elif name is enums.AttributeType.CERTIFICATE_ISSUER:
|
||||
raise NotImplementedError()
|
||||
elif name is enums.AttributeType.DIGITAL_SIGNATURE_ALGORITHM:
|
||||
raise NotImplementedError()
|
||||
elif name is enums.AttributeType.DIGEST:
|
||||
return attributes.Digest()
|
||||
elif name is enums.AttributeType.OPERATION_POLICY_NAME:
|
||||
return attributes.OperationPolicyName(value)
|
||||
elif name is enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK:
|
||||
return self._create_cryptographic_usage_mask(value)
|
||||
elif name is enums.AttributeType.LEASE_TIME:
|
||||
return primitives.Interval(value, enums.Tags.LEASE_TIME)
|
||||
elif name is enums.AttributeType.USAGE_LIMITS:
|
||||
raise NotImplementedError()
|
||||
elif name is enums.AttributeType.STATE:
|
||||
raise NotImplementedError()
|
||||
elif name is enums.AttributeType.INITIAL_DATE:
|
||||
return primitives.DateTime(value, enums.Tags.INITIAL_DATE)
|
||||
elif name is enums.AttributeType.ACTIVATION_DATE:
|
||||
return primitives.DateTime(value, enums.Tags.ACTIVATION_DATE)
|
||||
elif name is enums.AttributeType.PROCESS_START_DATE:
|
||||
return primitives.DateTime(value, enums.Tags.PROCESS_START_DATE)
|
||||
elif name is enums.AttributeType.PROTECT_STOP_DATE:
|
||||
return primitives.DateTime(value, enums.Tags.PROTECT_STOP_DATE)
|
||||
elif name is enums.AttributeType.DEACTIVATION_DATE:
|
||||
return primitives.DateTime(value, enums.Tags.DEACTIVATION_DATE)
|
||||
elif name is enums.AttributeType.DESTROY_DATE:
|
||||
return primitives.DateTime(value, enums.Tags.DESTROY_DATE)
|
||||
elif name is enums.AttributeType.COMPROMISE_OCCURRENCE_DATE:
|
||||
return primitives.DateTime(
|
||||
value, enums.Tags.COMPROMISE_OCCURRENCE_DATE)
|
||||
elif name is enums.AttributeType.COMPROMISE_DATE:
|
||||
return primitives.DateTime(value, enums.Tags.COMPROMISE_DATE)
|
||||
elif name is enums.AttributeType.REVOCATION_REASON:
|
||||
raise NotImplementedError()
|
||||
elif name is enums.AttributeType.ARCHIVE_DATE:
|
||||
return primitives.DateTime(value, enums.Tags.ARCHIVE_DATE)
|
||||
elif name is enums.AttributeType.OBJECT_GROUP:
|
||||
return self._create_object_group(value)
|
||||
elif name is enums.AttributeType.FRESH:
|
||||
return primitives.Boolean(value, enums.Tags.FRESH)
|
||||
elif name is enums.AttributeType.LINK:
|
||||
raise NotImplementedError()
|
||||
elif name is enums.AttributeType.APPLICATION_SPECIFIC_INFORMATION:
|
||||
return self._create_application_specific_information(value)
|
||||
elif name is enums.AttributeType.CONTACT_INFORMATION:
|
||||
return self._create_contact_information(value)
|
||||
elif name is enums.AttributeType.LAST_CHANGE_DATE:
|
||||
return primitives.DateTime(value, enums.Tags.LAST_CHANGE_DATE)
|
||||
elif name is enums.AttributeType.CUSTOM_ATTRIBUTE:
|
||||
return attributes.CustomAttribute(value)
|
||||
else:
|
||||
if not isinstance(name, str):
|
||||
raise ValueError('Unrecognized attribute type: '
|
||||
'{0}'.format(name))
|
||||
elif name.startswith('x-'):
|
||||
# Custom attribute indicated
|
||||
value = self._create_custom_attribute(value)
|
||||
|
||||
return value
|
||||
|
||||
def _create_unique_identifier(self, uuid):
|
||||
return UniqueIdentifier(uuid)
|
||||
return attributes.CustomAttribute(value)
|
||||
|
||||
def _create_name(self, name):
|
||||
if name is not None:
|
||||
name_value = name.name_value
|
||||
name_type = name.name_type
|
||||
|
||||
return Name.create(name_value, name_type)
|
||||
return attributes.Name.create(name_value, name_type)
|
||||
else:
|
||||
return Name()
|
||||
|
||||
def _create_object_type(self, obj):
|
||||
return ObjectType()
|
||||
|
||||
def _create_cryptographic_algorithm(self, alg):
|
||||
return CryptographicAlgorithm(alg)
|
||||
return attributes.Name()
|
||||
|
||||
def _create_cryptographic_length(self, length):
|
||||
if length is not None and not isinstance(length, int):
|
||||
msg = utils.build_er_error(CryptographicLength,
|
||||
msg = utils.build_er_error(attributes.CryptographicLength,
|
||||
'constructor argument type', int,
|
||||
type(length))
|
||||
raise TypeError(msg)
|
||||
|
||||
return CryptographicLength(length)
|
||||
return attributes.CryptographicLength(length)
|
||||
|
||||
def _create_cryptographic_parameters(self, params):
|
||||
block_cipher_mode = None
|
||||
bcm = None
|
||||
if 'block_cipher_mode' in params:
|
||||
block_cipher_mode = CryptographicParameters.BlockCipherMode(
|
||||
bcm = attributes.CryptographicParameters.BlockCipherMode(
|
||||
params.get('block_cipher_mode'))
|
||||
|
||||
padding_method = None
|
||||
if 'padding_method' in params:
|
||||
padding_method = CryptographicParameters.PaddingMethod(
|
||||
padding_method = attributes.CryptographicParameters.PaddingMethod(
|
||||
params.get('padding_method'))
|
||||
|
||||
key_role_type = None
|
||||
if 'key_role_type' in params:
|
||||
key_role_type = CryptographicParameters.KeyRoleType(
|
||||
key_role_type = attributes.CryptographicParameters.KeyRoleType(
|
||||
params.get('key_role_type'))
|
||||
|
||||
hashing_algorithm = None
|
||||
if 'hashing_algorithm' in params:
|
||||
hashing_algorithm = HashingAlgorithm(
|
||||
hashing_algorithm = attributes.HashingAlgorithm(
|
||||
params.get("hashing_algorithm"))
|
||||
|
||||
return CryptographicParameters(
|
||||
block_cipher_mode=block_cipher_mode,
|
||||
return attributes.CryptographicParameters(
|
||||
block_cipher_mode=bcm,
|
||||
padding_method=padding_method,
|
||||
hashing_algorithm=hashing_algorithm,
|
||||
key_role_type=key_role_type)
|
||||
|
||||
def _create_cryptographic_domain_parameters(self, params):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_certificate_type(self, cert):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_certificate_length(self, length):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_x_509_certificate_identifier(self, ident):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_x_509_certificate_subject(self, subject):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_x_509_certificate_issuer(self, issuer):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_certificate_identifier(self, ident):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_certificate_subject(self, subject):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_certificate_issuer(self, issuer):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_digital_signature_algorithm(self, alg):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_digest(self):
|
||||
return Digest()
|
||||
|
||||
def _create_operation_policy_name(self, name):
|
||||
return OperationPolicyName(name)
|
||||
|
||||
def _create_cryptographic_usage_mask(self, flags):
|
||||
mask = None
|
||||
if flags is not None:
|
||||
|
@ -225,98 +162,49 @@ class AttributeValueFactory(object):
|
|||
for flag in flags:
|
||||
mask |= flag.value
|
||||
|
||||
return CryptographicUsageMask(mask)
|
||||
|
||||
def _create_lease_time(self, lease):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_usage_limits(self, limits):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_state(self, state):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_initial_date(self, date):
|
||||
return DateTime(value=date, tag=Tags.INITIAL_DATE)
|
||||
|
||||
def _create_activation_date(self, date):
|
||||
return DateTime(value=date, tag=Tags.ACTIVATION_DATE)
|
||||
|
||||
def _create_process_start_date(self, date):
|
||||
return DateTime(value=date, tag=Tags.PROCESS_START_DATE)
|
||||
|
||||
def _create_protect_stop_date(self, date):
|
||||
return DateTime(value=date, tag=Tags.PROTECT_STOP_DATE)
|
||||
|
||||
def _create_deactivation_date(self, date):
|
||||
return DateTime(value=date, tag=Tags.DEACTIVATION_DATE)
|
||||
|
||||
def _create_destroy_date(self, date):
|
||||
return DateTime(value=date, tag=Tags.DESTROY_DATE)
|
||||
|
||||
def _create_compromise_occurrence_date(self, date):
|
||||
return DateTime(value=date, tag=Tags.COMPROMISE_OCCURRENCE_DATE)
|
||||
|
||||
def _create_compromise_date(self, date):
|
||||
return DateTime(value=date, tag=Tags.COMPROMISE_DATE)
|
||||
|
||||
def _create_revocation_reason(self, reason):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_archive_date(self, date):
|
||||
return DateTime(value=date, tag=Tags.ARCHIVE_DATE)
|
||||
return attributes.CryptographicUsageMask(mask)
|
||||
|
||||
def _create_object_group(self, group):
|
||||
if group is not None and not isinstance(group, str):
|
||||
msg = utils.build_er_error(ObjectGroup,
|
||||
msg = utils.build_er_error(attributes.ObjectGroup,
|
||||
'constructor argument type', str,
|
||||
type(group))
|
||||
raise TypeError(msg)
|
||||
|
||||
return ObjectGroup(group)
|
||||
|
||||
def _create_fresh(self, fresh):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_link(self, link):
|
||||
raise NotImplementedError()
|
||||
return attributes.ObjectGroup(group)
|
||||
|
||||
def _create_application_specific_information(self, info):
|
||||
if info is None:
|
||||
return ApplicationSpecificInformation()
|
||||
return attributes.ApplicationSpecificInformation()
|
||||
else:
|
||||
application_namespace = info.get('application_namespace')
|
||||
application_data = info.get('application_data')
|
||||
|
||||
if not isinstance(application_namespace, str):
|
||||
msg = utils.build_er_error(ApplicationSpecificInformation,
|
||||
'constructor argument type',
|
||||
str, type(application_namespace))
|
||||
msg = utils.build_er_error(
|
||||
attributes.ApplicationSpecificInformation,
|
||||
'constructor argument type',
|
||||
str, type(application_namespace))
|
||||
raise TypeError(msg)
|
||||
|
||||
if not isinstance(application_data, str):
|
||||
msg = utils.build_er_error(ApplicationSpecificInformation,
|
||||
'constructor argument type',
|
||||
str, type(application_data))
|
||||
msg = utils.build_er_error(
|
||||
attributes.ApplicationSpecificInformation,
|
||||
'constructor argument type',
|
||||
str, type(application_data))
|
||||
raise TypeError(msg)
|
||||
|
||||
return ApplicationSpecificInformation.create(application_namespace,
|
||||
application_data)
|
||||
return attributes.ApplicationSpecificInformation.create(
|
||||
application_namespace, application_data)
|
||||
|
||||
def _create_contact_information(self, info):
|
||||
if info is None:
|
||||
return ContactInformation()
|
||||
return attributes.ContactInformation()
|
||||
else:
|
||||
if not isinstance(info, str):
|
||||
msg = utils.build_er_error(ContactInformation,
|
||||
msg = utils.build_er_error(attributes.ContactInformation,
|
||||
'constructor argument type', str,
|
||||
type(info))
|
||||
raise TypeError(msg)
|
||||
|
||||
return ContactInformation(info)
|
||||
|
||||
def _create_last_change_date(self, date):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _create_custom_attribute(self, data):
|
||||
return CustomAttribute(data)
|
||||
return attributes.ContactInformation(info)
|
||||
|
|
|
@ -13,178 +13,376 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
|
||||
from kmip.core.enums import AttributeType
|
||||
from kmip.core.enums import BlockCipherMode
|
||||
from kmip.core.enums import HashingAlgorithm
|
||||
from kmip.core.enums import PaddingMethod
|
||||
from kmip.core.enums import KeyRoleType
|
||||
from kmip.core.enums import Tags
|
||||
import testtools
|
||||
|
||||
from kmip.core import attributes
|
||||
from kmip.core.attributes import CryptographicParameters
|
||||
from kmip.core.attributes import OperationPolicyName
|
||||
from kmip.core import enums
|
||||
from kmip.core import primitives
|
||||
|
||||
from kmip.core.primitives import DateTime
|
||||
|
||||
from kmip.core.factories.attribute_values import AttributeValueFactory
|
||||
from kmip.core.factories import attribute_values
|
||||
|
||||
|
||||
class TestAttributeValueFactory(TestCase):
|
||||
class TestAttributeValueFactory(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAttributeValueFactory, self).setUp()
|
||||
self.factory = AttributeValueFactory()
|
||||
self.factory = attribute_values.AttributeValueFactory()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestAttributeValueFactory, self).tearDown()
|
||||
|
||||
# TODO (peter-hamilton) Consider even further modularity
|
||||
def _test_operation_policy_name(self, opn, value):
|
||||
if value is None:
|
||||
value = ''
|
||||
def test_create_unique_identifier(self):
|
||||
"""
|
||||
Test that a UniqueIdentifier attribute can be created.
|
||||
"""
|
||||
self.skip('')
|
||||
|
||||
msg = "expected {0}, received {1}".format(OperationPolicyName, opn)
|
||||
self.assertIsInstance(opn, OperationPolicyName, msg)
|
||||
def test_create_name(self):
|
||||
"""
|
||||
Test that a Name attribute can be created.
|
||||
"""
|
||||
self.skip('')
|
||||
|
||||
msg = "expected {0}, received {1}".format(value, opn.value)
|
||||
self.assertEqual(value, opn.value, msg)
|
||||
def test_create_object_type(self):
|
||||
"""
|
||||
Test that an ObjectType attribute can be created.
|
||||
"""
|
||||
self.skip('')
|
||||
|
||||
def _test_create_attribute_value_operation_policy_name(self, value):
|
||||
opn = self.factory.create_attribute_value(
|
||||
AttributeType.OPERATION_POLICY_NAME, value)
|
||||
self._test_operation_policy_name(opn, value)
|
||||
def test_create_cryptographic_algorithm(self):
|
||||
"""
|
||||
Test that a CryptographicAlgorithm attribute can be created.
|
||||
"""
|
||||
self.skip('')
|
||||
|
||||
def _test_create_operation_policy_name(self, value):
|
||||
opn = self.factory._create_operation_policy_name(value)
|
||||
self._test_operation_policy_name(opn, value)
|
||||
def test_create_cryptographic_length(self):
|
||||
"""
|
||||
Test that a CryptographicLength attribute can be created.
|
||||
"""
|
||||
self.skip('')
|
||||
|
||||
def test_create_attribute_value_operation_policy_name(self):
|
||||
self._test_create_attribute_value_operation_policy_name('test')
|
||||
def test_create_cryptographic_parameters(self):
|
||||
"""
|
||||
Test that a CryptographicParameters attribute can be created.
|
||||
"""
|
||||
value = {
|
||||
'block_cipher_mode': enums.BlockCipherMode.NIST_KEY_WRAP,
|
||||
'padding_method': enums.PaddingMethod.ANSI_X9_23,
|
||||
'key_role_type': enums.KeyRoleType.KEK,
|
||||
'hashing_algorithm': enums.HashingAlgorithm.SHA_512}
|
||||
params = self.factory.create_attribute_value(
|
||||
enums.AttributeType.CRYPTOGRAPHIC_PARAMETERS, value)
|
||||
|
||||
def test_create_attribute_value_operation_policy_name_on_none(self):
|
||||
self._test_create_attribute_value_operation_policy_name(None)
|
||||
# TODO (peter-hamilton): Update assertEquals after structure changes
|
||||
self.assertIsInstance(params, attributes.CryptographicParameters)
|
||||
self.assertEqual(
|
||||
attributes.CryptographicParameters.BlockCipherMode(
|
||||
enums.BlockCipherMode.NIST_KEY_WRAP),
|
||||
params.block_cipher_mode)
|
||||
self.assertEqual(
|
||||
attributes.CryptographicParameters.PaddingMethod(
|
||||
enums.PaddingMethod.ANSI_X9_23),
|
||||
params.padding_method)
|
||||
self.assertEqual(
|
||||
attributes.CryptographicParameters.KeyRoleType(
|
||||
enums.KeyRoleType.KEK),
|
||||
params.key_role_type)
|
||||
self.assertEqual(
|
||||
attributes.HashingAlgorithm(enums.HashingAlgorithm.SHA_512),
|
||||
params.hashing_algorithm)
|
||||
|
||||
def test_create_cryptographic_domain_parameters(self):
|
||||
"""
|
||||
Test that a CryptographicDomainParameters attribute can be created.
|
||||
"""
|
||||
kwargs = {'name': enums.AttributeType.CRYPTOGRAPHIC_DOMAIN_PARAMETERS,
|
||||
'value': None}
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.factory.create_attribute_value, **kwargs)
|
||||
|
||||
def test_create_certificate_type(self):
|
||||
"""
|
||||
Test that a CertificateType attribute can be created.
|
||||
"""
|
||||
kwargs = {'name': enums.AttributeType.CERTIFICATE_TYPE,
|
||||
'value': None}
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.factory.create_attribute_value, **kwargs)
|
||||
|
||||
def test_create_certificate_length(self):
|
||||
"""
|
||||
Test that a CertificateLength attribute can be created.
|
||||
"""
|
||||
length = self.factory.create_attribute_value(
|
||||
enums.AttributeType.CERTIFICATE_LENGTH, 0)
|
||||
self.assertIsInstance(length, primitives.Integer)
|
||||
self.assertEqual(0, length.value)
|
||||
self.assertEqual(enums.Tags.CERTIFICATE_LENGTH, length.tag)
|
||||
|
||||
def test_create_x509_certificate_identifier(self):
|
||||
"""
|
||||
Test that an X509CertificateIdentifier attribute can be created.
|
||||
"""
|
||||
kwargs = {'name': enums.AttributeType.X_509_CERTIFICATE_IDENTIFIER,
|
||||
'value': None}
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.factory.create_attribute_value, **kwargs)
|
||||
|
||||
def test_create_x509_certificate_subject(self):
|
||||
"""
|
||||
Test that an X509CertificateSubject attribute can be created.
|
||||
"""
|
||||
kwargs = {'name': enums.AttributeType.X_509_CERTIFICATE_SUBJECT,
|
||||
'value': None}
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.factory.create_attribute_value, **kwargs)
|
||||
|
||||
def test_create_x509_certificate_issuer(self):
|
||||
"""
|
||||
Test that an X509CertificateIssuer attribute can be created.
|
||||
"""
|
||||
kwargs = {'name': enums.AttributeType.X_509_CERTIFICATE_ISSUER,
|
||||
'value': None}
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.factory.create_attribute_value, **kwargs)
|
||||
|
||||
def test_create_certificate_identifier(self):
|
||||
"""
|
||||
Test that a CertificateIdentifier attribute can be created.
|
||||
"""
|
||||
kwargs = {'name': enums.AttributeType.CERTIFICATE_IDENTIFIER,
|
||||
'value': None}
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.factory.create_attribute_value, **kwargs)
|
||||
|
||||
def test_create_certificate_subject(self):
|
||||
"""
|
||||
Test that a CertificateSubject attribute can be created.
|
||||
"""
|
||||
kwargs = {'name': enums.AttributeType.CERTIFICATE_SUBJECT,
|
||||
'value': None}
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.factory.create_attribute_value, **kwargs)
|
||||
|
||||
def test_create_certificate_issuer(self):
|
||||
"""
|
||||
Test that a CertificateIssuer attribute can be created.
|
||||
"""
|
||||
kwargs = {'name': enums.AttributeType.CERTIFICATE_ISSUER,
|
||||
'value': None}
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.factory.create_attribute_value, **kwargs)
|
||||
|
||||
def test_create_digital_signature_algorithm(self):
|
||||
"""
|
||||
Test that a DigitalSignatureAlgorithm attribute can be created.
|
||||
"""
|
||||
kwargs = {'name': enums.AttributeType.DIGITAL_SIGNATURE_ALGORITHM,
|
||||
'value': None}
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.factory.create_attribute_value, **kwargs)
|
||||
|
||||
def test_create_digest(self):
|
||||
"""
|
||||
Test that a Digest attribute can be created.
|
||||
"""
|
||||
digest = self.factory.create_attribute_value(
|
||||
enums.AttributeType.DIGEST, None)
|
||||
self.assertIsInstance(digest, attributes.Digest)
|
||||
|
||||
def test_create_operation_policy_name(self):
|
||||
self._test_create_operation_policy_name('test')
|
||||
"""
|
||||
Test that an OperationPolicyName attribute can be created.
|
||||
"""
|
||||
attribute = self.factory.create_attribute_value(
|
||||
enums.AttributeType.OPERATION_POLICY_NAME, 'test')
|
||||
self.assertIsInstance(attribute, attributes.OperationPolicyName)
|
||||
self.assertEqual('test', attribute.value)
|
||||
|
||||
def test_create_operation_policy_name_on_none(self):
|
||||
self._test_create_operation_policy_name(None)
|
||||
def test_create_cryptographic_usage_mask(self):
|
||||
"""
|
||||
Test that a CryptographicUsageMask attribute can be created.
|
||||
"""
|
||||
self.skip('')
|
||||
|
||||
def _test_cryptograpic_parameters(self, obj, block_cipher_mode,
|
||||
padding_method, key_role_type,
|
||||
hashing_algorithm):
|
||||
msg = "expected {0}, received {1}"
|
||||
self.assertIsInstance(obj, CryptographicParameters, msg.format(
|
||||
CryptographicParameters, obj.__class__))
|
||||
def test_create_lease_time(self):
|
||||
"""
|
||||
Test that a LeaseTime attribute can be created.
|
||||
"""
|
||||
lease = self.factory.create_attribute_value(
|
||||
enums.AttributeType.LEASE_TIME, 0)
|
||||
self.assertIsInstance(lease, primitives.Interval)
|
||||
self.assertEqual(0, lease.value)
|
||||
self.assertEqual(enums.Tags.LEASE_TIME, lease.tag)
|
||||
|
||||
self.assertEqual(block_cipher_mode, obj.block_cipher_mode, msg.format(
|
||||
block_cipher_mode, obj.block_cipher_mode))
|
||||
def test_create_usage_limits(self):
|
||||
"""
|
||||
Test that a UsageLimits attribute can be created.
|
||||
"""
|
||||
kwargs = {'name': enums.AttributeType.USAGE_LIMITS,
|
||||
'value': None}
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.factory.create_attribute_value, **kwargs)
|
||||
|
||||
self.assertEqual(padding_method, obj.padding_method, msg.format(
|
||||
padding_method, obj.padding_method))
|
||||
|
||||
self.assertEqual(key_role_type, obj.key_role_type, msg.format(
|
||||
key_role_type, obj.hashing_algorithm))
|
||||
|
||||
self.assertEqual(hashing_algorithm, obj.hashing_algorithm, msg.format(
|
||||
hashing_algorithm, obj.hashing_algorithm))
|
||||
|
||||
def test_create_cryptograpic_parameters_none(self):
|
||||
cp = self.factory.create_attribute_value(
|
||||
AttributeType.CRYPTOGRAPHIC_PARAMETERS,
|
||||
{})
|
||||
self._test_cryptograpic_parameters(cp, None, None, None, None)
|
||||
|
||||
def test_create_cryptograpic_parameters_block_cipher_mode(self):
|
||||
cp = self.factory.create_attribute_value(
|
||||
AttributeType.CRYPTOGRAPHIC_PARAMETERS,
|
||||
{'block_cipher_mode': BlockCipherMode.NIST_KEY_WRAP})
|
||||
|
||||
self._test_cryptograpic_parameters(
|
||||
cp, CryptographicParameters.BlockCipherMode(
|
||||
BlockCipherMode.NIST_KEY_WRAP),
|
||||
None, None, None)
|
||||
|
||||
def test_create_cryptograpic_parameters_padding_method(self):
|
||||
cp = self.factory.create_attribute_value(
|
||||
AttributeType.CRYPTOGRAPHIC_PARAMETERS,
|
||||
{'padding_method': PaddingMethod.ANSI_X9_23})
|
||||
|
||||
# noqa - E128 continuation line under-indented for visual indent
|
||||
self._test_cryptograpic_parameters(cp, None,
|
||||
CryptographicParameters.PaddingMethod(PaddingMethod.ANSI_X9_23),
|
||||
None, None) # noqa
|
||||
|
||||
def test_create_cryptograpic_parameters_key_role_type(self):
|
||||
cp = self.factory.create_attribute_value(
|
||||
AttributeType.CRYPTOGRAPHIC_PARAMETERS,
|
||||
{'key_role_type': KeyRoleType.KEK})
|
||||
|
||||
# noqa - E128 continuation line under-indented for visual indent
|
||||
self._test_cryptograpic_parameters(cp, None, None,
|
||||
CryptographicParameters.KeyRoleType(KeyRoleType.KEK),
|
||||
None) # noqa
|
||||
|
||||
def test_create_cryptograpic_parameters_hashing_algorithm(self):
|
||||
cp = self.factory.create_attribute_value(
|
||||
AttributeType.CRYPTOGRAPHIC_PARAMETERS,
|
||||
{'hashing_algorithm': HashingAlgorithm.SHA_512})
|
||||
|
||||
# noqa - E128 continuation line under-indented for visual indent
|
||||
self._test_cryptograpic_parameters(cp, None, None, None,
|
||||
attributes.HashingAlgorithm(HashingAlgorithm.SHA_512)) # noqa
|
||||
|
||||
def _test_date_value(self, date, value, tag):
|
||||
msg = "expected {0}, received {1}"
|
||||
self.assertIsInstance(date, DateTime, msg.format(
|
||||
DateTime, date.__class__))
|
||||
|
||||
self.assertEqual(date.value, value, msg.format(value, date.value))
|
||||
self.assertEqual(date.tag, tag, msg.format(tag, date.tag))
|
||||
def test_create_state(self):
|
||||
"""
|
||||
Test that a State attribute can be created.
|
||||
"""
|
||||
kwargs = {'name': enums.AttributeType.STATE,
|
||||
'value': None}
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.factory.create_attribute_value, **kwargs)
|
||||
|
||||
def test_create_initial_date(self):
|
||||
"""
|
||||
Test that an InitialDate attribute can be created.
|
||||
"""
|
||||
date = self.factory.create_attribute_value(
|
||||
AttributeType.INITIAL_DATE, 0)
|
||||
self._test_date_value(date, 0, Tags.INITIAL_DATE)
|
||||
enums.AttributeType.INITIAL_DATE, 0)
|
||||
self.assertIsInstance(date, primitives.DateTime)
|
||||
self.assertEqual(0, date.value)
|
||||
self.assertEqual(enums.Tags.INITIAL_DATE, date.tag)
|
||||
|
||||
def test_create_activation_date(self):
|
||||
"""
|
||||
Test that an ActivationDate attribute can be created.
|
||||
"""
|
||||
date = self.factory.create_attribute_value(
|
||||
AttributeType.ACTIVATION_DATE, 0)
|
||||
self._test_date_value(date, 0, Tags.ACTIVATION_DATE)
|
||||
enums.AttributeType.ACTIVATION_DATE, 0)
|
||||
self.assertIsInstance(date, primitives.DateTime)
|
||||
self.assertEqual(0, date.value)
|
||||
self.assertEqual(enums.Tags.ACTIVATION_DATE, date.tag)
|
||||
|
||||
def test_create_process_start_date(self):
|
||||
"""
|
||||
Test that a ProcessStartDate attribute can be created.
|
||||
"""
|
||||
date = self.factory.create_attribute_value(
|
||||
AttributeType.PROCESS_START_DATE, 0)
|
||||
self._test_date_value(date, 0, Tags.PROCESS_START_DATE)
|
||||
enums.AttributeType.PROCESS_START_DATE, 0)
|
||||
self.assertIsInstance(date, primitives.DateTime)
|
||||
self.assertEqual(0, date.value)
|
||||
self.assertEqual(enums.Tags.PROCESS_START_DATE, date.tag)
|
||||
|
||||
def test_create_protect_stop_date(self):
|
||||
"""
|
||||
Test that a ProtectStopDate attribute can be created.
|
||||
"""
|
||||
date = self.factory.create_attribute_value(
|
||||
AttributeType.PROTECT_STOP_DATE, 0)
|
||||
self._test_date_value(date, 0, Tags.PROTECT_STOP_DATE)
|
||||
enums.AttributeType.PROTECT_STOP_DATE, 0)
|
||||
self.assertIsInstance(date, primitives.DateTime)
|
||||
self.assertEqual(0, date.value)
|
||||
self.assertEqual(enums.Tags.PROTECT_STOP_DATE, date.tag)
|
||||
|
||||
def test_create_deactivation_date(self):
|
||||
"""
|
||||
Test that a DeactivationDate attribute can be created.
|
||||
"""
|
||||
date = self.factory.create_attribute_value(
|
||||
AttributeType.DEACTIVATION_DATE, 0)
|
||||
self._test_date_value(date, 0, Tags.DEACTIVATION_DATE)
|
||||
enums.AttributeType.DEACTIVATION_DATE, 0)
|
||||
self.assertIsInstance(date, primitives.DateTime)
|
||||
self.assertEqual(0, date.value)
|
||||
self.assertEqual(enums.Tags.DEACTIVATION_DATE, date.tag)
|
||||
|
||||
def test_create_destroy_date(self):
|
||||
"""
|
||||
Test that a DestroyDate attribute can be created.
|
||||
"""
|
||||
date = self.factory.create_attribute_value(
|
||||
AttributeType.DESTROY_DATE, 0)
|
||||
self._test_date_value(date, 0, Tags.DESTROY_DATE)
|
||||
enums.AttributeType.DESTROY_DATE, 0)
|
||||
self.assertIsInstance(date, primitives.DateTime)
|
||||
self.assertEqual(0, date.value)
|
||||
self.assertEqual(enums.Tags.DESTROY_DATE, date.tag)
|
||||
|
||||
def test_create_compromise_occurance_date(self):
|
||||
"""
|
||||
Test that a CompromiseOccurrenceDate attribute can be created.
|
||||
"""
|
||||
date = self.factory.create_attribute_value(
|
||||
AttributeType.COMPROMISE_OCCURRENCE_DATE, 0)
|
||||
self._test_date_value(date, 0, Tags.COMPROMISE_OCCURRENCE_DATE)
|
||||
enums.AttributeType.COMPROMISE_OCCURRENCE_DATE, 0)
|
||||
self.assertIsInstance(date, primitives.DateTime)
|
||||
self.assertEqual(0, date.value)
|
||||
self.assertEqual(enums.Tags.COMPROMISE_OCCURRENCE_DATE, date.tag)
|
||||
|
||||
def test_create_compromise_date(self):
|
||||
"""
|
||||
Test that a CompromiseDate attribute can be created.
|
||||
"""
|
||||
date = self.factory.create_attribute_value(
|
||||
AttributeType.COMPROMISE_DATE, 0)
|
||||
self._test_date_value(date, 0, Tags.COMPROMISE_DATE)
|
||||
enums.AttributeType.COMPROMISE_DATE, 0)
|
||||
self.assertIsInstance(date, primitives.DateTime)
|
||||
self.assertEqual(0, date.value)
|
||||
self.assertEqual(enums.Tags.COMPROMISE_DATE, date.tag)
|
||||
|
||||
def test_create_revocation_reason(self):
|
||||
"""
|
||||
Test that a RevocationReason attribute can be created.
|
||||
"""
|
||||
kwargs = {'name': enums.AttributeType.REVOCATION_REASON,
|
||||
'value': None}
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.factory.create_attribute_value, **kwargs)
|
||||
|
||||
def test_create_archive_date(self):
|
||||
"""
|
||||
Test that an ArchiveDate attribute can be created.
|
||||
"""
|
||||
date = self.factory.create_attribute_value(
|
||||
AttributeType.ARCHIVE_DATE, 0)
|
||||
self._test_date_value(date, 0, Tags.ARCHIVE_DATE)
|
||||
enums.AttributeType.ARCHIVE_DATE, 0)
|
||||
self.assertIsInstance(date, primitives.DateTime)
|
||||
self.assertEqual(0, date.value)
|
||||
self.assertEqual(enums.Tags.ARCHIVE_DATE, date.tag)
|
||||
|
||||
def test_create_object_group(self):
|
||||
"""
|
||||
Test that an ObjectGroup attribute can be created.
|
||||
"""
|
||||
self.skip('')
|
||||
|
||||
def test_create_fresh(self):
|
||||
"""
|
||||
Test that a Fresh attribute can be created.
|
||||
"""
|
||||
fresh = self.factory.create_attribute_value(
|
||||
enums.AttributeType.FRESH, True)
|
||||
self.assertIsInstance(fresh, primitives.Boolean)
|
||||
self.assertEqual(True, fresh.value)
|
||||
self.assertEqual(enums.Tags.FRESH, fresh.tag)
|
||||
|
||||
def test_create_link(self):
|
||||
"""
|
||||
Test that a Link attribute can be created.
|
||||
"""
|
||||
kwargs = {'name': enums.AttributeType.LINK,
|
||||
'value': None}
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.factory.create_attribute_value, **kwargs)
|
||||
|
||||
def test_create_application_specific_information(self):
|
||||
"""
|
||||
Test that an ApplicationSpecificInformation attribute can be created.
|
||||
"""
|
||||
self.skip('')
|
||||
|
||||
def test_create_contact_information(self):
|
||||
"""
|
||||
Test that a ContactInformation attribute can be created.
|
||||
"""
|
||||
self.skip('')
|
||||
|
||||
def test_create_last_change_date(self):
|
||||
"""
|
||||
Test that an LastChangeDate attribute can be created.
|
||||
"""
|
||||
date = self.factory.create_attribute_value(
|
||||
enums.AttributeType.LAST_CHANGE_DATE, 0)
|
||||
self.assertIsInstance(date, primitives.DateTime)
|
||||
self.assertEqual(0, date.value)
|
||||
self.assertEqual(enums.Tags.LAST_CHANGE_DATE, date.tag)
|
||||
|
||||
def test_create_custom_attribute(self):
|
||||
"""
|
||||
Test that a CustomAttribute can be created.
|
||||
"""
|
||||
custom = self.factory.create_attribute_value(
|
||||
enums.AttributeType.CUSTOM_ATTRIBUTE, None)
|
||||
self.assertIsInstance(custom, attributes.CustomAttribute)
|
||||
|
|
Loading…
Reference in New Issue