Merge pull request #2515 from Sytten/fix/delete_iot_principal_thing

Detach principal from thing when it is deleted
This commit is contained in:
Mike Grima 2019-10-24 12:23:09 -07:00 committed by GitHub
commit 6b67002a42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -331,6 +331,12 @@ class IoTBackend(BaseBackend):
# can raise ResourceNotFoundError # can raise ResourceNotFoundError
thing = self.describe_thing(thing_name) thing = self.describe_thing(thing_name)
# detach all principals
for k in list(self.principal_things.keys()):
if k[1] == thing_name:
del self.principal_things[k]
del self.things[thing.arn] del self.things[thing.arn]
def delete_thing_type(self, thing_type_name): def delete_thing_type(self, thing_type_name):

View File

@ -519,6 +519,25 @@ def test_principal_thing():
res.should.have.key('principals').which.should.have.length_of(0) res.should.have.key('principals').which.should.have.length_of(0)
@mock_iot
def test_delete_principal_thing():
client = boto3.client('iot', region_name='ap-northeast-1')
thing_name = 'my-thing'
thing = client.create_thing(thingName=thing_name)
cert = client.create_keys_and_certificate(setAsActive=True)
cert_arn = cert['certificateArn']
cert_id = cert['certificateId']
client.attach_thing_principal(thingName=thing_name, principal=cert_arn)
client.delete_thing(thingName=thing_name)
res = client.list_principal_things(principal=cert_arn)
res.should.have.key('things').which.should.have.length_of(0)
client.update_certificate(certificateId=cert_id, newStatus="INACTIVE")
client.delete_certificate(certificateId=cert_id)
@mock_iot @mock_iot
def test_thing_groups(): def test_thing_groups():
client = boto3.client('iot', region_name='ap-northeast-1') client = boto3.client('iot', region_name='ap-northeast-1')