From c36371e235a92a45dbd49aefca3cbd8d24c76fdd Mon Sep 17 00:00:00 2001 From: Guilherme Martins Crocetti Date: Sun, 2 Feb 2020 12:47:54 -0300 Subject: [PATCH 1/8] Add failing test for database creation with iam --- tests/test_rds2/test_rds2.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py index 9a5a73678..6dc42fbc1 100644 --- a/tests/test_rds2/test_rds2.py +++ b/tests/test_rds2/test_rds2.py @@ -1689,3 +1689,18 @@ def test_create_parameter_group_with_tags(): ResourceName="arn:aws:rds:us-west-2:1234567890:pg:test" ) result["TagList"].should.equal([{"Value": "bar", "Key": "foo"}]) + + +@mock_rds2 +def test_create_database_with_iam_authentication(): + conn = boto3.client("rds", region_name="us-west-2") + + database = conn.create_db_instance( + DBInstanceIdentifier="rds", + DBInstanceClass="db.t1.micro", + Engine="postgres", + EnableIAMDatabaseAuthentication=True, + ) + + db_instance = database["DBInstance"] + db_instance["IAMDatabaseAuthenticationEnabled"].should.equal(True) From ec66670315750fd1c60df369c8e12a05f0b4498e Mon Sep 17 00:00:00 2001 From: Guilherme Martins Crocetti Date: Sun, 2 Feb 2020 12:50:46 -0300 Subject: [PATCH 2/8] Add enable_iam_database_authentication parameter in RDS2Response --- moto/rds2/responses.py | 1 + 1 file changed, 1 insertion(+) diff --git a/moto/rds2/responses.py b/moto/rds2/responses.py index 7c815b2d5..cdffdd40e 100644 --- a/moto/rds2/responses.py +++ b/moto/rds2/responses.py @@ -27,6 +27,7 @@ class RDS2Response(BaseResponse): "db_subnet_group_name": self._get_param("DBSubnetGroupName"), "engine": self._get_param("Engine"), "engine_version": self._get_param("EngineVersion"), + "enable_iam_database_authentication": self._get_bool_param("EnableIAMDatabaseAuthentication"), "license_model": self._get_param("LicenseModel"), "iops": self._get_int_param("Iops"), "kms_key_id": self._get_param("KmsKeyId"), From dfd21187e143e58f412d03a48c05529600f99cbe Mon Sep 17 00:00:00 2001 From: Guilherme Martins Crocetti Date: Sun, 2 Feb 2020 12:55:05 -0300 Subject: [PATCH 3/8] Change iam_database_authentication_enabled to enabled_iam_database_authentication in accordance with aws docs --- moto/rds2/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/moto/rds2/models.py b/moto/rds2/models.py index d2aa24a20..68acef0a0 100644 --- a/moto/rds2/models.py +++ b/moto/rds2/models.py @@ -130,7 +130,9 @@ class Database(BaseModel): if not self.option_group_name and self.engine in self.default_option_groups: self.option_group_name = self.default_option_groups[self.engine] self.character_set_name = kwargs.get("character_set_name", None) - self.iam_database_authentication_enabled = False + self.enable_iam_database_authentication = kwargs.get( + "enable_iam_database_authentication", False + ) self.dbi_resource_id = "db-M5ENSHXFPU6XHZ4G4ZEI5QIO2U" self.tags = kwargs.get("tags", []) From 51e787fba6b24af7284394126ae5f1ced96a4f35 Mon Sep 17 00:00:00 2001 From: Guilherme Martins Crocetti Date: Sun, 2 Feb 2020 12:57:16 -0300 Subject: [PATCH 4/8] Add enable_iam_database_authentication in 'to_xml' method --- moto/rds2/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moto/rds2/models.py b/moto/rds2/models.py index 68acef0a0..aae708cdd 100644 --- a/moto/rds2/models.py +++ b/moto/rds2/models.py @@ -216,7 +216,7 @@ class Database(BaseModel): {{ database.source_db_identifier }} {% endif %} {{ database.engine }} - {{database.iam_database_authentication_enabled }} + {{database.enable_iam_database_authentication|lower }} {{ database.license_model }} {{ database.engine_version }} From eb0687eeaa3fb544c139c0dec43b2b6b828dbaa8 Mon Sep 17 00:00:00 2001 From: Guilherme Martins Crocetti Date: Sun, 2 Feb 2020 13:08:13 -0300 Subject: [PATCH 5/8] Add failing test for EnableIAMDatabaseAuthentication snapshot --- tests/test_rds2/test_rds2.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py index 6dc42fbc1..7e6670e9b 100644 --- a/tests/test_rds2/test_rds2.py +++ b/tests/test_rds2/test_rds2.py @@ -1704,3 +1704,21 @@ def test_create_database_with_iam_authentication(): db_instance = database["DBInstance"] db_instance["IAMDatabaseAuthenticationEnabled"].should.equal(True) + + +@mock_rds2 +def test_create_db_snapshot_with_iam_authentication(): + conn = boto3.client("rds", region_name="us-west-2") + + conn.create_db_instance( + DBInstanceIdentifier="rds", + DBInstanceClass="db.t1.micro", + Engine="postgres", + EnableIAMDatabaseAuthentication=True, + ) + + snapshot = conn.create_db_snapshot( + DBInstanceIdentifier="rds", DBSnapshotIdentifier="snapshot" + ).get("DBSnapshot") + + snapshot.get("IAMDatabaseAuthenticationEnabled").should.equal(True) From 06e4cafd20aa5140d89a952a97b35c8833999194 Mon Sep 17 00:00:00 2001 From: Guilherme Martins Crocetti Date: Sun, 2 Feb 2020 13:10:04 -0300 Subject: [PATCH 6/8] Add enable_iam_database_authentication variable into snapshot 'to_xml' --- moto/rds2/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moto/rds2/models.py b/moto/rds2/models.py index aae708cdd..963af1c63 100644 --- a/moto/rds2/models.py +++ b/moto/rds2/models.py @@ -544,7 +544,7 @@ class Snapshot(BaseModel): {{ database.kms_key_id }} {{ snapshot.snapshot_arn }} - false + {{ database.enable_iam_database_authentication|lower }} """ ) return template.render(snapshot=self, database=self.database) From 9f8388e4021f082b2199d698d56da941c551dd53 Mon Sep 17 00:00:00 2001 From: Guilherme Martins Crocetti Date: Sun, 2 Feb 2020 13:19:50 -0300 Subject: [PATCH 7/8] Change test name in favor of abbreviation --- tests/test_rds2/test_rds2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py index 7e6670e9b..e93ff43e9 100644 --- a/tests/test_rds2/test_rds2.py +++ b/tests/test_rds2/test_rds2.py @@ -1692,7 +1692,7 @@ def test_create_parameter_group_with_tags(): @mock_rds2 -def test_create_database_with_iam_authentication(): +def test_create_db_with_iam_authentication(): conn = boto3.client("rds", region_name="us-west-2") database = conn.create_db_instance( From f0509276d892258aeee1f869b4ac1f08120feaa5 Mon Sep 17 00:00:00 2001 From: Guilherme Martins Crocetti Date: Sun, 2 Feb 2020 13:46:01 -0300 Subject: [PATCH 8/8] Apply black in responses.py --- moto/rds2/responses.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/moto/rds2/responses.py b/moto/rds2/responses.py index cdffdd40e..b63e9f8b8 100644 --- a/moto/rds2/responses.py +++ b/moto/rds2/responses.py @@ -27,7 +27,9 @@ class RDS2Response(BaseResponse): "db_subnet_group_name": self._get_param("DBSubnetGroupName"), "engine": self._get_param("Engine"), "engine_version": self._get_param("EngineVersion"), - "enable_iam_database_authentication": self._get_bool_param("EnableIAMDatabaseAuthentication"), + "enable_iam_database_authentication": self._get_bool_param( + "EnableIAMDatabaseAuthentication" + ), "license_model": self._get_param("LicenseModel"), "iops": self._get_int_param("Iops"), "kms_key_id": self._get_param("KmsKeyId"),