From c098455d2ea7205ad24744fe4bedd6d2c673934a Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Robles Date: Mon, 2 Nov 2015 10:26:54 +0200 Subject: [PATCH] Allow null values for secret names This secret allows null values for names in secrets as discussed a couple of cycles back. Since the code for the mocked client in the functional tests actually filters out null values, it is currently not possible to write a functional test for this in this functional test code base. However, it will be written as part of the python-barbicanclient functional test suite. Change-Id: I68330d1d1b13e1bbb6436ca4f6684a76af3babd3 Related-bug: #1425667 Related-bug: #1376469 --- barbican/common/validators.py | 3 ++- barbican/tests/common/test_validators.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/barbican/common/validators.py b/barbican/common/validators.py index f33be4d8c..4361b43f2 100644 --- a/barbican/common/validators.py +++ b/barbican/common/validators.py @@ -180,7 +180,7 @@ class NewSecretValidator(ValidatorBase): self.schema = { "type": "object", "properties": { - "name": {"type": "string", "maxLength": 255}, + "name": {"type": ["string", "null"], "maxLength": 255}, "algorithm": {"type": "string", "maxLength": 255}, "mode": {"type": "string", "maxLength": 255}, "bit_length": { @@ -242,6 +242,7 @@ class NewSecretValidator(ValidatorBase): payload, schema_name) json_data['payload'] = payload elif 'payload_content_type' in json_data: + # parent_schema would be populated if it comes from an order. self._assert_validity(parent_schema is not None, schema_name, u._("payload must be provided when " "payload_content_type is specified"), diff --git a/barbican/tests/common/test_validators.py b/barbican/tests/common/test_validators.py index e24c49d64..e7879921b 100644 --- a/barbican/tests/common/test_validators.py +++ b/barbican/tests/common/test_validators.py @@ -146,6 +146,10 @@ class WhenTestingSecretValidator(utils.BaseTestCase): self.secret_req['name'] = ' ' self.validator.validate(self.secret_req) + def test_should_validate_null_name(self): + self.secret_req['name'] = None + self.validator.validate(self.secret_req) + def test_should_validate_no_payload(self): del self.secret_req['payload'] del self.secret_req['payload_content_type']