Merge pull request #2911 from cm-iwata/fix_2910_list_thing_principal

Added existence check of target thing to IoT ListThingPrincipals
This commit is contained in:
Bert Blommers 2020-04-21 07:47:12 +01:00 committed by GitHub
commit 12ac1cbae2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -7,10 +7,10 @@ class IoTClientError(JsonRESTError):
class ResourceNotFoundException(IoTClientError):
def __init__(self):
def __init__(self, msg=None):
self.code = 404
super(ResourceNotFoundException, self).__init__(
"ResourceNotFoundException", "The specified resource does not exist"
"ResourceNotFoundException", msg or "The specified resource does not exist"
)

View File

@ -805,6 +805,14 @@ class IoTBackend(BaseBackend):
return thing_names
def list_thing_principals(self, thing_name):
things = [_ for _ in self.things.values() if _.thing_name == thing_name]
if len(things) == 0:
raise ResourceNotFoundException(
"Failed to list principals for thing %s because the thing does not exist in your account"
% thing_name
)
principals = [
k[0] for k, v in self.principal_things.items() if k[1] == thing_name
]

View File

@ -728,6 +728,14 @@ def test_principal_thing():
res = client.list_thing_principals(thingName=thing_name)
res.should.have.key("principals").which.should.have.length_of(0)
with assert_raises(ClientError) as e:
client.list_thing_principals(thingName="xxx")
e.exception.response["Error"]["Code"].should.equal("ResourceNotFoundException")
e.exception.response["Error"]["Message"].should.equal(
"Failed to list principals for thing xxx because the thing does not exist in your account"
)
@mock_iot
def test_delete_principal_thing():