Merge pull request #392 from OpenKMIP/feat/update-protocol-version

Update the ProtocolVersion implementation
This commit is contained in:
Peter Hamilton 2018-02-22 14:07:56 -05:00 committed by GitHub
commit 499328b077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 557 additions and 427 deletions

View File

@ -13,10 +13,13 @@
# 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 six
from kmip.core import enums from kmip.core import enums
from kmip.core import objects from kmip.core import objects
from kmip.core import utils from kmip.core import utils
from kmip.core import primitives
from kmip.core.primitives import Struct from kmip.core.primitives import Struct
from kmip.core.primitives import Integer from kmip.core.primitives import Integer
from kmip.core.primitives import Enumeration from kmip.core.primitives import Enumeration
@ -26,105 +29,170 @@ from kmip.core.primitives import ByteString
from kmip.core.primitives import DateTime from kmip.core.primitives import DateTime
# 6.1 class ProtocolVersion(primitives.Struct):
class ProtocolVersion(Struct): """
A struct representing a ProtocolVersion number.
class ProtocolVersionMajor(Integer): Attributes:
def __init__(self, value=None): major: The major protocol version number.
super(ProtocolVersion.ProtocolVersionMajor, self).\ minor: The minor protocol version number.
__init__(value, enums.Tags.PROTOCOL_VERSION_MAJOR) """
class ProtocolVersionMinor(Integer): def __init__(self, major=None, minor=None):
def __init__(self, value=None): """
super(ProtocolVersion.ProtocolVersionMinor, self).\ Construct a ProtocolVersion struct.
__init__(value, enums.Tags.PROTOCOL_VERSION_MINOR)
def __init__(self, Args:
protocol_version_major=None, major (int): The major protocol version number. Optional, defaults
protocol_version_minor=None): to None.
minor (int): The minor protocol version number. Optional, defaults
to None.
"""
super(ProtocolVersion, self).__init__(enums.Tags.PROTOCOL_VERSION) super(ProtocolVersion, self).__init__(enums.Tags.PROTOCOL_VERSION)
if protocol_version_major is None: self._major = None
self.protocol_version_major = \ self._minor = None
ProtocolVersion.ProtocolVersionMajor()
self.major = major
self.minor = minor
@property
def major(self):
if self._major:
return self._major.value
else: else:
self.protocol_version_major = protocol_version_major return None
if protocol_version_minor is None: @major.setter
self.protocol_version_minor = \ def major(self, value):
ProtocolVersion.ProtocolVersionMinor() if value is None:
self._major = None
elif isinstance(value, six.integer_types):
self._major = primitives.Integer(
value=value,
tag=enums.Tags.PROTOCOL_VERSION_MAJOR
)
else: else:
self.protocol_version_minor = protocol_version_minor raise TypeError(
"Major protocol version number must be an integer."
)
self.validate() @property
def minor(self):
if self._minor:
return self._minor.value
else:
return None
def read(self, istream): @minor.setter
super(ProtocolVersion, self).read(istream) def minor(self, value):
tstream = utils.BytearrayStream(istream.read(self.length)) if value is None:
self._minor = None
elif isinstance(value, six.integer_types):
self._minor = primitives.Integer(
value=value,
tag=enums.Tags.PROTOCOL_VERSION_MINOR
)
else:
raise TypeError(
"Minor protocol version number must be an integer."
)
# Read the major and minor portions of the version number def read(self, input_stream):
self.protocol_version_major.read(tstream) """
self.protocol_version_minor.read(tstream) Read the data encoding the ProtocolVersion struct and decode it into
its constituent parts.
self.is_oversized(tstream) Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
def write(self, ostream): Raises:
tstream = utils.BytearrayStream() ValueError: Raised if either the major or minor protocol versions
are missing from the encoding.
"""
super(ProtocolVersion, self).read(input_stream)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
# Write the major and minor portions of the protocol version if self.is_tag_next(enums.Tags.PROTOCOL_VERSION_MAJOR, local_stream):
self.protocol_version_major.write(tstream) self._major = primitives.Integer(
self.protocol_version_minor.write(tstream) tag=enums.Tags.PROTOCOL_VERSION_MAJOR
)
self._major.read(local_stream)
else:
raise ValueError(
"Invalid encoding missing the major protocol version number."
)
# Write the length and value of the protocol version if self.is_tag_next(enums.Tags.PROTOCOL_VERSION_MINOR, local_stream):
self.length = tstream.length() self._minor = primitives.Integer(
super(ProtocolVersion, self).write(ostream) tag=enums.Tags.PROTOCOL_VERSION_MINOR
ostream.write(tstream.buffer) )
self._minor.read(local_stream)
else:
raise ValueError(
"Invalid encoding missing the minor protocol version number."
)
def validate(self): self.is_oversized(local_stream)
self.__validate()
def __validate(self): def write(self, output_stream):
if not isinstance(self.protocol_version_major, """
ProtocolVersion.ProtocolVersionMajor): Write the data encoding the ProtocolVersion struct to a stream.
msg = "invalid protocol version major"
msg += "; expected {0}, received {1}".format(
ProtocolVersion.ProtocolVersionMajor,
self.protocol_version_major)
raise TypeError(msg)
if not isinstance(self.protocol_version_minor, Args:
ProtocolVersion.ProtocolVersionMinor): output_stream (stream): A data stream in which to encode object
msg = "invalid protocol version minor" data, supporting a write method; usually a BytearrayStream
msg += "; expected {0}, received {1}".format( object.
ProtocolVersion.ProtocolVersionMinor,
self.protocol_version_minor) Raises:
raise TypeError(msg) ValueError: Raised if the data attribute is not defined.
"""
local_stream = utils.BytearrayStream()
if self._major:
self._major.write(local_stream)
else:
raise ValueError(
"Invalid struct missing the major protocol version number."
)
if self._minor:
self._minor.write(local_stream)
else:
raise ValueError(
"Invalid struct missing the minor protocol version number."
)
self.length = local_stream.length()
super(ProtocolVersion, self).write(output_stream)
output_stream.write(local_stream.buffer)
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, ProtocolVersion): if isinstance(other, ProtocolVersion):
if ((self.protocol_version_major == if self.major != other.major:
other.protocol_version_major) and
(self.protocol_version_minor ==
other.protocol_version_minor)):
return True
else:
return False return False
elif self.minor != other.minor:
return False
else:
return True
else: else:
return NotImplemented return NotImplemented
def __ne__(self, other): def __ne__(self, other):
if isinstance(other, ProtocolVersion): if isinstance(other, ProtocolVersion):
return not self.__eq__(other) return not (self == other)
else: else:
return NotImplemented return NotImplemented
def __lt__(self, other): def __lt__(self, other):
if isinstance(other, ProtocolVersion): if isinstance(other, ProtocolVersion):
if self.protocol_version_major < other.protocol_version_major: if self.major < other.major:
return True return True
elif self.protocol_version_major > other.protocol_version_major: elif self.major > other.major:
return False return False
elif self.protocol_version_minor < other.protocol_version_minor: elif self.minor < other.minor:
return True return True
else: else:
return False return False
@ -133,24 +201,16 @@ class ProtocolVersion(Struct):
def __gt__(self, other): def __gt__(self, other):
if isinstance(other, ProtocolVersion): if isinstance(other, ProtocolVersion):
if self.protocol_version_major > other.protocol_version_major: if (self == other) or (self < other):
return True
elif self.protocol_version_major < other.protocol_version_major:
return False return False
elif self.protocol_version_minor > other.protocol_version_minor:
return True
else: else:
return False return True
else: else:
return NotImplemented return NotImplemented
def __le__(self, other): def __le__(self, other):
if isinstance(other, ProtocolVersion): if isinstance(other, ProtocolVersion):
if self.protocol_version_major < other.protocol_version_major: if (self == other) or (self < other):
return True
elif self.protocol_version_major > other.protocol_version_major:
return False
elif self.protocol_version_minor <= other.protocol_version_minor:
return True return True
else: else:
return False return False
@ -159,11 +219,7 @@ class ProtocolVersion(Struct):
def __ge__(self, other): def __ge__(self, other):
if isinstance(other, ProtocolVersion): if isinstance(other, ProtocolVersion):
if self.protocol_version_major > other.protocol_version_major: if (self == other) or (self > other):
return True
elif self.protocol_version_major < other.protocol_version_major:
return False
elif self.protocol_version_minor >= other.protocol_version_minor:
return True return True
else: else:
return False return False
@ -171,15 +227,14 @@ class ProtocolVersion(Struct):
return NotImplemented return NotImplemented
def __repr__(self): def __repr__(self):
major = self.protocol_version_major.value args = ", ".join([
minor = self.protocol_version_minor.value "major={}".format(self.major),
return "{0}.{1}".format(major, minor) "minor={}".format(self.minor)
])
return "ProtocolVersion({})".format(args)
@classmethod def __str__(self):
def create(cls, major, minor): return "{}.{}".format(self.major, self.minor)
major = cls.ProtocolVersionMajor(major)
minor = cls.ProtocolVersionMinor(minor)
return ProtocolVersion(major, minor)
# 6.2 # 6.2

View File

@ -157,9 +157,6 @@ class ResponseHeader(Struct):
ostream.write(tstream.buffer) ostream.write(tstream.buffer)
def validate(self): def validate(self):
if self.protocol_version is not None:
# TODO (peter-hamilton) conduct type check
self.protocol_version.validate()
if self.time_stamp is not None: if self.time_stamp is not None:
# TODO (peter-hamilton) conduct type check # TODO (peter-hamilton) conduct type check
self.time_stamp.validate() self.time_stamp.validate()

View File

@ -42,8 +42,7 @@ if __name__ == '__main__':
if opts.protocol_versions is not None: if opts.protocol_versions is not None:
for version in re.split(',| ', opts.protocol_versions): for version in re.split(',| ', opts.protocol_versions):
mm = re.split('\.', version) mm = re.split('\.', version)
protocol_versions.append(ProtocolVersion.create(int(mm[0]), protocol_versions.append(ProtocolVersion(int(mm[0]), int(mm[1])))
int(mm[1])))
# Build the client and connect to the server # Build the client and connect to the server
client = KMIPProxy(config=config) client = KMIPProxy(config=config)

View File

@ -1341,7 +1341,7 @@ class KMIPProxy(KMIP):
return credential return credential
def _build_request_message(self, credential, batch_items): def _build_request_message(self, credential, batch_items):
protocol_version = ProtocolVersion.create(1, 2) protocol_version = ProtocolVersion(1, 2)
if credential is None: if credential is None:
credential = self._build_credential() credential = self._build_credential()

View File

@ -105,9 +105,9 @@ class KmipEngine(object):
self._id_placeholder = None self._id_placeholder = None
self._protocol_versions = [ self._protocol_versions = [
contents.ProtocolVersion.create(1, 2), contents.ProtocolVersion(1, 2),
contents.ProtocolVersion.create(1, 1), contents.ProtocolVersion(1, 1),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
] ]
self._protocol_version = self._protocol_versions[0] self._protocol_version = self._protocol_versions[0]
@ -2001,11 +2001,11 @@ class KmipEngine(object):
contents.Operation(enums.Operation.QUERY) contents.Operation(enums.Operation.QUERY)
]) ])
if self._protocol_version >= contents.ProtocolVersion.create(1, 1): if self._protocol_version >= contents.ProtocolVersion(1, 1):
operations.extend([ operations.extend([
contents.Operation(enums.Operation.DISCOVER_VERSIONS) contents.Operation(enums.Operation.DISCOVER_VERSIONS)
]) ])
if self._protocol_version >= contents.ProtocolVersion.create(1, 2): if self._protocol_version >= contents.ProtocolVersion(1, 2):
operations.extend([ operations.extend([
contents.Operation(enums.Operation.ENCRYPT), contents.Operation(enums.Operation.ENCRYPT),
contents.Operation(enums.Operation.DECRYPT), contents.Operation(enums.Operation.DECRYPT),

View File

@ -157,7 +157,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Name': AttributeRuleSet( 'Name': AttributeRuleSet(
False, False,
@ -181,7 +181,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Object Type': AttributeRuleSet( 'Object Type': AttributeRuleSet(
True, True,
@ -210,7 +210,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Cryptographic Algorithm': AttributeRuleSet( 'Cryptographic Algorithm': AttributeRuleSet(
True, True,
@ -237,7 +237,7 @@ class AttributePolicy(object):
enums.ObjectType.SPLIT_KEY, enums.ObjectType.SPLIT_KEY,
enums.ObjectType.TEMPLATE enums.ObjectType.TEMPLATE
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Cryptographic Length': AttributeRuleSet( 'Cryptographic Length': AttributeRuleSet(
True, True,
@ -264,7 +264,7 @@ class AttributePolicy(object):
enums.ObjectType.SPLIT_KEY, enums.ObjectType.SPLIT_KEY,
enums.ObjectType.TEMPLATE enums.ObjectType.TEMPLATE
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Cryptographic Parameters': AttributeRuleSet( 'Cryptographic Parameters': AttributeRuleSet(
False, False,
@ -286,7 +286,7 @@ class AttributePolicy(object):
enums.ObjectType.SPLIT_KEY, enums.ObjectType.SPLIT_KEY,
enums.ObjectType.TEMPLATE enums.ObjectType.TEMPLATE
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Cryptographic Domain Parameters': AttributeRuleSet( 'Cryptographic Domain Parameters': AttributeRuleSet(
False, False,
@ -304,7 +304,7 @@ class AttributePolicy(object):
enums.ObjectType.PRIVATE_KEY, enums.ObjectType.PRIVATE_KEY,
enums.ObjectType.TEMPLATE enums.ObjectType.TEMPLATE
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Certificate Type': AttributeRuleSet( 'Certificate Type': AttributeRuleSet(
True, True,
@ -321,7 +321,7 @@ class AttributePolicy(object):
( (
enums.ObjectType.CERTIFICATE, enums.ObjectType.CERTIFICATE,
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Certificate Length': AttributeRuleSet( 'Certificate Length': AttributeRuleSet(
True, True,
@ -338,7 +338,7 @@ class AttributePolicy(object):
( (
enums.ObjectType.CERTIFICATE, enums.ObjectType.CERTIFICATE,
), ),
contents.ProtocolVersion.create(1, 1) contents.ProtocolVersion(1, 1)
), ),
'X.509 Certificate Identifier': AttributeRuleSet( 'X.509 Certificate Identifier': AttributeRuleSet(
True, True,
@ -356,7 +356,7 @@ class AttributePolicy(object):
# TODO (peterhamilton) Enforce only on X.509 certificates # TODO (peterhamilton) Enforce only on X.509 certificates
enums.ObjectType.CERTIFICATE, enums.ObjectType.CERTIFICATE,
), ),
contents.ProtocolVersion.create(1, 1) contents.ProtocolVersion(1, 1)
), ),
'X.509 Certificate Subject': AttributeRuleSet( 'X.509 Certificate Subject': AttributeRuleSet(
True, True,
@ -374,7 +374,7 @@ class AttributePolicy(object):
# TODO (peterhamilton) Enforce only on X.509 certificates # TODO (peterhamilton) Enforce only on X.509 certificates
enums.ObjectType.CERTIFICATE, enums.ObjectType.CERTIFICATE,
), ),
contents.ProtocolVersion.create(1, 1) contents.ProtocolVersion(1, 1)
), ),
'X.509 Certificate Issuer': AttributeRuleSet( 'X.509 Certificate Issuer': AttributeRuleSet(
True, True,
@ -392,7 +392,7 @@ class AttributePolicy(object):
# TODO (peterhamilton) Enforce only on X.509 certificates # TODO (peterhamilton) Enforce only on X.509 certificates
enums.ObjectType.CERTIFICATE, enums.ObjectType.CERTIFICATE,
), ),
contents.ProtocolVersion.create(1, 1) contents.ProtocolVersion(1, 1)
), ),
'Certificate Identifier': AttributeRuleSet( 'Certificate Identifier': AttributeRuleSet(
True, True,
@ -409,8 +409,8 @@ class AttributePolicy(object):
( (
enums.ObjectType.CERTIFICATE, enums.ObjectType.CERTIFICATE,
), ),
contents.ProtocolVersion.create(1, 0), contents.ProtocolVersion(1, 0),
contents.ProtocolVersion.create(1, 1) contents.ProtocolVersion(1, 1)
), ),
'Certificate Subject': AttributeRuleSet( 'Certificate Subject': AttributeRuleSet(
True, True,
@ -427,8 +427,8 @@ class AttributePolicy(object):
( (
enums.ObjectType.CERTIFICATE, enums.ObjectType.CERTIFICATE,
), ),
contents.ProtocolVersion.create(1, 0), contents.ProtocolVersion(1, 0),
contents.ProtocolVersion.create(1, 1) contents.ProtocolVersion(1, 1)
), ),
'Certificate Issuer': AttributeRuleSet( 'Certificate Issuer': AttributeRuleSet(
True, True,
@ -445,8 +445,8 @@ class AttributePolicy(object):
( (
enums.ObjectType.CERTIFICATE, enums.ObjectType.CERTIFICATE,
), ),
contents.ProtocolVersion.create(1, 0), contents.ProtocolVersion(1, 0),
contents.ProtocolVersion.create(1, 1) contents.ProtocolVersion(1, 1)
), ),
'Digital Signature Algorithm': AttributeRuleSet( 'Digital Signature Algorithm': AttributeRuleSet(
True, True,
@ -464,7 +464,7 @@ class AttributePolicy(object):
( (
enums.ObjectType.CERTIFICATE, enums.ObjectType.CERTIFICATE,
), ),
contents.ProtocolVersion.create(1, 1) contents.ProtocolVersion(1, 1)
), ),
'Digest': AttributeRuleSet( 'Digest': AttributeRuleSet(
True, # If the server has access to the data True, # If the server has access to the data
@ -492,7 +492,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Operation Policy Name': AttributeRuleSet( 'Operation Policy Name': AttributeRuleSet(
False, False,
@ -521,7 +521,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Cryptographic Usage Mask': AttributeRuleSet( 'Cryptographic Usage Mask': AttributeRuleSet(
True, True,
@ -549,7 +549,7 @@ class AttributePolicy(object):
enums.ObjectType.TEMPLATE, enums.ObjectType.TEMPLATE,
enums.ObjectType.SECRET_DATA enums.ObjectType.SECRET_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Lease Time': AttributeRuleSet( 'Lease Time': AttributeRuleSet(
False, False,
@ -576,7 +576,7 @@ class AttributePolicy(object):
enums.ObjectType.SPLIT_KEY, enums.ObjectType.SPLIT_KEY,
enums.ObjectType.SECRET_DATA enums.ObjectType.SECRET_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Usage Limits': AttributeRuleSet( 'Usage Limits': AttributeRuleSet(
False, False,
@ -601,7 +601,7 @@ class AttributePolicy(object):
enums.ObjectType.SPLIT_KEY, enums.ObjectType.SPLIT_KEY,
enums.ObjectType.TEMPLATE enums.ObjectType.TEMPLATE
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'State': AttributeRuleSet( 'State': AttributeRuleSet(
True, True,
@ -631,7 +631,7 @@ class AttributePolicy(object):
enums.ObjectType.SPLIT_KEY, enums.ObjectType.SPLIT_KEY,
enums.ObjectType.SECRET_DATA enums.ObjectType.SECRET_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Initial Date': AttributeRuleSet( 'Initial Date': AttributeRuleSet(
True, True,
@ -660,7 +660,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Activation Date': AttributeRuleSet( 'Activation Date': AttributeRuleSet(
False, False,
@ -689,7 +689,7 @@ class AttributePolicy(object):
enums.ObjectType.TEMPLATE, enums.ObjectType.TEMPLATE,
enums.ObjectType.SECRET_DATA enums.ObjectType.SECRET_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Process Start Date': AttributeRuleSet( 'Process Start Date': AttributeRuleSet(
False, False,
@ -710,7 +710,7 @@ class AttributePolicy(object):
enums.ObjectType.SPLIT_KEY, enums.ObjectType.SPLIT_KEY,
enums.ObjectType.TEMPLATE enums.ObjectType.TEMPLATE
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Protect Stop Date': AttributeRuleSet( 'Protect Stop Date': AttributeRuleSet(
False, False,
@ -731,7 +731,7 @@ class AttributePolicy(object):
enums.ObjectType.SPLIT_KEY, enums.ObjectType.SPLIT_KEY,
enums.ObjectType.TEMPLATE enums.ObjectType.TEMPLATE
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Deactivation Date': AttributeRuleSet( 'Deactivation Date': AttributeRuleSet(
False, False,
@ -760,7 +760,7 @@ class AttributePolicy(object):
enums.ObjectType.TEMPLATE, enums.ObjectType.TEMPLATE,
enums.ObjectType.SECRET_DATA enums.ObjectType.SECRET_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Destroy Date': AttributeRuleSet( 'Destroy Date': AttributeRuleSet(
False, False,
@ -781,7 +781,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Compromise Occurrence Date': AttributeRuleSet( 'Compromise Occurrence Date': AttributeRuleSet(
False, False,
@ -802,7 +802,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Compromise Date': AttributeRuleSet( 'Compromise Date': AttributeRuleSet(
False, False,
@ -823,7 +823,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Revocation Reason': AttributeRuleSet( 'Revocation Reason': AttributeRuleSet(
False, False,
@ -844,7 +844,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Archive Date': AttributeRuleSet( 'Archive Date': AttributeRuleSet(
False, False,
@ -866,7 +866,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Object Group': AttributeRuleSet( 'Object Group': AttributeRuleSet(
False, False,
@ -895,7 +895,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Fresh': AttributeRuleSet( 'Fresh': AttributeRuleSet(
False, False,
@ -924,7 +924,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 1) contents.ProtocolVersion(1, 1)
), ),
'Link': AttributeRuleSet( 'Link': AttributeRuleSet(
False, False,
@ -951,7 +951,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Application Specific Information': AttributeRuleSet( 'Application Specific Information': AttributeRuleSet(
False, False,
@ -975,7 +975,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Contact Information': AttributeRuleSet( 'Contact Information': AttributeRuleSet(
False, False,
@ -1004,7 +1004,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Last Change Date': AttributeRuleSet( 'Last Change Date': AttributeRuleSet(
True, True,
@ -1042,7 +1042,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
'Custom Attribute': AttributeRuleSet( 'Custom Attribute': AttributeRuleSet(
False, False,
@ -1074,7 +1074,7 @@ class AttributePolicy(object):
enums.ObjectType.SECRET_DATA, enums.ObjectType.SECRET_DATA,
enums.ObjectType.OPAQUE_DATA enums.ObjectType.OPAQUE_DATA
), ),
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
), ),
} }

View File

@ -176,7 +176,7 @@ class KmipSession(threading.Thread):
self._logger.warning("Failure parsing request message.") self._logger.warning("Failure parsing request message.")
self._logger.exception(e) self._logger.exception(e)
response = self._engine.build_error_response( response = self._engine.build_error_response(
contents.ProtocolVersion.create(1, 0), contents.ProtocolVersion(1, 0),
enums.ResultReason.INVALID_MESSAGE, enums.ResultReason.INVALID_MESSAGE,
"Error parsing request message. See server logs for more " "Error parsing request message. See server logs for more "
"information." "information."

View File

@ -13,171 +13,243 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from testtools import TestCase import testtools
from kmip.core.messages.contents import ProtocolVersion from kmip.core.messages import contents
from kmip.core.utils import BytearrayStream from kmip.core import utils
class TestProtocolVersion(TestCase): class TestProtocolVersion(testtools.TestCase):
def setUp(self): def setUp(self):
super(TestProtocolVersion, self).setUp() super(TestProtocolVersion, self).setUp()
self.major_default = ProtocolVersion.ProtocolVersionMajor() # Encoding obtained from the KMIP 1.1 testing document, Section 3.1.1.
self.minor_default = ProtocolVersion.ProtocolVersionMinor() #
self.major = ProtocolVersion.ProtocolVersionMajor(1) # This encoding matches the following set of values:
self.minor = ProtocolVersion.ProtocolVersionMinor(1) # ProtocolVersion
# ProtocolVersionMajor - 1
# ProtocolVersionMinor - 1
self.encoding_default = BytearrayStream(( self.full_encoding = utils.BytearrayStream(
b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04' b'\x42\x00\x69\x01\x00\x00\x00\x20'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04' b'\x42\x00\x6A\x02\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00')) b'\x42\x00\x6B\x02\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00'
self.encoding = BytearrayStream(( )
b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04' self.encoding_no_major_number = utils.BytearrayStream(
b'\x00\x00\x00\x01\x00\x00\x00\x00')) b'\x42\x00\x69\x01\x00\x00\x00\x10'
b'\x42\x00\x6B\x02\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00'
)
self.encoding_no_minor_number = utils.BytearrayStream(
b'\x42\x00\x69\x01\x00\x00\x00\x10'
b'\x42\x00\x6A\x02\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00'
)
def tearDown(self): def tearDown(self):
super(TestProtocolVersion, self).tearDown() super(TestProtocolVersion, self).tearDown()
def _test_init(self, protocol_version_major, protocol_version_minor): def test_init(self):
protocol_version = ProtocolVersion( """
protocol_version_major, protocol_version_minor) Test that a ProtocolVersion struct can be constructed with no
arguments.
"""
struct = contents.ProtocolVersion()
if protocol_version_major is None: self.assertEqual(None, struct.major)
self.assertEqual(ProtocolVersion.ProtocolVersionMajor(), self.assertEqual(None, struct.minor)
protocol_version.protocol_version_major)
else:
self.assertEqual(protocol_version_major,
protocol_version.protocol_version_major)
if protocol_version_minor is None:
self.assertEqual(ProtocolVersion.ProtocolVersionMinor(),
protocol_version.protocol_version_minor)
else:
self.assertEqual(protocol_version_minor,
protocol_version.protocol_version_minor)
def test_init_with_none(self):
self._test_init(None, None)
def test_init_with_args(self): def test_init_with_args(self):
major = ProtocolVersion.ProtocolVersionMajor(1) """
minor = ProtocolVersion.ProtocolVersionMinor(0) Test that a ProtocolVersion struct can be constructed with valid
values.
"""
struct = contents.ProtocolVersion(1, 1)
self._test_init(major, minor) self.assertEqual(1, struct.major)
self.assertEqual(1, struct.minor)
def test_validate_on_invalid_protocol_version_major(self):
major = "invalid"
minor = ProtocolVersion.ProtocolVersionMinor(0)
args = [major, minor]
def test_invalid_protocol_version_major(self):
"""
Test that a TypeError is raised when an invalid value is used to set
the major protocol version number of a ProtocolVersion struct.
"""
struct = contents.ProtocolVersion()
args = (struct, 'major', 'invalid')
self.assertRaisesRegexp( self.assertRaisesRegexp(
TypeError, "invalid protocol version major", self._test_init, TypeError,
*args) "Major protocol version number must be an integer.",
setattr,
def test_validate_on_invalid_protocol_version_minor(self): *args
major = ProtocolVersion.ProtocolVersionMajor(1) )
minor = "invalid"
args = [major, minor]
def test_invalid_protocol_version_minor(self):
"""
Test that a TypeError is raised when an invalid value is used to set
the minor protocol version number of a ProtocolVersion struct.
"""
struct = contents.ProtocolVersion()
args = (struct, 'minor', 'invalid')
self.assertRaisesRegexp( self.assertRaisesRegexp(
TypeError, "invalid protocol version minor", self._test_init, TypeError,
*args) "Minor protocol version number must be an integer.",
setattr,
*args
)
def _test_read(self, stream, major, minor): def test_read(self):
protocol_version = ProtocolVersion() """
protocol_version.read(stream) Test that a ProtocolVersion struct can be read from a data stream.
"""
struct = contents.ProtocolVersion()
msg = "protocol version major decoding mismatch" self.assertEqual(None, struct.major)
msg += "; expected {0}, received {1}".format( self.assertEqual(None, struct.minor)
major, protocol_version.protocol_version_major)
self.assertEqual(major, protocol_version.protocol_version_major, msg)
msg = "protocol version minor decoding mismatch" struct.read(self.full_encoding)
msg += "; expected {0}, received {1}".format(
minor, protocol_version.protocol_version_minor)
self.assertEqual(minor, protocol_version.protocol_version_minor, msg)
def test_read_with_none(self): self.assertEqual(1, struct.major)
self._test_read(self.encoding_default, self.major_default, self.assertEqual(1, struct.minor)
self.minor_default)
def test_read_with_args(self): def test_read_missing_major_number(self):
self._test_read(self.encoding, self.major, self.minor) """
Test that a ValueError gets raised when a required ProtocolVersion
struct attribute is missing from the struct encoding.
"""
struct = contents.ProtocolVersion()
args = (self.encoding_no_major_number, )
self.assertRaisesRegexp(
ValueError,
"Invalid encoding missing the major protocol version number.",
struct.read,
*args
)
def _test_write(self, stream_expected, major, minor): def test_read_missing_minor_number(self):
stream_observed = BytearrayStream() """
protocol_version = ProtocolVersion(major, minor) Test that a ValueError gets raised when a required ProtocolVersion
protocol_version.write(stream_observed) struct attribute is missing from the struct encoding.
"""
struct = contents.ProtocolVersion()
args = (self.encoding_no_minor_number, )
self.assertRaisesRegexp(
ValueError,
"Invalid encoding missing the minor protocol version number.",
struct.read,
*args
)
length_expected = len(stream_expected) def test_write(self):
length_observed = len(stream_observed) """
Test that a ProtocolVersion struct can be written to a data stream.
"""
struct = contents.ProtocolVersion(1, 1)
stream = utils.BytearrayStream()
struct.write(stream)
msg = "encoding lengths not equal" self.assertEqual(len(self.full_encoding), len(stream))
msg += "; expected {0}, received {1}".format( self.assertEqual(str(self.full_encoding), str(stream))
length_expected, length_observed)
self.assertEqual(length_expected, length_observed, msg)
msg = "encoding mismatch" def test_write_missing_major_number(self):
msg += ";\nexpected:\n{0}\nreceived:\n{1}".format( """
stream_expected, stream_observed) Test that a ValueError gets raised when a required ProtocolVersion
struct attribute is missing when encoding the struct.
"""
struct = contents.ProtocolVersion(None, 1)
stream = utils.BytearrayStream()
args = (stream, )
self.assertRaisesRegexp(
ValueError,
"Invalid struct missing the major protocol version number.",
struct.write,
*args
)
self.assertEqual(stream_expected, stream_observed, msg) def test_write_missing_minor_number(self):
"""
def test_write_with_none(self): Test that a ValueError gets raised when a required ProtocolVersion
self._test_write(self.encoding_default, self.major_default, struct attribute is missing when encoding the struct.
self.minor_default) """
struct = contents.ProtocolVersion(1, None)
def test_write_with_args(self): stream = utils.BytearrayStream()
self._test_write(self.encoding, self.major, self.minor) args = (stream, )
self.assertRaisesRegexp(
ValueError,
"Invalid struct missing the minor protocol version number.",
struct.write,
*args
)
def test_equal_on_equal(self): def test_equal_on_equal(self):
a = ProtocolVersion.create(1, 0) """
b = ProtocolVersion.create(1, 0) Test that the equality operator returns True when comparing two
ProtocolVersion structs with the same data.
"""
a = contents.ProtocolVersion(1, 0)
b = contents.ProtocolVersion(1, 0)
self.assertTrue(a == b) self.assertTrue(a == b)
def test_equal_on_not_equal(self): def test_equal_on_not_equal(self):
a = ProtocolVersion.create(1, 0) """
b = ProtocolVersion.create(0, 1) Test that the equality operator returns False when comparing two
ProtocolVersion structs with different data.
"""
a = contents.ProtocolVersion(1, 0)
b = contents.ProtocolVersion(0, 1)
self.assertFalse(a == b) self.assertFalse(a == b)
def test_equal_on_type_mismatch(self): def test_equal_on_type_mismatch(self):
a = ProtocolVersion.create(1, 0) """
Test that the equality operator returns False when comparing two
ProtocolVersion structs with different types.
"""
a = contents.ProtocolVersion(1, 0)
b = "invalid" b = "invalid"
self.assertFalse(a == b) self.assertFalse(a == b)
def test_not_equal_on_equal(self): def test_not_equal_on_equal(self):
a = ProtocolVersion.create(1, 0) """
b = ProtocolVersion.create(1, 0) Test that the inequality operator returns False when comparing two
ProtocolVersion structs with the same data.
"""
a = contents.ProtocolVersion(1, 0)
b = contents.ProtocolVersion(1, 0)
self.assertFalse(a != b) self.assertFalse(a != b)
def test_not_equal_on_not_equal(self): def test_not_equal_on_not_equal(self):
a = ProtocolVersion.create(1, 0) """
b = ProtocolVersion.create(0, 1) Test that the inequality operator returns True when comparing two
ProtocolVersion structs with different data.
"""
a = contents.ProtocolVersion(1, 0)
b = contents.ProtocolVersion(0, 1)
self.assertTrue(a != b) self.assertTrue(a != b)
def test_not_equal_on_type_mismatch(self): def test_not_equal_on_type_mismatch(self):
a = ProtocolVersion.create(1, 0) """
Test that the inequality operator returns True when comparing two
ProtocolVersion structs with different types.
"""
a = contents.ProtocolVersion(1, 0)
b = "invalid" b = "invalid"
self.assertTrue(a != b) self.assertTrue(a != b)
def test_less_than(self): def test_less_than(self):
""" """
Test that the less than operator returns True/False when comparing Test that the less than operator correctly returns True/False when
two different ProtocolVersions. comparing two different ProtocolVersions.
""" """
a = ProtocolVersion.create(1, 0) a = contents.ProtocolVersion(1, 0)
b = ProtocolVersion.create(1, 1) b = contents.ProtocolVersion(1, 1)
c = ProtocolVersion.create(2, 0) c = contents.ProtocolVersion(2, 0)
d = ProtocolVersion.create(0, 2) d = contents.ProtocolVersion(0, 2)
self.assertTrue(a < b) self.assertTrue(a < b)
self.assertFalse(b < a) self.assertFalse(b < a)
@ -187,15 +259,19 @@ class TestProtocolVersion(TestCase):
self.assertFalse(c < d) self.assertFalse(c < d)
self.assertTrue(d < c) self.assertTrue(d < c)
# A direct call to __lt__ is required here due to differences in how
# Python 2 and Python 3 treat comparison operators.
self.assertEqual(NotImplemented, a.__lt__('invalid'))
def test_greater_than(self): def test_greater_than(self):
""" """
Test that the greater than operator returns True/False when Test that the greater than operator correctly returns True/False when
comparing two different ProtocolVersions. comparing two different ProtocolVersions.
""" """
a = ProtocolVersion.create(1, 0) a = contents.ProtocolVersion(1, 0)
b = ProtocolVersion.create(1, 1) b = contents.ProtocolVersion(1, 1)
c = ProtocolVersion.create(2, 0) c = contents.ProtocolVersion(2, 0)
d = ProtocolVersion.create(0, 2) d = contents.ProtocolVersion(0, 2)
self.assertFalse(a > b) self.assertFalse(a > b)
self.assertTrue(b > a) self.assertTrue(b > a)
@ -205,15 +281,19 @@ class TestProtocolVersion(TestCase):
self.assertTrue(c > d) self.assertTrue(c > d)
self.assertFalse(d > c) self.assertFalse(d > c)
# A direct call to __gt__ is required here due to differences in how
# Python 2 and Python 3 treat comparison operators.
self.assertEqual(NotImplemented, a.__gt__('invalid'))
def test_less_than_or_equal(self): def test_less_than_or_equal(self):
""" """
Test that the less than or equal operator returns True/False when Test that the less than or equal operator correctly returns True/False
comparing two different ProtocolVersions. when comparing two different ProtocolVersions.
""" """
a = ProtocolVersion.create(1, 0) a = contents.ProtocolVersion(1, 0)
b = ProtocolVersion.create(1, 1) b = contents.ProtocolVersion(1, 1)
c = ProtocolVersion.create(2, 0) c = contents.ProtocolVersion(2, 0)
d = ProtocolVersion.create(0, 2) d = contents.ProtocolVersion(0, 2)
self.assertTrue(a <= b) self.assertTrue(a <= b)
self.assertFalse(b <= a) self.assertFalse(b <= a)
@ -223,15 +303,19 @@ class TestProtocolVersion(TestCase):
self.assertFalse(c <= d) self.assertFalse(c <= d)
self.assertTrue(d <= c) self.assertTrue(d <= c)
# A direct call to __le__ is required here due to differences in how
# Python 2 and Python 3 treat comparison operators.
self.assertEqual(NotImplemented, a.__le__('invalid'))
def test_greater_than_or_equal(self): def test_greater_than_or_equal(self):
""" """
Test that the greater than or equal operator returns True/False when Test that the greater than or equal operator correctly returns
comparing two different ProtocolVersions. True/False when comparing two different ProtocolVersions.
""" """
a = ProtocolVersion.create(1, 0) a = contents.ProtocolVersion(1, 0)
b = ProtocolVersion.create(1, 1) b = contents.ProtocolVersion(1, 1)
c = ProtocolVersion.create(2, 0) c = contents.ProtocolVersion(2, 0)
d = ProtocolVersion.create(0, 2) d = contents.ProtocolVersion(0, 2)
self.assertFalse(a >= b) self.assertFalse(a >= b)
self.assertTrue(b >= a) self.assertTrue(b >= a)
@ -241,30 +325,25 @@ class TestProtocolVersion(TestCase):
self.assertTrue(c >= d) self.assertTrue(c >= d)
self.assertFalse(d >= c) self.assertFalse(d >= c)
# A direct call to __ge__ is required here due to differences in how
# Python 2 and Python 3 treat comparison operators.
self.assertEqual(NotImplemented, a.__ge__('invalid'))
def test_repr(self): def test_repr(self):
a = ProtocolVersion.create(1, 0) """
Test that repr can be applied to a ProtocolVersion struct.
"""
struct = contents.ProtocolVersion(1, 0)
self.assertEqual("1.0", "{0}".format(a)) self.assertEqual(
"ProtocolVersion(major=1, minor=0)",
"{}".format(repr(struct))
)
def _test_create(self, major, minor): def test_str(self):
protocol_version = ProtocolVersion.create(major, minor) """
Test that str can be applied to a ProtocolVersion struct.
"""
struct = contents.ProtocolVersion(1, 0)
if major is None: self.assertEqual("1.0", str(struct))
expected = ProtocolVersion.ProtocolVersionMajor()
else:
expected = ProtocolVersion.ProtocolVersionMajor(major)
self.assertEqual(expected, protocol_version.protocol_version_major)
if minor is None:
expected = ProtocolVersion.ProtocolVersionMinor()
else:
expected = ProtocolVersion.ProtocolVersionMinor(minor)
self.assertEqual(expected, protocol_version.protocol_version_minor)
def test_create_with_none(self):
self._test_create(None, None)
def test_create_with_args(self):
self._test_create(1, 0)

View File

@ -30,10 +30,10 @@ class TestDiscoverVersionsRequestPayload(TestCase):
self.protocol_versions_empty = list() self.protocol_versions_empty = list()
self.protocol_versions_one = list() self.protocol_versions_one = list()
self.protocol_versions_one.append(ProtocolVersion.create(1, 0)) self.protocol_versions_one.append(ProtocolVersion(1, 0))
self.protocol_versions_two = list() self.protocol_versions_two = list()
self.protocol_versions_two.append(ProtocolVersion.create(1, 1)) self.protocol_versions_two.append(ProtocolVersion(1, 1))
self.protocol_versions_two.append(ProtocolVersion.create(1, 0)) self.protocol_versions_two.append(ProtocolVersion(1, 0))
self.encoding_empty = utils.BytearrayStream(( self.encoding_empty = utils.BytearrayStream((
b'\x42\x00\x79\x01\x00\x00\x00\x00')) b'\x42\x00\x79\x01\x00\x00\x00\x00'))
@ -157,10 +157,10 @@ class TestDiscoverVersionsResponsePayload(TestCase):
self.protocol_versions_empty = list() self.protocol_versions_empty = list()
self.protocol_versions_one = list() self.protocol_versions_one = list()
self.protocol_versions_one.append(ProtocolVersion.create(1, 0)) self.protocol_versions_one.append(ProtocolVersion(1, 0))
self.protocol_versions_two = list() self.protocol_versions_two = list()
self.protocol_versions_two.append(ProtocolVersion.create(1, 1)) self.protocol_versions_two.append(ProtocolVersion(1, 1))
self.protocol_versions_two.append(ProtocolVersion.create(1, 0)) self.protocol_versions_two.append(ProtocolVersion(1, 0))
self.encoding_empty = utils.BytearrayStream(( self.encoding_empty = utils.BytearrayStream((
b'\x42\x00\x7C\x01\x00\x00\x00\x00')) b'\x42\x00\x7C\x01\x00\x00\x00\x00'))

View File

@ -183,25 +183,25 @@ class TestRequestMessage(TestCase):
msg.format(contents.ProtocolVersion, msg.format(contents.ProtocolVersion,
type(protocol_version))) type(protocol_version)))
protocol_version_major = protocol_version.protocol_version_major protocol_version_major = protocol_version.major
msg = "Bad protocol version major type: expected {0}, received {1}" msg = "Bad protocol version major type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMajor exp_type = int
rcv_type = type(protocol_version_major) rcv_type = type(protocol_version_major)
self.assertIsInstance(protocol_version_major, exp_type, self.assertIsInstance(protocol_version_major, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version major value: expected {0}, received {1}" msg = "Bad protocol version major value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_major.value, self.assertEqual(1, protocol_version_major,
msg.format(1, protocol_version_major.value)) msg.format(1, protocol_version_major))
protocol_version_minor = protocol_version.protocol_version_minor protocol_version_minor = protocol_version.minor
msg = "Bad protocol version minor type: expected {0}, received {1}" msg = "Bad protocol version minor type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMinor exp_type = int
rcv_type = type(protocol_version_minor) rcv_type = type(protocol_version_minor)
self.assertIsInstance(protocol_version_minor, exp_type, self.assertIsInstance(protocol_version_minor, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version minor value: expected {0}, received {1}" msg = "Bad protocol version minor value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_minor.value, self.assertEqual(1, protocol_version_minor,
msg.format(1, protocol_version_minor.value)) msg.format(1, protocol_version_minor))
batch_count = request_header.batch_count batch_count = request_header.batch_count
msg = "Bad batch count type: expected {0}, received {1}" msg = "Bad batch count type: expected {0}, received {1}"
@ -352,7 +352,7 @@ class TestRequestMessage(TestCase):
exp_value, attribute_value.value)) exp_value, attribute_value.value))
def test_create_request_write(self): def test_create_request_write(self):
prot_ver = contents.ProtocolVersion.create(1, 1) prot_ver = contents.ProtocolVersion(1, 1)
batch_count = contents.BatchCount(1) batch_count = contents.BatchCount(1)
request_header = messages.RequestHeader(protocol_version=prot_ver, request_header = messages.RequestHeader(protocol_version=prot_ver,
@ -414,25 +414,25 @@ class TestRequestMessage(TestCase):
msg.format(contents.ProtocolVersion, msg.format(contents.ProtocolVersion,
type(protocol_version))) type(protocol_version)))
protocol_version_major = protocol_version.protocol_version_major protocol_version_major = protocol_version.major
msg = "Bad protocol version major type: expected {0}, received {1}" msg = "Bad protocol version major type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMajor exp_type = int
rcv_type = type(protocol_version_major) rcv_type = type(protocol_version_major)
self.assertIsInstance(protocol_version_major, exp_type, self.assertIsInstance(protocol_version_major, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version major value: expected {0}, received {1}" msg = "Bad protocol version major value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_major.value, self.assertEqual(1, protocol_version_major,
msg.format(1, protocol_version_major.value)) msg.format(1, protocol_version_major))
protocol_version_minor = protocol_version.protocol_version_minor protocol_version_minor = protocol_version.minor
msg = "Bad protocol version minor type: expected {0}, received {1}" msg = "Bad protocol version minor type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMinor exp_type = int
rcv_type = type(protocol_version_minor) rcv_type = type(protocol_version_minor)
self.assertIsInstance(protocol_version_minor, exp_type, self.assertIsInstance(protocol_version_minor, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version minor value: expected {0}, received {1}" msg = "Bad protocol version minor value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_minor.value, self.assertEqual(1, protocol_version_minor,
msg.format(1, protocol_version_minor.value)) msg.format(1, protocol_version_minor))
batch_count = request_header.batch_count batch_count = request_header.batch_count
msg = "Bad batch count type: expected {0}, received {1}" msg = "Bad batch count type: expected {0}, received {1}"
@ -486,7 +486,7 @@ class TestRequestMessage(TestCase):
) )
def test_get_request_write(self): def test_get_request_write(self):
prot_ver = contents.ProtocolVersion.create(1, 1) prot_ver = contents.ProtocolVersion(1, 1)
batch_count = contents.BatchCount(1) batch_count = contents.BatchCount(1)
req_header = messages.RequestHeader(protocol_version=prot_ver, req_header = messages.RequestHeader(protocol_version=prot_ver,
@ -532,25 +532,25 @@ class TestRequestMessage(TestCase):
msg.format(contents.ProtocolVersion, msg.format(contents.ProtocolVersion,
type(protocol_version))) type(protocol_version)))
protocol_version_major = protocol_version.protocol_version_major protocol_version_major = protocol_version.major
msg = "Bad protocol version major type: expected {0}, received {1}" msg = "Bad protocol version major type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMajor exp_type = int
rcv_type = type(protocol_version_major) rcv_type = type(protocol_version_major)
self.assertIsInstance(protocol_version_major, exp_type, self.assertIsInstance(protocol_version_major, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version major value: expected {0}, received {1}" msg = "Bad protocol version major value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_major.value, self.assertEqual(1, protocol_version_major,
msg.format(1, protocol_version_major.value)) msg.format(1, protocol_version_major))
protocol_version_minor = protocol_version.protocol_version_minor protocol_version_minor = protocol_version.minor
msg = "Bad protocol version minor type: expected {0}, received {1}" msg = "Bad protocol version minor type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMinor exp_type = int
rcv_type = type(protocol_version_minor) rcv_type = type(protocol_version_minor)
self.assertIsInstance(protocol_version_minor, exp_type, self.assertIsInstance(protocol_version_minor, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version minor value: expected {0}, received {1}" msg = "Bad protocol version minor value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_minor.value, self.assertEqual(1, protocol_version_minor,
msg.format(1, protocol_version_minor.value)) msg.format(1, protocol_version_minor))
batch_count = request_header.batch_count batch_count = request_header.batch_count
msg = "Bad batch count type: expected {0}, received {1}" msg = "Bad batch count type: expected {0}, received {1}"
@ -605,7 +605,7 @@ class TestRequestMessage(TestCase):
msg.format(exp_value, rcv_value)) msg.format(exp_value, rcv_value))
def test_destroy_request_write(self): def test_destroy_request_write(self):
prot_ver = contents.ProtocolVersion.create(1, 1) prot_ver = contents.ProtocolVersion(1, 1)
batch_count = contents.BatchCount(1) batch_count = contents.BatchCount(1)
req_header = messages.RequestHeader(protocol_version=prot_ver, req_header = messages.RequestHeader(protocol_version=prot_ver,
@ -651,25 +651,25 @@ class TestRequestMessage(TestCase):
msg.format(contents.ProtocolVersion, msg.format(contents.ProtocolVersion,
type(protocol_version))) type(protocol_version)))
protocol_version_major = protocol_version.protocol_version_major protocol_version_major = protocol_version.major
msg = "Bad protocol version major type: expected {0}, received {1}" msg = "Bad protocol version major type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMajor exp_type = int
rcv_type = type(protocol_version_major) rcv_type = type(protocol_version_major)
self.assertIsInstance(protocol_version_major, exp_type, self.assertIsInstance(protocol_version_major, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version major value: expected {0}, received {1}" msg = "Bad protocol version major value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_major.value, self.assertEqual(1, protocol_version_major,
msg.format(1, protocol_version_major.value)) msg.format(1, protocol_version_major))
protocol_version_minor = protocol_version.protocol_version_minor protocol_version_minor = protocol_version.minor
msg = "Bad protocol version minor type: expected {0}, received {1}" msg = "Bad protocol version minor type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMinor exp_type = int
rcv_type = type(protocol_version_minor) rcv_type = type(protocol_version_minor)
self.assertIsInstance(protocol_version_minor, exp_type, self.assertIsInstance(protocol_version_minor, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version minor value: expected {0}, received {1}" msg = "Bad protocol version minor value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_minor.value, self.assertEqual(1, protocol_version_minor,
msg.format(1, protocol_version_minor.value)) msg.format(1, protocol_version_minor))
batch_count = request_header.batch_count batch_count = request_header.batch_count
msg = "Bad batch count type: expected {0}, received {1}" msg = "Bad batch count type: expected {0}, received {1}"
@ -775,7 +775,7 @@ class TestRequestMessage(TestCase):
msg.format(exp_length, rcv_length)) msg.format(exp_length, rcv_length))
def test_register_request_write(self): def test_register_request_write(self):
prot_ver = contents.ProtocolVersion.create(1, 1) prot_ver = contents.ProtocolVersion(1, 1)
batch_count = contents.BatchCount(1) batch_count = contents.BatchCount(1)
req_header = messages.RequestHeader(protocol_version=prot_ver, req_header = messages.RequestHeader(protocol_version=prot_ver,
@ -867,25 +867,25 @@ class TestRequestMessage(TestCase):
msg.format(contents.ProtocolVersion, msg.format(contents.ProtocolVersion,
type(protocol_version))) type(protocol_version)))
protocol_version_major = protocol_version.protocol_version_major protocol_version_major = protocol_version.major
msg = "Bad protocol version major type: expected {0}, received {1}" msg = "Bad protocol version major type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMajor exp_type = int
rcv_type = type(protocol_version_major) rcv_type = type(protocol_version_major)
self.assertIsInstance(protocol_version_major, exp_type, self.assertIsInstance(protocol_version_major, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version major value: expected {0}, received {1}" msg = "Bad protocol version major value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_major.value, self.assertEqual(1, protocol_version_major,
msg.format(1, protocol_version_major.value)) msg.format(1, protocol_version_major))
protocol_version_minor = protocol_version.protocol_version_minor protocol_version_minor = protocol_version.minor
msg = "Bad protocol version minor type: expected {0}, received {1}" msg = "Bad protocol version minor type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMinor exp_type = int
rcv_type = type(protocol_version_minor) rcv_type = type(protocol_version_minor)
self.assertIsInstance(protocol_version_minor, exp_type, self.assertIsInstance(protocol_version_minor, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version minor value: expected {0}, received {1}" msg = "Bad protocol version minor value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_minor.value, self.assertEqual(1, protocol_version_minor,
msg.format(1, protocol_version_minor.value)) msg.format(1, protocol_version_minor))
batch_count = request_header.batch_count batch_count = request_header.batch_count
msg = "Bad batch count type: expected {0}, received {1}" msg = "Bad batch count type: expected {0}, received {1}"
@ -1012,25 +1012,25 @@ class TestRequestMessage(TestCase):
msg.format(contents.ProtocolVersion, msg.format(contents.ProtocolVersion,
type(protocol_version))) type(protocol_version)))
protocol_version_major = protocol_version.protocol_version_major protocol_version_major = protocol_version.major
msg = "Bad protocol version major type: expected {0}, received {1}" msg = "Bad protocol version major type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMajor exp_type = int
rcv_type = type(protocol_version_major) rcv_type = type(protocol_version_major)
self.assertIsInstance(protocol_version_major, exp_type, self.assertIsInstance(protocol_version_major, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version major value: expected {0}, received {1}" msg = "Bad protocol version major value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_major.value, self.assertEqual(1, protocol_version_major,
msg.format(1, protocol_version_major.value)) msg.format(1, protocol_version_major))
protocol_version_minor = protocol_version.protocol_version_minor protocol_version_minor = protocol_version.minor
msg = "Bad protocol version minor type: expected {0}, received {1}" msg = "Bad protocol version minor type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMinor exp_type = int
rcv_type = type(protocol_version_minor) rcv_type = type(protocol_version_minor)
self.assertIsInstance(protocol_version_minor, exp_type, self.assertIsInstance(protocol_version_minor, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version minor value: expected {0}, received {1}" msg = "Bad protocol version minor value: expected {0}, received {1}"
self.assertEqual(2, protocol_version_minor.value, self.assertEqual(2, protocol_version_minor,
msg.format(2, protocol_version_minor.value)) msg.format(2, protocol_version_minor))
batch_count = request_header.batch_count batch_count = request_header.batch_count
msg = "Bad batch count type: expected {0}, received {1}" msg = "Bad batch count type: expected {0}, received {1}"
@ -1114,7 +1114,7 @@ class TestRequestMessage(TestCase):
) )
def test_mac_request_write(self): def test_mac_request_write(self):
prot_ver = contents.ProtocolVersion.create(1, 2) prot_ver = contents.ProtocolVersion(1, 2)
batch_count = contents.BatchCount(1) batch_count = contents.BatchCount(1)
req_header = messages.RequestHeader(protocol_version=prot_ver, req_header = messages.RequestHeader(protocol_version=prot_ver,
@ -1284,26 +1284,26 @@ class TestResponseMessage(TestCase):
contents.ProtocolVersion, contents.ProtocolVersion,
type(protocol_version))) type(protocol_version)))
protocol_version_major = protocol_version.protocol_version_major protocol_version_major = protocol_version.major
exp_type = contents.ProtocolVersion.ProtocolVersionMajor exp_type = int
rcv_type = type(protocol_version_major) rcv_type = type(protocol_version_major)
self.assertIsInstance(protocol_version_major, exp_type, self.assertIsInstance(protocol_version_major, exp_type,
self.msg.format('protocol version major', self.msg.format('protocol version major',
'type', exp_type, rcv_type)) 'type', exp_type, rcv_type))
self.assertEqual(1, protocol_version_major.value, self.assertEqual(1, protocol_version_major,
self.msg.format('protocol version major', 'value', self.msg.format('protocol version major', 'value',
1, protocol_version_major.value)) 1, protocol_version_major))
protocol_version_minor = protocol_version.protocol_version_minor protocol_version_minor = protocol_version.minor
exp_type = contents.ProtocolVersion.ProtocolVersionMinor exp_type = int
rcv_type = type(protocol_version_minor) rcv_type = type(protocol_version_minor)
self.assertIsInstance(protocol_version_minor, self.assertIsInstance(protocol_version_minor,
contents.ProtocolVersion.ProtocolVersionMinor, int,
self.msg.format('protocol version minor', self.msg.format('protocol version minor',
'type', exp_type, rcv_type)) 'type', exp_type, rcv_type))
self.assertEqual(1, protocol_version_minor.value, self.assertEqual(1, protocol_version_minor,
self.msg.format('protocol version minor', 'value', self.msg.format('protocol version minor', 'value',
1, protocol_version_minor.value)) 1, protocol_version_minor))
time_stamp = response_header.time_stamp time_stamp = response_header.time_stamp
value = 0x4f9a54e5 # Fri Apr 27 10:12:21 CEST 2012 value = 0x4f9a54e5 # Fri Apr 27 10:12:21 CEST 2012
@ -1383,7 +1383,7 @@ class TestResponseMessage(TestCase):
unique_identifier.value, value)) unique_identifier.value, value))
def test_create_response_write(self): def test_create_response_write(self):
prot_ver = contents.ProtocolVersion.create(1, 1) prot_ver = contents.ProtocolVersion(1, 1)
# Fri Apr 27 10:12:21 CEST 2012 # Fri Apr 27 10:12:21 CEST 2012
time_stamp = contents.TimeStamp(0x4f9a54e5) time_stamp = contents.TimeStamp(0x4f9a54e5)
@ -1436,25 +1436,25 @@ class TestResponseMessage(TestCase):
contents.ProtocolVersion, contents.ProtocolVersion,
type(protocol_version))) type(protocol_version)))
protocol_version_major = protocol_version.protocol_version_major protocol_version_major = protocol_version.major
exp_type = contents.ProtocolVersion.ProtocolVersionMajor exp_type = int
rcv_type = type(protocol_version_major) rcv_type = type(protocol_version_major)
self.assertIsInstance(protocol_version_major, exp_type, self.assertIsInstance(protocol_version_major, exp_type,
self.msg.format('protocol version major', 'type', self.msg.format('protocol version major', 'type',
exp_type, rcv_type)) exp_type, rcv_type))
self.assertEqual(1, protocol_version_major.value, self.assertEqual(1, protocol_version_major,
self.msg.format('protocol version major', 'value', self.msg.format('protocol version major', 'value',
1, protocol_version_major.value)) 1, protocol_version_major))
protocol_version_minor = protocol_version.protocol_version_minor protocol_version_minor = protocol_version.minor
exp_type = contents.ProtocolVersion.ProtocolVersionMinor exp_type = int
rcv_type = type(protocol_version_minor) rcv_type = type(protocol_version_minor)
self.assertIsInstance(protocol_version_minor, exp_type, self.assertIsInstance(protocol_version_minor, exp_type,
self.msg.format('protocol version minor', 'type', self.msg.format('protocol version minor', 'type',
exp_type, rcv_type)) exp_type, rcv_type))
self.assertEqual(1, protocol_version_minor.value, self.assertEqual(1, protocol_version_minor,
self.msg.format('protocol version minor', 'value', self.msg.format('protocol version minor', 'value',
1, protocol_version_minor.value)) 1, protocol_version_minor))
time_stamp = response_header.time_stamp time_stamp = response_header.time_stamp
value = 0x4f9a54e7 # Fri Apr 27 10:12:23 CEST 2012 value = 0x4f9a54e7 # Fri Apr 27 10:12:23 CEST 2012
@ -1584,7 +1584,7 @@ class TestResponseMessage(TestCase):
'value', exp, obs)) 'value', exp, obs))
def test_get_response_write(self): def test_get_response_write(self):
prot_ver = contents.ProtocolVersion.create(1, 1) prot_ver = contents.ProtocolVersion(1, 1)
# Fri Apr 27 10:12:23 CEST 2012 # Fri Apr 27 10:12:23 CEST 2012
time_stamp = contents.TimeStamp(0x4f9a54e7) time_stamp = contents.TimeStamp(0x4f9a54e7)
@ -1665,25 +1665,25 @@ class TestResponseMessage(TestCase):
msg.format(contents.ProtocolVersion, msg.format(contents.ProtocolVersion,
type(protocol_version))) type(protocol_version)))
protocol_version_major = protocol_version.protocol_version_major protocol_version_major = protocol_version.major
msg = "Bad protocol version major type: expected {0}, received {1}" msg = "Bad protocol version major type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMajor exp_type = int
rcv_type = type(protocol_version_major) rcv_type = type(protocol_version_major)
self.assertIsInstance(protocol_version_major, exp_type, self.assertIsInstance(protocol_version_major, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version major value: expected {0}, received {1}" msg = "Bad protocol version major value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_major.value, self.assertEqual(1, protocol_version_major,
msg.format(1, protocol_version_major.value)) msg.format(1, protocol_version_major))
protocol_version_minor = protocol_version.protocol_version_minor protocol_version_minor = protocol_version.minor
msg = "Bad protocol version minor type: expected {0}, received {1}" msg = "Bad protocol version minor type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMinor exp_type = int
rcv_type = type(protocol_version_minor) rcv_type = type(protocol_version_minor)
self.assertIsInstance(protocol_version_minor, exp_type, self.assertIsInstance(protocol_version_minor, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version minor value: expected {0}, received {1}" msg = "Bad protocol version minor value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_minor.value, self.assertEqual(1, protocol_version_minor,
msg.format(1, protocol_version_minor.value)) msg.format(1, protocol_version_minor))
time_stamp = response_header.time_stamp time_stamp = response_header.time_stamp
value = 0x4f9a54e5 # Fri Apr 27 10:12:21 CEST 2012 value = 0x4f9a54e5 # Fri Apr 27 10:12:21 CEST 2012
@ -1758,7 +1758,7 @@ class TestResponseMessage(TestCase):
msg.format(exp_value, rcv_value)) msg.format(exp_value, rcv_value))
def test_destroy_response_write(self): def test_destroy_response_write(self):
prot_ver = contents.ProtocolVersion.create(1, 1) prot_ver = contents.ProtocolVersion(1, 1)
# Fri Apr 27 10:12:21 CEST 2012 # Fri Apr 27 10:12:21 CEST 2012
time_stamp = contents.TimeStamp(0x4f9a54e5) time_stamp = contents.TimeStamp(0x4f9a54e5)
@ -1808,25 +1808,25 @@ class TestResponseMessage(TestCase):
msg.format(contents.ProtocolVersion, msg.format(contents.ProtocolVersion,
type(protocol_version))) type(protocol_version)))
protocol_version_major = protocol_version.protocol_version_major protocol_version_major = protocol_version.major
msg = "Bad protocol version major type: expected {0}, received {1}" msg = "Bad protocol version major type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMajor exp_type = int
rcv_type = type(protocol_version_major) rcv_type = type(protocol_version_major)
self.assertIsInstance(protocol_version_major, exp_type, self.assertIsInstance(protocol_version_major, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version major value: expected {0}, received {1}" msg = "Bad protocol version major value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_major.value, self.assertEqual(1, protocol_version_major,
msg.format(1, protocol_version_major.value)) msg.format(1, protocol_version_major))
protocol_version_minor = protocol_version.protocol_version_minor protocol_version_minor = protocol_version.minor
msg = "Bad protocol version minor type: expected {0}, received {1}" msg = "Bad protocol version minor type: expected {0}, received {1}"
exp_type = contents.ProtocolVersion.ProtocolVersionMinor exp_type = int
rcv_type = type(protocol_version_minor) rcv_type = type(protocol_version_minor)
self.assertIsInstance(protocol_version_minor, exp_type, self.assertIsInstance(protocol_version_minor, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
msg = "Bad protocol version minor value: expected {0}, received {1}" msg = "Bad protocol version minor value: expected {0}, received {1}"
self.assertEqual(1, protocol_version_minor.value, self.assertEqual(1, protocol_version_minor,
msg.format(1, protocol_version_minor.value)) msg.format(1, protocol_version_minor))
time_stamp = response_header.time_stamp time_stamp = response_header.time_stamp
value = 0x4f9a54e5 # Fri Apr 27 10:12:21 CEST 2012 value = 0x4f9a54e5 # Fri Apr 27 10:12:21 CEST 2012
@ -1901,7 +1901,7 @@ class TestResponseMessage(TestCase):
msg.format(exp_value, rcv_value)) msg.format(exp_value, rcv_value))
def test_register_response_write(self): def test_register_response_write(self):
prot_ver = contents.ProtocolVersion.create(1, 1) prot_ver = contents.ProtocolVersion(1, 1)
# Fri Apr 27 10:12:21 CEST 2012 # Fri Apr 27 10:12:21 CEST 2012
time_stamp = contents.TimeStamp(0x4f9a54e5) time_stamp = contents.TimeStamp(0x4f9a54e5)
@ -1934,7 +1934,7 @@ class TestResponseMessage(TestCase):
self.assertEqual(self.register, result, msg) self.assertEqual(self.register, result, msg)
def test_locate_response_write(self): def test_locate_response_write(self):
prot_ver = contents.ProtocolVersion.create(1, 1) prot_ver = contents.ProtocolVersion(1, 1)
# Fri Apr 27 10:12:22 CEST 2012 # Fri Apr 27 10:12:22 CEST 2012
time_stamp = contents.TimeStamp(0x4f9a54e6) time_stamp = contents.TimeStamp(0x4f9a54e6)
@ -1985,25 +1985,25 @@ class TestResponseMessage(TestCase):
contents.ProtocolVersion, contents.ProtocolVersion,
type(protocol_version))) type(protocol_version)))
protocol_version_major = protocol_version.protocol_version_major protocol_version_major = protocol_version.major
exp_type = contents.ProtocolVersion.ProtocolVersionMajor exp_type = int
rcv_type = type(protocol_version_major) rcv_type = type(protocol_version_major)
self.assertIsInstance(protocol_version_major, exp_type, self.assertIsInstance(protocol_version_major, exp_type,
self.msg.format('protocol version major', 'type', self.msg.format('protocol version major', 'type',
exp_type, rcv_type)) exp_type, rcv_type))
self.assertEqual(1, protocol_version_major.value, self.assertEqual(1, protocol_version_major,
self.msg.format('protocol version major', 'value', self.msg.format('protocol version major', 'value',
1, protocol_version_major.value)) 1, protocol_version_major))
protocol_version_minor = protocol_version.protocol_version_minor protocol_version_minor = protocol_version.minor
exp_type = contents.ProtocolVersion.ProtocolVersionMinor exp_type = int
rcv_type = type(protocol_version_minor) rcv_type = type(protocol_version_minor)
self.assertIsInstance(protocol_version_minor, exp_type, self.assertIsInstance(protocol_version_minor, exp_type,
self.msg.format('protocol version minor', 'type', self.msg.format('protocol version minor', 'type',
exp_type, rcv_type)) exp_type, rcv_type))
self.assertEqual(2, protocol_version_minor.value, self.assertEqual(2, protocol_version_minor,
self.msg.format('protocol version minor', 'value', self.msg.format('protocol version minor', 'value',
2, protocol_version_minor.value)) 2, protocol_version_minor))
time_stamp = response_header.time_stamp time_stamp = response_header.time_stamp
value = 0x588a3f23 value = 0x588a3f23
@ -2092,7 +2092,7 @@ class TestResponseMessage(TestCase):
binascii.hexlify(value))) binascii.hexlify(value)))
def test_mac_response_write(self): def test_mac_response_write(self):
prot_ver = contents.ProtocolVersion.create(1, 2) prot_ver = contents.ProtocolVersion(1, 2)
# Fri Apr 27 10:12:23 CEST 2012 # Fri Apr 27 10:12:23 CEST 2012
time_stamp = contents.TimeStamp(0x588a3f23) time_stamp = contents.TimeStamp(0x588a3f23)
@ -2142,7 +2142,7 @@ class TestResponseMessage(TestCase):
def test_message_invalid_response_write(self): def test_message_invalid_response_write(self):
# Batch item of 'INVALID MESSAGE' response # Batch item of 'INVALID MESSAGE' response
# has no 'operation' attribute # has no 'operation' attribute
prot_ver = contents.ProtocolVersion.create(1, 1) prot_ver = contents.ProtocolVersion(1, 1)
# Time stamp Tue Mar 29 10:58:37 2016 # Time stamp Tue Mar 29 10:58:37 2016
time_stamp = contents.TimeStamp(0x56fa43bd) time_stamp = contents.TimeStamp(0x56fa43bd)

View File

@ -89,7 +89,7 @@ class TestKmipEngine(testtools.TestCase):
) )
] ]
protocol = contents.ProtocolVersion.create(1, 0) protocol = contents.ProtocolVersion(1, 0)
max_size = contents.MaximumResponseSize(2 ** 20) max_size = contents.MaximumResponseSize(2 ** 20)
asynch = contents.AsynchronousIndicator(False) asynch = contents.AsynchronousIndicator(False)
@ -339,7 +339,7 @@ class TestKmipEngine(testtools.TestCase):
""" """
e = engine.KmipEngine() e = engine.KmipEngine()
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
e._protocol_version = contents.ProtocolVersion.create(1, 0) e._protocol_version = contents.ProtocolVersion(1, 0)
args = (None, ) args = (None, )
regex = "DiscoverVersions is not supported by KMIP {0}".format( regex = "DiscoverVersions is not supported by KMIP {0}".format(
@ -360,7 +360,7 @@ class TestKmipEngine(testtools.TestCase):
e = engine.KmipEngine() e = engine.KmipEngine()
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
protocol = contents.ProtocolVersion.create(1, 1) protocol = contents.ProtocolVersion(1, 1)
header = messages.RequestHeader( header = messages.RequestHeader(
protocol_version=protocol, protocol_version=protocol,
maximum_response_size=contents.MaximumResponseSize(2 ** 20), maximum_response_size=contents.MaximumResponseSize(2 ** 20),
@ -402,7 +402,7 @@ class TestKmipEngine(testtools.TestCase):
self.assertIsNotNone(header) self.assertIsNotNone(header)
self.assertEqual( self.assertEqual(
contents.ProtocolVersion.create(1, 1), contents.ProtocolVersion(1, 1),
header.protocol_version header.protocol_version
) )
self.assertIsInstance(header.time_stamp, contents.TimeStamp) self.assertIsInstance(header.time_stamp, contents.TimeStamp)
@ -442,7 +442,7 @@ class TestKmipEngine(testtools.TestCase):
e = engine.KmipEngine() e = engine.KmipEngine()
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
protocol = contents.ProtocolVersion.create(0, 1) protocol = contents.ProtocolVersion(0, 1)
header = messages.RequestHeader( header = messages.RequestHeader(
protocol_version=protocol protocol_version=protocol
) )
@ -470,7 +470,7 @@ class TestKmipEngine(testtools.TestCase):
e = engine.KmipEngine() e = engine.KmipEngine()
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
protocol = contents.ProtocolVersion.create(1, 0) protocol = contents.ProtocolVersion(1, 0)
header = messages.RequestHeader( header = messages.RequestHeader(
protocol_version=protocol, protocol_version=protocol,
time_stamp=contents.TimeStamp(0) time_stamp=contents.TimeStamp(0)
@ -503,7 +503,7 @@ class TestKmipEngine(testtools.TestCase):
e = engine.KmipEngine() e = engine.KmipEngine()
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
protocol = contents.ProtocolVersion.create(1, 0) protocol = contents.ProtocolVersion(1, 0)
header = messages.RequestHeader( header = messages.RequestHeader(
protocol_version=protocol, protocol_version=protocol,
time_stamp=contents.TimeStamp(10 ** 10) time_stamp=contents.TimeStamp(10 ** 10)
@ -536,7 +536,7 @@ class TestKmipEngine(testtools.TestCase):
e = engine.KmipEngine() e = engine.KmipEngine()
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
protocol = contents.ProtocolVersion.create(1, 1) protocol = contents.ProtocolVersion(1, 1)
header = messages.RequestHeader( header = messages.RequestHeader(
protocol_version=protocol, protocol_version=protocol,
asynchronous_indicator=contents.AsynchronousIndicator(True) asynchronous_indicator=contents.AsynchronousIndicator(True)
@ -563,7 +563,7 @@ class TestKmipEngine(testtools.TestCase):
e = engine.KmipEngine() e = engine.KmipEngine()
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
protocol = contents.ProtocolVersion.create(1, 1) protocol = contents.ProtocolVersion(1, 1)
header = messages.RequestHeader( header = messages.RequestHeader(
protocol_version=protocol, protocol_version=protocol,
authentication=contents.Authentication(), authentication=contents.Authentication(),
@ -593,7 +593,7 @@ class TestKmipEngine(testtools.TestCase):
e = engine.KmipEngine() e = engine.KmipEngine()
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
protocol = contents.ProtocolVersion.create(1, 1) protocol = contents.ProtocolVersion(1, 1)
header = messages.RequestHeader( header = messages.RequestHeader(
protocol_version=protocol, protocol_version=protocol,
authentication=None, authentication=None,
@ -629,7 +629,7 @@ class TestKmipEngine(testtools.TestCase):
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
response = e.build_error_response( response = e.build_error_response(
contents.ProtocolVersion.create(1, 1), contents.ProtocolVersion(1, 1),
enums.ResultReason.GENERAL_FAILURE, enums.ResultReason.GENERAL_FAILURE,
"A general test failure occurred." "A general test failure occurred."
) )
@ -639,7 +639,7 @@ class TestKmipEngine(testtools.TestCase):
header = response.response_header header = response.response_header
self.assertEqual( self.assertEqual(
contents.ProtocolVersion.create(1, 1), contents.ProtocolVersion(1, 1),
header.protocol_version header.protocol_version
) )
self.assertIsNotNone(header.time_stamp) self.assertIsNotNone(header.time_stamp)
@ -760,7 +760,7 @@ class TestKmipEngine(testtools.TestCase):
""" """
e = engine.KmipEngine() e = engine.KmipEngine()
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
e._protocol_version = contents.ProtocolVersion.create(1, 0) e._protocol_version = contents.ProtocolVersion(1, 0)
batch = list([ batch = list([
messages.RequestBatchItem( messages.RequestBatchItem(
@ -6515,7 +6515,7 @@ class TestKmipEngine(testtools.TestCase):
e = engine.KmipEngine() e = engine.KmipEngine()
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
e._protocol_version = contents.ProtocolVersion.create(1, 0) e._protocol_version = contents.ProtocolVersion(1, 0)
payload = payloads.QueryRequestPayload([ payload = payloads.QueryRequestPayload([
misc.QueryFunction(enums.QueryFunction.QUERY_OPERATIONS), misc.QueryFunction(enums.QueryFunction.QUERY_OPERATIONS),
@ -6601,7 +6601,7 @@ class TestKmipEngine(testtools.TestCase):
e = engine.KmipEngine() e = engine.KmipEngine()
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
e._protocol_version = contents.ProtocolVersion.create(1, 1) e._protocol_version = contents.ProtocolVersion(1, 1)
payload = payloads.QueryRequestPayload([ payload = payloads.QueryRequestPayload([
misc.QueryFunction(enums.QueryFunction.QUERY_OPERATIONS), misc.QueryFunction(enums.QueryFunction.QUERY_OPERATIONS),
@ -6691,7 +6691,7 @@ class TestKmipEngine(testtools.TestCase):
e = engine.KmipEngine() e = engine.KmipEngine()
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
e._protocol_version = contents.ProtocolVersion.create(1, 2) e._protocol_version = contents.ProtocolVersion(1, 2)
payload = payloads.QueryRequestPayload([ payload = payloads.QueryRequestPayload([
misc.QueryFunction(enums.QueryFunction.QUERY_OPERATIONS), misc.QueryFunction(enums.QueryFunction.QUERY_OPERATIONS),
@ -6817,22 +6817,22 @@ class TestKmipEngine(testtools.TestCase):
self.assertIsNotNone(result.protocol_versions) self.assertIsNotNone(result.protocol_versions)
self.assertEqual(3, len(result.protocol_versions)) self.assertEqual(3, len(result.protocol_versions))
self.assertEqual( self.assertEqual(
contents.ProtocolVersion.create(1, 2), contents.ProtocolVersion(1, 2),
result.protocol_versions[0] result.protocol_versions[0]
) )
self.assertEqual( self.assertEqual(
contents.ProtocolVersion.create(1, 1), contents.ProtocolVersion(1, 1),
result.protocol_versions[1] result.protocol_versions[1]
) )
self.assertEqual( self.assertEqual(
contents.ProtocolVersion.create(1, 0), contents.ProtocolVersion(1, 0),
result.protocol_versions[2] result.protocol_versions[2]
) )
# Test detailed request. # Test detailed request.
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
payload = payloads.DiscoverVersionsRequestPayload([ payload = payloads.DiscoverVersionsRequestPayload([
contents.ProtocolVersion.create(1, 0) contents.ProtocolVersion(1, 0)
]) ])
result = e._process_discover_versions(payload) result = e._process_discover_versions(payload)
@ -6843,14 +6843,14 @@ class TestKmipEngine(testtools.TestCase):
self.assertIsNotNone(result.protocol_versions) self.assertIsNotNone(result.protocol_versions)
self.assertEqual(1, len(result.protocol_versions)) self.assertEqual(1, len(result.protocol_versions))
self.assertEqual( self.assertEqual(
contents.ProtocolVersion.create(1, 0), contents.ProtocolVersion(1, 0),
result.protocol_versions[0] result.protocol_versions[0]
) )
# Test disjoint request. # Test disjoint request.
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
payload = payloads.DiscoverVersionsRequestPayload([ payload = payloads.DiscoverVersionsRequestPayload([
contents.ProtocolVersion.create(0, 1) contents.ProtocolVersion(0, 1)
]) ])
result = e._process_discover_versions(payload) result = e._process_discover_versions(payload)

View File

@ -35,14 +35,14 @@ class TestAttributePolicy(testtools.TestCase):
""" """
Test that an AttributePolicy can be built without any errors. Test that an AttributePolicy can be built without any errors.
""" """
policy.AttributePolicy(contents.ProtocolVersion.create(1, 0)) policy.AttributePolicy(contents.ProtocolVersion(1, 0))
def test_is_attribute_supported(self): def test_is_attribute_supported(self):
""" """
Test that is_attribute_supported returns the expected results in all Test that is_attribute_supported returns the expected results in all
cases. cases.
""" """
rules = policy.AttributePolicy(contents.ProtocolVersion.create(1, 0)) rules = policy.AttributePolicy(contents.ProtocolVersion(1, 0))
attribute_a = 'Unique Identifier' attribute_a = 'Unique Identifier'
attribute_b = 'Certificate Length' attribute_b = 'Certificate Length'
attribute_c = 'invalid' attribute_c = 'invalid'
@ -61,7 +61,7 @@ class TestAttributePolicy(testtools.TestCase):
Test that is_attribute_deprecated returns the expected results in all Test that is_attribute_deprecated returns the expected results in all
cases. cases.
""" """
rules = policy.AttributePolicy(contents.ProtocolVersion.create(1, 0)) rules = policy.AttributePolicy(contents.ProtocolVersion(1, 0))
attribute_a = 'Name' attribute_a = 'Name'
attribute_b = 'Certificate Subject' attribute_b = 'Certificate Subject'
@ -71,7 +71,7 @@ class TestAttributePolicy(testtools.TestCase):
result = rules.is_attribute_deprecated(attribute_b) result = rules.is_attribute_deprecated(attribute_b)
self.assertFalse(result) self.assertFalse(result)
rules = policy.AttributePolicy(contents.ProtocolVersion.create(1, 1)) rules = policy.AttributePolicy(contents.ProtocolVersion(1, 1))
result = rules.is_attribute_deprecated(attribute_b) result = rules.is_attribute_deprecated(attribute_b)
self.assertTrue(result) self.assertTrue(result)
@ -81,7 +81,7 @@ class TestAttributePolicy(testtools.TestCase):
Test that is_attribute_applicable_to_object_type returns the Test that is_attribute_applicable_to_object_type returns the
expected results in all cases. expected results in all cases.
""" """
rules = policy.AttributePolicy(contents.ProtocolVersion.create(1, 0)) rules = policy.AttributePolicy(contents.ProtocolVersion(1, 0))
attribute = 'Cryptographic Algorithm' attribute = 'Cryptographic Algorithm'
object_type_a = enums.ObjectType.SYMMETRIC_KEY object_type_a = enums.ObjectType.SYMMETRIC_KEY
object_type_b = enums.ObjectType.OPAQUE_DATA object_type_b = enums.ObjectType.OPAQUE_DATA
@ -103,7 +103,7 @@ class TestAttributePolicy(testtools.TestCase):
Test that is_attribute_multivalued returns the expected results in Test that is_attribute_multivalued returns the expected results in
all cases. all cases.
""" """
rules = policy.AttributePolicy(contents.ProtocolVersion.create(1, 0)) rules = policy.AttributePolicy(contents.ProtocolVersion(1, 0))
attribute_a = 'Object Type' attribute_a = 'Object Type'
attribute_b = 'Link' attribute_b = 'Link'
@ -118,7 +118,7 @@ class TestAttributePolicy(testtools.TestCase):
Test that get_all_attribute_names returns a complete list of the Test that get_all_attribute_names returns a complete list of the
names of all spec-defined attributes. names of all spec-defined attributes.
""" """
rules = policy.AttributePolicy(contents.ProtocolVersion.create(1, 0)) rules = policy.AttributePolicy(contents.ProtocolVersion(1, 0))
attribute_names = [ attribute_names = [
'Unique Identifier', 'Unique Identifier',
'Name', 'Name',

View File

@ -345,7 +345,7 @@ class TestKmipSession(testtools.TestCase):
) )
batch_items = [batch_item] batch_items = [batch_item]
header = messages.ResponseHeader( header = messages.ResponseHeader(
protocol_version=contents.ProtocolVersion.create(1, 0), protocol_version=contents.ProtocolVersion(1, 0),
time_stamp=contents.TimeStamp(int(time.time())), time_stamp=contents.TimeStamp(int(time.time())),
batch_count=contents.BatchCount(len(batch_items)) batch_count=contents.BatchCount(len(batch_items))
) )

View File

@ -385,7 +385,7 @@ class TestKMIPClient(TestCase):
self.assertEqual(protocol_versions, observed, msg) self.assertEqual(protocol_versions, observed, msg)
def test_build_discover_versions_batch_item_with_input(self): def test_build_discover_versions_batch_item_with_input(self):
protocol_versions = [ProtocolVersion.create(1, 0)] protocol_versions = [ProtocolVersion(1, 0)]
self._test_build_discover_versions_batch_item(protocol_versions) self._test_build_discover_versions_batch_item(protocol_versions)
def test_build_discover_versions_batch_item_no_input(self): def test_build_discover_versions_batch_item_no_input(self):
@ -612,7 +612,7 @@ class TestKMIPClient(TestCase):
self.assertEqual(protocol_versions, result.protocol_versions, msg) self.assertEqual(protocol_versions, result.protocol_versions, msg)
def test_process_discover_versions_batch_item_with_results(self): def test_process_discover_versions_batch_item_with_results(self):
protocol_versions = [ProtocolVersion.create(1, 0)] protocol_versions = [ProtocolVersion(1, 0)]
self._test_process_discover_versions_batch_item(protocol_versions) self._test_process_discover_versions_batch_item(protocol_versions)
def test_process_discover_versions_batch_item_no_results(self): def test_process_discover_versions_batch_item_no_results(self):