-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `iam.Policy` class expected to be provided (concrete) `Role` instances, making it unusable when all that is available is an `IRole` (as should be in most situations). This changes the API to accept an `IRole` instead, increasing the usability.
- Loading branch information
1 parent
2b491d4
commit 9128390
Showing
6 changed files
with
89 additions
and
6 deletions.
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
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
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
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
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,59 @@ | ||
import { expect, haveResource, haveResourceLike } from '@aws-cdk/assert'; | ||
import cdk = require('@aws-cdk/cdk'); | ||
import nodeunit = require('nodeunit'); | ||
import iam = require('../lib'); | ||
|
||
export = nodeunit.testCase({ | ||
'creates no resource when unused'(test: nodeunit.Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
// WHEN | ||
new iam.LazyRole(stack, 'Lazy', { | ||
assumedBy: new iam.ServicePrincipal('test.amazonaws.com') | ||
}); | ||
|
||
// THEN | ||
expect(stack).notTo(haveResourceLike('AWS::IAM::Role')); | ||
test.done(); | ||
}, | ||
|
||
'creates the resource when a property is read'(test: nodeunit.Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
// WHEN | ||
const roleArn = new iam.LazyRole(stack, 'Lazy', { | ||
assumedBy: new iam.ServicePrincipal('test.amazonaws.com') | ||
}).roleArn; | ||
|
||
// THEN | ||
test.notEqual(roleArn, null); | ||
expect(stack).to(haveResource('AWS::IAM::Role', { | ||
AssumeRolePolicyDocument: { | ||
Version: '2012-10-17', | ||
Statement: [{ | ||
Action: 'sts:AssumeRole', | ||
Effect: 'Allow', | ||
Principal: { Service: 'test.amazonaws.com' } | ||
}] | ||
} | ||
})); | ||
test.done(); | ||
}, | ||
|
||
'returns appropriate roleName'(test: nodeunit.Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
// WHEN | ||
const role = new iam.LazyRole(stack, 'Lazy', { | ||
assumedBy: new iam.ServicePrincipal('test.amazonaws.com') | ||
}); | ||
|
||
// THEN | ||
test.deepEqual(stack.node.resolve(role.roleName), | ||
{ Ref: 'Lazy399F7F48'}); | ||
test.done(); | ||
} | ||
}); |
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