Skip to content

Commit

Permalink
IOT - Use regular AccountId for Thing ARN (#4678)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers authored Dec 12, 2021
1 parent 3d10536 commit bc6f6c1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
4 changes: 2 additions & 2 deletions moto/iot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .utils import PAGINATION_MODEL

from boto3 import Session
from moto.core import BaseBackend, BaseModel
from moto.core import ACCOUNT_ID, BaseBackend, BaseModel
from moto.utilities.utils import random_string
from moto.utilities.paginator import paginate
from .exceptions import (
Expand All @@ -31,7 +31,7 @@ def __init__(self, thing_name, thing_type, attributes, region_name):
self.thing_name = thing_name
self.thing_type = thing_type
self.attributes = attributes
self.arn = "arn:aws:iot:%s:1:thing/%s" % (self.region_name, thing_name)
self.arn = f"arn:aws:iot:{region_name}:{ACCOUNT_ID}:thing/{thing_name}"
self.version = 1
# TODO: we need to handle "version"?

Expand Down
45 changes: 27 additions & 18 deletions tests/test_iot/test_iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import boto3

from moto import mock_iot, mock_cognitoidentity
from moto.core import ACCOUNT_ID
from botocore.exceptions import ClientError
import pytest

Expand Down Expand Up @@ -395,46 +396,48 @@ def test_list_things_with_next_token():
things.should.have.key("nextToken")
things.should.have.key("things").which.should.have.length_of(50)
things["things"][0]["thingName"].should.equal("1")
things["things"][0]["thingArn"].should.equal("arn:aws:iot:ap-northeast-1:1:thing/1")
things["things"][0]["thingArn"].should.equal(
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/1"
)
things["things"][-1]["thingName"].should.equal("50")
things["things"][-1]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/50"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/50"
)

things = client.list_things(nextToken=things["nextToken"])
things.should.have.key("nextToken")
things.should.have.key("things").which.should.have.length_of(50)
things["things"][0]["thingName"].should.equal("51")
things["things"][0]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/51"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/51"
)
things["things"][-1]["thingName"].should.equal("100")
things["things"][-1]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/100"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/100"
)

things = client.list_things(nextToken=things["nextToken"])
things.should.have.key("nextToken")
things.should.have.key("things").which.should.have.length_of(50)
things["things"][0]["thingName"].should.equal("101")
things["things"][0]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/101"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/101"
)
things["things"][-1]["thingName"].should.equal("150")
things["things"][-1]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/150"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/150"
)

things = client.list_things(nextToken=things["nextToken"])
things.should_not.have.key("nextToken")
things.should.have.key("things").which.should.have.length_of(50)
things["things"][0]["thingName"].should.equal("151")
things["things"][0]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/151"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/151"
)
things["things"][-1]["thingName"].should.equal("200")
things["things"][-1]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/200"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/200"
)


Expand Down Expand Up @@ -468,10 +471,12 @@ def test_list_things_with_attribute_and_thing_type_filter_and_next_token():
things.should.have.key("nextToken")
things.should.have.key("things").which.should.have.length_of(50)
things["things"][0]["thingName"].should.equal("2")
things["things"][0]["thingArn"].should.equal("arn:aws:iot:ap-northeast-1:1:thing/2")
things["things"][0]["thingArn"].should.equal(
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/2"
)
things["things"][-1]["thingName"].should.equal("100")
things["things"][-1]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/100"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/100"
)
all(item["thingTypeName"] == thing_type_name for item in things["things"])

Expand All @@ -482,11 +487,11 @@ def test_list_things_with_attribute_and_thing_type_filter_and_next_token():
things.should.have.key("things").which.should.have.length_of(50)
things["things"][0]["thingName"].should.equal("102")
things["things"][0]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/102"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/102"
)
things["things"][-1]["thingName"].should.equal("200")
things["things"][-1]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/200"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/200"
)
all(item["thingTypeName"] == thing_type_name for item in things["things"])

Expand All @@ -495,10 +500,12 @@ def test_list_things_with_attribute_and_thing_type_filter_and_next_token():
things.should.have.key("nextToken")
things.should.have.key("things").which.should.have.length_of(50)
things["things"][0]["thingName"].should.equal("3")
things["things"][0]["thingArn"].should.equal("arn:aws:iot:ap-northeast-1:1:thing/3")
things["things"][0]["thingArn"].should.equal(
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/3"
)
things["things"][-1]["thingName"].should.equal("150")
things["things"][-1]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/150"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/150"
)
all(item["attributes"] == {"foo": "bar"} for item in things["things"])

Expand All @@ -509,11 +516,11 @@ def test_list_things_with_attribute_and_thing_type_filter_and_next_token():
things.should.have.key("things").which.should.have.length_of(16)
things["things"][0]["thingName"].should.equal("153")
things["things"][0]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/153"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/153"
)
things["things"][-1]["thingName"].should.equal("198")
things["things"][-1]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/198"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/198"
)
all(item["attributes"] == {"foo": "bar"} for item in things["things"])

Expand All @@ -524,10 +531,12 @@ def test_list_things_with_attribute_and_thing_type_filter_and_next_token():
things.should_not.have.key("nextToken")
things.should.have.key("things").which.should.have.length_of(33)
things["things"][0]["thingName"].should.equal("6")
things["things"][0]["thingArn"].should.equal("arn:aws:iot:ap-northeast-1:1:thing/6")
things["things"][0]["thingArn"].should.equal(
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/6"
)
things["things"][-1]["thingName"].should.equal("198")
things["things"][-1]["thingArn"].should.equal(
"arn:aws:iot:ap-northeast-1:1:thing/198"
f"arn:aws:iot:ap-northeast-1:{ACCOUNT_ID}:thing/198"
)
all(
item["attributes"] == {"foo": "bar"}
Expand Down

0 comments on commit bc6f6c1

Please sign in to comment.