diff --git a/moto/swf/exceptions.py b/moto/swf/exceptions.py index bfbb96020..f58c0360a 100644 --- a/moto/swf/exceptions.py +++ b/moto/swf/exceptions.py @@ -30,3 +30,13 @@ class SWFDomainDeprecatedFault(SWFClientError): super(SWFDomainDeprecatedFault, self).__init__( domain_name, "com.amazonaws.swf.base.model#DomainDeprecatedFault") + + +class SWFSerializationException(JSONResponseError): + def __init__(self): + message = "class java.lang.Foo can not be converted to an String (not a real SWF exception)" + __type = "com.amazonaws.swf.base.model#SerializationException" + super(SWFSerializationException, self).__init__( + 400, "Bad Request", + body={"Message": message, "__type": __type} + ) diff --git a/moto/swf/models.py b/moto/swf/models.py index 61ed508aa..880e00b3d 100644 --- a/moto/swf/models.py +++ b/moto/swf/models.py @@ -7,6 +7,7 @@ from .exceptions import ( SWFUnknownResourceFault, SWFDomainAlreadyExistsFault, SWFDomainDeprecatedFault, + SWFSerializationException, ) @@ -40,12 +41,21 @@ class SWFBackend(BaseBackend): return matching[0] return None + def _check_string(self, parameter): + if not isinstance(parameter, basestring): + raise SWFSerializationException() + def list_domains(self, status): + self._check_string(status) return [domain for domain in self.domains if domain.status == status] def register_domain(self, name, workflow_execution_retention_period_in_days, description=None): + self._check_string(name) + self._check_string(workflow_execution_retention_period_in_days) + if description: + self._check_string(description) if self._get_domain(name, ignore_empty=True): raise SWFDomainAlreadyExistsFault(name) domain = Domain(name, workflow_execution_retention_period_in_days, @@ -53,12 +63,14 @@ class SWFBackend(BaseBackend): self.domains.append(domain) def deprecate_domain(self, name): + self._check_string(name) domain = self._get_domain(name) if domain.status == "DEPRECATED": raise SWFDomainDeprecatedFault(name) domain.status = "DEPRECATED" def describe_domain(self, name): + self._check_string(name) return self._get_domain(name) diff --git a/tests/test_swf/test_swf.py b/tests/test_swf/test_swf.py index 4f0617fc1..1a43e4cd0 100644 --- a/tests/test_swf/test_swf.py +++ b/tests/test_swf/test_swf.py @@ -7,6 +7,7 @@ from moto.swf.exceptions import ( SWFUnknownResourceFault, SWFDomainAlreadyExistsFault, SWFDomainDeprecatedFault, + SWFSerializationException, ) @@ -15,7 +16,7 @@ from moto.swf.exceptions import ( @mock_swf def test_register_domain(): conn = boto.connect_swf("the_key", "the_secret") - conn.register_domain("test-domain", 60, description="A test domain") + conn.register_domain("test-domain", "60", description="A test domain") all_domains = conn.list_domains("REGISTERED") domain = all_domains["domainInfos"][0] @@ -27,10 +28,10 @@ def test_register_domain(): @mock_swf def test_register_already_existing_domain(): conn = boto.connect_swf("the_key", "the_secret") - conn.register_domain("test-domain", 60, description="A test domain") + conn.register_domain("test-domain", "60", description="A test domain") with assert_raises(SWFDomainAlreadyExistsFault) as err: - conn.register_domain("test-domain", 60, description="A test domain") + conn.register_domain("test-domain", "60", description="A test domain") ex = err.exception ex.status.should.equal(400) @@ -40,12 +41,27 @@ def test_register_already_existing_domain(): "message": "test-domain" }) +@mock_swf +def test_register_with_wrong_parameter_type(): + conn = boto.connect_swf("the_key", "the_secret") + + with assert_raises(SWFSerializationException) as err: + conn.register_domain("test-domain", 60, description="A test domain") + + ex = err.exception + ex.status.should.equal(400) + ex.error_code.should.equal("SerializationException") + ex.body.should.equal({ + "__type": "com.amazonaws.swf.base.model#SerializationException", + "Message": "class java.lang.Foo can not be converted to an String (not a real SWF exception)" + }) + # DeprecateDomain endpoint @mock_swf def test_deprecate_domain(): conn = boto.connect_swf("the_key", "the_secret") - conn.register_domain("test-domain", 60, description="A test domain") + conn.register_domain("test-domain", "60", description="A test domain") conn.deprecate_domain("test-domain") all_domains = conn.list_domains("DEPRECATED") @@ -56,7 +72,7 @@ def test_deprecate_domain(): @mock_swf def test_deprecate_already_deprecated_domain(): conn = boto.connect_swf("the_key", "the_secret") - conn.register_domain("test-domain", 60, description="A test domain") + conn.register_domain("test-domain", "60", description="A test domain") conn.deprecate_domain("test-domain") with assert_raises(SWFDomainDeprecatedFault) as err: @@ -89,7 +105,7 @@ def test_deprecate_non_existent_domain(): @mock_swf def test_describe_domain(): conn = boto.connect_swf("the_key", "the_secret") - conn.register_domain("test-domain", 60, description="A test domain") + conn.register_domain("test-domain", "60", description="A test domain") domain = conn.describe_domain("test-domain") domain["configuration"]["workflowExecutionRetentionPeriodInDays"].should.equal("60")