diff --git a/moto/rds2/models.py b/moto/rds2/models.py index 4651f68d4..a5169f04f 100644 --- a/moto/rds2/models.py +++ b/moto/rds2/models.py @@ -151,8 +151,8 @@ class Database(CloudFormationModel): @property def db_instance_arn(self): - return "arn:aws:rds:{0}:1234567890:db:{1}".format( - self.region, self.db_instance_identifier + return "arn:aws:rds:{0}:{1}:db:{2}".format( + self.region, ACCOUNT_ID, self.db_instance_identifier ) @property @@ -551,8 +551,8 @@ class Snapshot(BaseModel): @property def snapshot_arn(self): - return "arn:aws:rds:{0}:1234567890:snapshot:{1}".format( - self.database.region, self.snapshot_id + return "arn:aws:rds:{0}:{1}:snapshot:{2}".format( + self.database.region, ACCOUNT_ID, self.snapshot_id ) def to_xml(self): @@ -614,7 +614,7 @@ class SecurityGroup(CloudFormationModel): self.ip_ranges = [] self.ec2_security_groups = [] self.tags = tags - self.owner_id = "1234567890" + self.owner_id = ACCOUNT_ID self.vpc_id = None def to_xml(self): diff --git a/moto/secretsmanager/utils.py b/moto/secretsmanager/utils.py index ab0f584f0..2ddf50dd5 100644 --- a/moto/secretsmanager/utils.py +++ b/moto/secretsmanager/utils.py @@ -5,6 +5,8 @@ import string import six import re +from moto.core import ACCOUNT_ID + def random_password( password_length, @@ -68,8 +70,8 @@ def random_password( def secret_arn(region, secret_id): id_string = "".join(random.choice(string.ascii_letters) for _ in range(5)) - return "arn:aws:secretsmanager:{0}:1234567890:secret:{1}-{2}".format( - region, secret_id, id_string + return "arn:aws:secretsmanager:{0}:{1}:secret:{2}-{3}".format( + region, ACCOUNT_ID, secret_id, id_string ) diff --git a/moto/ssm/utils.py b/moto/ssm/utils.py index 3f3762d1c..ad27c2175 100644 --- a/moto/ssm/utils.py +++ b/moto/ssm/utils.py @@ -1,4 +1,4 @@ -ACCOUNT_ID = "1234567890" +from moto.core import ACCOUNT_ID def parameter_arn(region, parameter_name): diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py index 393a46163..047f3d32f 100644 --- a/tests/test_rds2/test_rds2.py +++ b/tests/test_rds2/test_rds2.py @@ -31,7 +31,7 @@ def test_create_database(): db_instance["MasterUsername"].should.equal("root") db_instance["DBSecurityGroups"][0]["DBSecurityGroupName"].should.equal("my_sg") db_instance["DBInstanceArn"].should.equal( - "arn:aws:rds:us-west-2:1234567890:db:db-master-1" + "arn:aws:rds:us-west-2:{}:db:db-master-1".format(ACCOUNT_ID) ) db_instance["DBInstanceStatus"].should.equal("available") db_instance["DBName"].should.equal("staging-postgres") @@ -312,7 +312,7 @@ def test_get_databases(): list(instances["DBInstances"]).should.have.length_of(1) instances["DBInstances"][0]["DBInstanceIdentifier"].should.equal("db-master-1") instances["DBInstances"][0]["DBInstanceArn"].should.equal( - "arn:aws:rds:us-west-2:1234567890:db:db-master-1" + "arn:aws:rds:us-west-2:{}:db:db-master-1".format(ACCOUNT_ID) ) diff --git a/tests/test_secretsmanager/test_secretsmanager.py b/tests/test_secretsmanager/test_secretsmanager.py index a60742942..ac699b4bf 100644 --- a/tests/test_secretsmanager/test_secretsmanager.py +++ b/tests/test_secretsmanager/test_secretsmanager.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import boto3 from moto import mock_secretsmanager, mock_lambda, settings +from moto.core import ACCOUNT_ID from botocore.exceptions import ClientError import string import pytz @@ -30,11 +31,15 @@ def test_get_secret_value(): def test_get_secret_value_by_arn(): conn = boto3.client("secretsmanager", region_name="us-west-2") + name = "java-util-test-password" secret_value = "test_get_secret_value_by_arn" - result = conn.create_secret( - Name="java-util-test-password", SecretString=secret_value + result = conn.create_secret(Name=name, SecretString=secret_value) + arn = result["ARN"] + arn.should.match( + "^arn:aws:secretsmanager:us-west-2:{}:secret:{}".format(ACCOUNT_ID, name) ) - result = conn.get_secret_value(SecretId=result["ARN"]) + + result = conn.get_secret_value(SecretId=arn) assert result["SecretString"] == secret_value diff --git a/tests/test_ssm/test_ssm_boto3.py b/tests/test_ssm/test_ssm_boto3.py index b1dc63709..e63c18c80 100644 --- a/tests/test_ssm/test_ssm_boto3.py +++ b/tests/test_ssm/test_ssm_boto3.py @@ -12,6 +12,7 @@ from botocore.exceptions import ClientError import pytest from moto import mock_ec2, mock_ssm +from moto.core import ACCOUNT_ID from moto.ssm.models import PARAMETER_VERSION_LIMIT, PARAMETER_HISTORY_MAX_RESULTS from tests import EXAMPLE_AMI_ID @@ -120,8 +121,8 @@ def test_get_parameters_by_path(): {p["ARN"] for p in response["Parameters"]}.should.equal( set( [ - "arn:aws:ssm:us-east-1:1234567890:parameter/foo", - "arn:aws:ssm:us-east-1:1234567890:parameter/baz", + "arn:aws:ssm:us-east-1:{}:parameter/foo".format(ACCOUNT_ID), + "arn:aws:ssm:us-east-1:{}:parameter/baz".format(ACCOUNT_ID), ] ) ) @@ -247,7 +248,7 @@ def test_put_parameter(name): response["Parameters"][0]["Version"].should.equal(1) response["Parameters"][0]["LastModifiedDate"].should.be.a(datetime.datetime) response["Parameters"][0]["ARN"].should.equal( - "arn:aws:ssm:us-east-1:1234567890:parameter/{}".format(name) + "arn:aws:ssm:us-east-1:{}:parameter/{}".format(ACCOUNT_ID, name) ) initial_modification_date = response["Parameters"][0]["LastModifiedDate"] @@ -274,7 +275,7 @@ def test_put_parameter(name): initial_modification_date ) response["Parameters"][0]["ARN"].should.equal( - "arn:aws:ssm:us-east-1:1234567890:parameter/{}".format(name) + "arn:aws:ssm:us-east-1:{}:parameter/{}".format(ACCOUNT_ID, name) ) response = client.put_parameter( @@ -295,7 +296,7 @@ def test_put_parameter(name): initial_modification_date ) response["Parameters"][0]["ARN"].should.equal( - "arn:aws:ssm:us-east-1:1234567890:parameter/{}".format(name) + "arn:aws:ssm:us-east-1:{}:parameter/{}".format(ACCOUNT_ID, name) ) @@ -408,7 +409,7 @@ def test_get_parameter(): response["Parameter"]["Type"].should.equal("String") response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime) response["Parameter"]["ARN"].should.equal( - "arn:aws:ssm:us-east-1:1234567890:parameter/test" + "arn:aws:ssm:us-east-1:{}:parameter/test".format(ACCOUNT_ID) ) @@ -434,7 +435,7 @@ def test_get_parameter_with_version_and_labels(): response["Parameter"]["Type"].should.equal("String") response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime) response["Parameter"]["ARN"].should.equal( - "arn:aws:ssm:us-east-1:1234567890:parameter/test-1" + "arn:aws:ssm:us-east-1:{}:parameter/test-1".format(ACCOUNT_ID) ) response = client.get_parameter(Name="test-2:1", WithDecryption=False) @@ -443,7 +444,7 @@ def test_get_parameter_with_version_and_labels(): response["Parameter"]["Type"].should.equal("String") response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime) response["Parameter"]["ARN"].should.equal( - "arn:aws:ssm:us-east-1:1234567890:parameter/test-2" + "arn:aws:ssm:us-east-1:{}:parameter/test-2".format(ACCOUNT_ID) ) response = client.get_parameter(Name="test-2:test-label", WithDecryption=False) @@ -452,7 +453,7 @@ def test_get_parameter_with_version_and_labels(): response["Parameter"]["Type"].should.equal("String") response["Parameter"]["LastModifiedDate"].should.be.a(datetime.datetime) response["Parameter"]["ARN"].should.equal( - "arn:aws:ssm:us-east-1:1234567890:parameter/test-2" + "arn:aws:ssm:us-east-1:{}:parameter/test-2".format(ACCOUNT_ID) ) with pytest.raises(ClientError) as ex: