2
0
mirror of https://github.com/openkmip/pykmip synced 2026-01-04 09:33:37 +00:00

Block Attributes encoding and decoding on non KMIP 2.0 calls

This change adds a check to the read and write methods of the new
Attributes object that raises a new VersionNotSupported exception
if KMIP 2.0 is not the version used for encoding and decoding.
The Attributes object is not defined for older versions of KMIP
and therefore cannot be correctly encoded or decoded in those use
cases.
This commit is contained in:
Peter Hamilton
2019-02-25 14:38:03 -05:00
committed by Peter Hamilton
parent 24f30d46b2
commit 54f3688a14
3 changed files with 66 additions and 0 deletions

View File

@@ -400,6 +400,24 @@ class TestAttributes(TestCase):
self.assertIsInstance(attr_2, primitives.Integer)
self.assertEqual(128, attr_2.value)
def test_read_version_not_supported(self):
"""
Test that a VersionNotSupported error is raised when an unsupported
KMIP version is provided while reading in an Attributes structure from
a data stream. The Attributes structure is only supported in KMIP 2.0+.
"""
attrs = objects.Attributes()
args = (self.full_encoding, )
kwargs = {"kmip_version": enums.KMIPVersion.KMIP_1_2}
self.assertRaisesRegex(
exceptions.VersionNotSupported,
"KMIP 1.2 does not support the Attributes object.",
attrs.read,
*args,
**kwargs
)
def test_write(self):
"""
Test that an Attributes structure can be correctly written to a data
@@ -489,6 +507,30 @@ class TestAttributes(TestCase):
self.assertEqual(len(self.alt_encoding), len(stream))
self.assertEqual(str(self.alt_encoding), str(stream))
def test_write_version_not_supported(self):
"""
Test that a VersionNotSupported error is raised when an unsupported
KMIP version is provided while writing an Attributes structure to a
data stream. The Attributes structure is only supported in KMIP 2.0+.
"""
attrs = objects.Attributes(attributes=[
primitives.TextString(
"default",
tag=enums.Tags.OPERATION_POLICY_NAME
)
])
stream = utils.BytearrayStream()
args = (stream, )
kwargs = {"kmip_version": enums.KMIPVersion.KMIP_1_1}
self.assertRaisesRegex(
exceptions.VersionNotSupported,
"KMIP 1.1 does not support the Attributes object.",
attrs.write,
*args,
**kwargs
)
def test_repr(self):
"""
Test that repr can be applied to an Attributes structure.