Skip to content

Commit

Permalink
Merge branch 'master' into DaWyz/events-targets-codebuild-dlq
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Mar 9, 2021
2 parents e4c031d + e08213f commit 43cea79
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 154 deletions.
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-cloudfront/lib/cache-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ export class CacheHeaderBehavior {
if (headers.length === 0) {
throw new Error('At least one header to allow must be provided');
}
if (headers.length > 10) {
throw new Error(`Maximum allowed headers in Cache Policy is 10; got ${headers.length}.`);
}
return new CacheHeaderBehavior('whitelist', headers);
}

Expand Down
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-cloudfront/test/cache-policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ describe('CachePolicy', () => {
expect(() => new CachePolicy(stack, 'CachePolicy6', { cachePolicyName: 'My_Policy' })).not.toThrow();
});

test('throws if more than 10 CacheHeaderBehavior headers are being passed', () => {
const errorMessage = /Maximum allowed headers in Cache Policy is 10; got (.*?)/;
expect(() => new CachePolicy(stack, 'CachePolicy1', {
headerBehavior: CacheHeaderBehavior.allowList('Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'sed', 'do', 'eiusmod'),
})).toThrow(errorMessage);

expect(() => new CachePolicy(stack, 'CachePolicy2', {
headerBehavior: CacheHeaderBehavior.allowList('Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'sed', 'do'),
})).not.toThrow();
});

test('does not throw if cachePolicyName is a token', () => {
expect(() => new CachePolicy(stack, 'CachePolicy', {
cachePolicyName: Aws.STACK_NAME,
Expand Down
6 changes: 5 additions & 1 deletion packages/@aws-cdk/aws-events/lib/event-bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ class ImportedEventBus extends EventBusBase {
public readonly eventBusPolicy: string;
public readonly eventSourceName?: string;
constructor(scope: Construct, id: string, attrs: EventBusAttributes) {
super(scope, id);
const arnParts = Stack.of(scope).parseArn(attrs.eventBusArn);
super(scope, id, {
account: arnParts.account,
region: arnParts.region,
});

this.eventBusArn = attrs.eventBusArn;
this.eventBusName = attrs.eventBusName;
Expand Down
61 changes: 60 additions & 1 deletion packages/@aws-cdk/aws-events/test/test.event-bus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, haveResource } from '@aws-cdk/assert';
import * as iam from '@aws-cdk/aws-iam';
import { Aws, CfnResource, Stack } from '@aws-cdk/core';
import { Aws, CfnResource, Stack, Arn } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { EventBus } from '../lib';

Expand Down Expand Up @@ -55,6 +55,65 @@ export = {
test.done();
},

'imported event bus'(test: Test) {
const stack = new Stack();

const eventBus = new EventBus(stack, 'Bus');

const importEB = EventBus.fromEventBusArn(stack, 'ImportBus', eventBus.eventBusArn);

// WHEN
new CfnResource(stack, 'Res', {
type: 'Test::Resource',
properties: {
EventBusArn1: eventBus.eventBusArn,
EventBusArn2: importEB.eventBusArn,
},
});

expect(stack).to(haveResource('Test::Resource', {
EventBusArn1: { 'Fn::GetAtt': ['BusEA82B648', 'Arn'] },
EventBusArn2: { 'Fn::GetAtt': ['BusEA82B648', 'Arn'] },
}));

test.done();
},

'same account imported event bus has right resource env'(test: Test) {
const stack = new Stack();

const eventBus = new EventBus(stack, 'Bus');

const importEB = EventBus.fromEventBusArn(stack, 'ImportBus', eventBus.eventBusArn);

// WHEN
test.deepEqual(stack.resolve(importEB.env.account), { 'Fn::Select': [4, { 'Fn::Split': [':', { 'Fn::GetAtt': ['BusEA82B648', 'Arn'] }] }] });
test.deepEqual(stack.resolve(importEB.env.region), { 'Fn::Select': [3, { 'Fn::Split': [':', { 'Fn::GetAtt': ['BusEA82B648', 'Arn'] }] }] });

test.done();
},

'cross account imported event bus has right resource env'(test: Test) {
const stack = new Stack();

const arnParts = {
resource: 'bus',
service: 'events',
account: 'myAccount',
region: 'us-west-1',
};

const arn = Arn.format(arnParts, stack);

const importEB = EventBus.fromEventBusArn(stack, 'ImportBus', arn);

// WHEN
test.deepEqual(importEB.env.account, arnParts.account);
test.deepEqual(importEB.env.region, arnParts.region);

test.done();
},

'can get bus name'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down
Loading

0 comments on commit 43cea79

Please sign in to comment.