|
| 1 | +import '@aws-cdk/assert-internal/jest'; |
| 2 | +import { App, Stack } from '@aws-cdk/core'; |
| 3 | +import { AccessKey, AccessKeyStatus, User } from '../lib'; |
| 4 | + |
| 5 | +describe('IAM Access keys', () => { |
| 6 | + test('user name is identifed via reference', () => { |
| 7 | + // GIVEN |
| 8 | + const app = new App(); |
| 9 | + const stack = new Stack(app, 'MyStack'); |
| 10 | + const user = new User(stack, 'MyUser'); |
| 11 | + |
| 12 | + // WHEN |
| 13 | + new AccessKey(stack, 'MyAccessKey', { user }); |
| 14 | + |
| 15 | + // THEN |
| 16 | + expect(stack).toMatchTemplate({ |
| 17 | + Resources: { |
| 18 | + MyUserDC45028B: { |
| 19 | + Type: 'AWS::IAM::User', |
| 20 | + }, |
| 21 | + MyAccessKeyF0FFBE2E: { |
| 22 | + Type: 'AWS::IAM::AccessKey', |
| 23 | + Properties: { |
| 24 | + UserName: { Ref: 'MyUserDC45028B' }, |
| 25 | + }, |
| 26 | + }, |
| 27 | + }, |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + test('active status is specified with correct capitalization', () => { |
| 32 | + // GIVEN |
| 33 | + const app = new App(); |
| 34 | + const stack = new Stack(app, 'MyStack'); |
| 35 | + const user = new User(stack, 'MyUser'); |
| 36 | + |
| 37 | + // WHEN |
| 38 | + new AccessKey(stack, 'MyAccessKey', { user, status: AccessKeyStatus.ACTIVE }); |
| 39 | + |
| 40 | + // THEN |
| 41 | + expect(stack).toHaveResourceLike('AWS::IAM::AccessKey', { Status: 'Active' }); |
| 42 | + }); |
| 43 | + |
| 44 | + test('inactive status is specified with correct capitalization', () => { |
| 45 | + // GIVEN |
| 46 | + const app = new App(); |
| 47 | + const stack = new Stack(app, 'MyStack'); |
| 48 | + const user = new User(stack, 'MyUser'); |
| 49 | + |
| 50 | + // WHEN |
| 51 | + new AccessKey(stack, 'MyAccessKey', { |
| 52 | + user, |
| 53 | + status: AccessKeyStatus.INACTIVE, |
| 54 | + }); |
| 55 | + |
| 56 | + // THEN |
| 57 | + expect(stack).toHaveResourceLike('AWS::IAM::AccessKey', { |
| 58 | + Status: 'Inactive', |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + test('access key secret ', () => { |
| 63 | + // GIVEN |
| 64 | + const app = new App(); |
| 65 | + const stack = new Stack(app, 'MyStack'); |
| 66 | + const user = new User(stack, 'MyUser'); |
| 67 | + |
| 68 | + // WHEN |
| 69 | + const accessKey = new AccessKey(stack, 'MyAccessKey', { |
| 70 | + user, |
| 71 | + }); |
| 72 | + |
| 73 | + // THEN |
| 74 | + expect(stack.resolve(accessKey.secretAccessKey)).toStrictEqual({ |
| 75 | + 'Fn::GetAtt': ['MyAccessKeyF0FFBE2E', 'SecretAccessKey'], |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | +}); |
0 commit comments