Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding support for built-in AWS policies
- Loading branch information
T.J. Corrigan
committed
Aug 25, 2016
1 parent
3a81731
commit a6b2826
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/test/scala/com/monsanto/arch/cloudformation/model/resource/IAMRole_UT.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} | ||
} | ||
} |