Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,783 changes: 4,775 additions & 8 deletions packages/@aws-cdk/aws-iam/package-lock.json

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-iam/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"cdk-build-tools": "file:../../../tools/cdk-build-tools",
"cdk-integ-tools": "file:../../../tools/cdk-integ-tools",
"cfn2ts": "file:../../../tools/cfn2ts",
"jest": "^24.8.0",
"pkglint": "file:../../../tools/pkglint"
},
"dependencies": {
Expand All @@ -78,6 +79,17 @@
"@aws-cdk/core": "^1.6.1",
"@aws-cdk/region-info": "^1.6.1"
},
"jest": {
"moduleFileExtensions": [
"js"
],
"coverageThreshold": {
"global": {
"branches": 70,
"statements": 70
}
}
},
"homepage": "https://github.com/aws/aws-cdk",
"engines": {
"node": ">= 8.10.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect, SynthUtils } from '@aws-cdk/assert';
import { SynthUtils } from '@aws-cdk/assert';
import '@aws-cdk/assert/jest';
import cdk = require('@aws-cdk/core');
import { Test } from 'nodeunit';
import iam = require('../lib');

export = {
'automatic exports are created when attributes are referneced across stacks'(test: Test) {
describe('automatic cross-stack references', () => {
test('automatic exports are created when attributes are referneced across stacks', () => {
// GIVEN
const app = new cdk.App();
const stackWithUser = new cdk.Stack(app, 'stack1');
Expand All @@ -25,7 +25,7 @@ export = {
//

// THEN
expect(stackWithUser).toMatch({
expect(stackWithUser).toMatchTemplate({
Resources: {
User00B015A1: {
Type: "AWS::IAM::User",
Expand All @@ -35,7 +35,7 @@ export = {
}
}
});
expect(stackWithGroup).toMatch({
expect(stackWithGroup).toMatchTemplate({
Outputs: {
ExportsOutputRefGroupC77FDACD8CF7DD5B: {
Value: { Ref: "GroupC77FDACD" },
Expand All @@ -48,10 +48,9 @@ export = {
}
}
});
test.done();
},
});

'cannot reference tokens across apps'(test: Test) {
test('cannot reference tokens across apps', () => {
// GIVEN
const stack1 = new cdk.Stack();
const stack2 = new cdk.Stack();
Expand All @@ -60,7 +59,6 @@ export = {
group.addUser(user);

// THEN
test.throws(() => SynthUtils.synthesize(stack1), /Cannot reference across apps/);
test.done();
},
};
expect(() => SynthUtils.synthesize(stack1)).toThrow(/Cannot reference across apps/);
});
});
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// tests for the L1 escape hatches (overrides). those are in the IAM module
// because we want to verify them end-to-end, as a complement to the unit
// tests in the @aws-cdk/core module
import { expect } from '@aws-cdk/assert';
import '@aws-cdk/assert/jest';
import { Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import iam = require('../lib');

// tslint:disable:object-literal-key-quotes

export = {
'addPropertyOverride should allow overriding supported properties'(test: Test) {
describe('IAM escape hatches', () => {
test('addPropertyOverride should allow overriding supported properties', () => {
const stack = new Stack();
const user = new iam.User(stack, 'user', {
userName: 'MyUserName',
Expand All @@ -18,7 +17,7 @@ export = {
const cfn = user.node.findChild('Resource') as iam.CfnUser;
cfn.addPropertyOverride('UserName', 'OverriddenUserName');

expect(stack).toMatch({
expect(stack).toMatchTemplate({
"Resources": {
"user2C2B57AE": {
"Type": "AWS::IAM::User",
Expand All @@ -28,9 +27,9 @@ export = {
}
}
});
test.done();
},
'addPropertyOverrides should allow specifying arbitrary properties'(test: Test) {
});

test('addPropertyOverrides should allow specifying arbitrary properties', () => {
// GIVEN
const stack = new Stack();
const user = new iam.User(stack, 'user', { userName: 'MyUserName' });
Expand All @@ -40,7 +39,7 @@ export = {
cfn.addPropertyOverride('Hello.World', 'Boom');

// THEN
expect(stack).toMatch({
expect(stack).toMatchTemplate({
"Resources": {
"user2C2B57AE": {
"Type": "AWS::IAM::User",
Expand All @@ -53,10 +52,9 @@ export = {
}
}
});
});

test.done();
},
'addOverride should allow overriding properties'(test: Test) {
test('addOverride should allow overriding properties', () => {
// GIVEN
const stack = new Stack();
const user = new iam.User(stack, 'user', { userName: 'MyUserName' });
Expand All @@ -71,7 +69,7 @@ export = {
cfn.addOverride('UpdatePolicy.UseOnlineResharding.Type', 'None');

// THEN
expect(stack).toMatch({
expect(stack).toMatchTemplate({
"Resources": {
"user2C2B57AE": {
"Type": "AWS::IAM::User",
Expand All @@ -92,7 +90,5 @@ export = {
}
}
});

test.done();
}
};
});
});
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-iam/test/grant.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import '@aws-cdk/assert/jest';
import { Stack } from '@aws-cdk/core';
import { Grant } from '../lib';
import iam = require('../lib');

describe('IAM grant', () => {
test('Grant.drop() returns a no-op grant', () => {
const stack = new Stack();
const user = new iam.User(stack, 'poo');
const grant = Grant.drop(user, 'dropping me');

expect(grant.success).toBeFalsy();
expect(grant.principalStatement).toBeUndefined();
expect(grant.resourceStatement).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { expect, haveResource } from '@aws-cdk/assert';
import '@aws-cdk/assert/jest';
import { App, Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { Group, ManagedPolicy, User } from '../lib';

export = {
'default group'(test: Test) {
describe('IAM groups', () => {
test('default group', () => {
const app = new App();
const stack = new Stack(app, 'MyStack');
new Group(stack, 'MyGroup');

expect(stack).toMatch({
expect(stack).toMatchTemplate({
Resources: { MyGroupCBA54B1B: { Type: 'AWS::IAM::Group' } }
});
});

test.done();
},

'users can be added to the group either via `user.addToGroup` or `group.addUser`'(test: Test) {
test('users can be added to the group either via `user.addToGroup` or `group.addUser`', () => {
const app = new App();
const stack = new Stack(app, 'MyStack');
const group = new Group(stack, 'MyGroup');
Expand All @@ -25,18 +22,17 @@ export = {
user1.addToGroup(group);
group.addUser(user2);

expect(stack).toMatch({ Resources:
expect(stack).toMatchTemplate({ Resources:
{ MyGroupCBA54B1B: { Type: 'AWS::IAM::Group' },
User1E278A736:
{ Type: 'AWS::IAM::User',
Properties: { Groups: [ { Ref: 'MyGroupCBA54B1B' } ] } },
User21F1486D1:
{ Type: 'AWS::IAM::User',
Properties: { Groups: [ { Ref: 'MyGroupCBA54B1B' } ] } } } });
test.done();
},
});

'create with managed policy'(test: Test) {
test('create with managed policy', () => {
// GIVEN
const stack = new Stack();

Expand All @@ -46,12 +42,10 @@ export = {
});

// THEN
expect(stack).to(haveResource('AWS::IAM::Group', {
expect(stack).toHaveResource('AWS::IAM::Group', {
ManagedPolicyArns: [
{ "Fn::Join": [ "", [ "arn:", { Ref: "AWS::Partition" }, ":iam::aws:policy/asdf" ] ] }
]
}));

test.done();
}
};
});
});
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { expect, haveResource, haveResourceLike } from '@aws-cdk/assert';
import '@aws-cdk/assert/jest';
import cdk = require('@aws-cdk/core');
import nodeunit = require('nodeunit');
import iam = require('../lib');

export = nodeunit.testCase({
'creates no resource when unused'(test: nodeunit.Test) {
describe('IAM lazy role', () => {
test('creates no resource when unused', () => {
// GIVEN
const stack = new cdk.Stack();

Expand All @@ -14,11 +13,10 @@ export = nodeunit.testCase({
});

// THEN
expect(stack).notTo(haveResourceLike('AWS::IAM::Role'));
test.done();
},
expect(stack).not.toHaveResource('AWS::IAM::Role');
});

'creates the resource when a property is read'(test: nodeunit.Test) {
test('creates the resource when a property is read', () => {
// GIVEN
const stack = new cdk.Stack();

Expand All @@ -28,8 +26,8 @@ export = nodeunit.testCase({
}).roleArn;

// THEN
test.notEqual(roleArn, null);
expect(stack).to(haveResource('AWS::IAM::Role', {
expect(roleArn).not.toBeNull();
expect(stack).toHaveResource('AWS::IAM::Role', {
AssumeRolePolicyDocument: {
Version: '2012-10-17',
Statement: [{
Expand All @@ -38,11 +36,10 @@ export = nodeunit.testCase({
Principal: { Service: 'test.service' }
}]
}
}));
test.done();
},
});
});

'returns appropriate roleName'(test: nodeunit.Test) {
test('returns appropriate roleName', () => {
// GIVEN
const stack = new cdk.Stack();

Expand All @@ -52,8 +49,7 @@ export = nodeunit.testCase({
});

// THEN
test.deepEqual(stack.resolve(role.roleName),
{ Ref: 'Lazy399F7F48'});
test.done();
}
expect(stack.resolve(role.roleName))
.toEqual({ Ref: 'Lazy399F7F48' });
});
});
Loading