/
IAMRole_UT.scala
41 lines (33 loc) · 1.24 KB
/
IAMRole_UT.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.monsanto.arch.cloudformation.model.resource
import com.monsanto.arch.cloudformation.model.ResourceRef
import org.scalatest.{FunSpec, Matchers}
import spray.json.{JsObject, JsString, _}
class IAMRole_UT extends FunSpec with Matchers {
describe("AWS::IAM::Role") {
it("should handle both AWS Managed and Customer policies into valid json") {
val customerPolicy = `AWS::IAM::ManagedPolicy`("customer-policy", PolicyDocument(Seq()))
val awsPolicy = AWSManagedPolicy("AdministratorAccess")
val fakePolicyDoc = PolicyDocument(Seq(
PolicyStatement(
"Allow",
Some(DefinedPrincipal(Map("Service" -> Seq("config.amazonaws.com")))),
Seq("sts:AssumeRole")
)
))
val expectedJson = JsObject(
"name" -> JsString("role"),
"AssumeRolePolicyDocument" -> fakePolicyDoc.toJson,
"ManagedPolicyArns" -> JsArray(
JsObject("Ref" -> JsString("customer-policy")),
JsString("arn:aws:iam::aws:policy/AdministratorAccess")
)
)
val role = `AWS::IAM::Role`(
"role",
fakePolicyDoc,
ManagedPolicyArns = Some(Seq(ResourceRef(customerPolicy), awsPolicy))
)
role.toJson should be(expectedJson)
}
}
}