From 651d5a06463e4a76ae5b40e5486ae59bc58bfebf Mon Sep 17 00:00:00 2001 From: spg Date: Wed, 19 Jun 2019 15:13:01 -0700 Subject: [PATCH] fix(sns) UrlSubscription: don't validate protocol --- packages/@aws-cdk/aws-sns-subscriptions/lib/url.ts | 7 ++----- packages/@aws-cdk/aws-sns-subscriptions/test/subs.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/@aws-cdk/aws-sns-subscriptions/lib/url.ts b/packages/@aws-cdk/aws-sns-subscriptions/lib/url.ts index 91046dc4e2407..a361b864a018d 100644 --- a/packages/@aws-cdk/aws-sns-subscriptions/lib/url.ts +++ b/packages/@aws-cdk/aws-sns-subscriptions/lib/url.ts @@ -23,17 +23,14 @@ export interface UrlSubscriptionProps { * @see https://docs.aws.amazon.com/sns/latest/dg/sns-http-https-endpoint-as-subscriber.html */ export class UrlSubscription implements sns.ITopicSubscription { - constructor(private readonly url: string, private readonly props: UrlSubscriptionProps = {}) { - if (!url.startsWith('http://') && !url.startsWith('https://')) { - throw new Error('URL must start with either http:// or https://'); - } + constructor(private readonly url: string, private readonly protocol: sns.SubscriptionProtocol, private readonly props: UrlSubscriptionProps = {}) { } public bind(scope: Construct, topic: sns.ITopic): void { new sns.Subscription(scope, this.url, { topic, endpoint: this.url, - protocol: this.url.startsWith('https:') ? sns.SubscriptionProtocol.Https : sns.SubscriptionProtocol.Http, + protocol: this.protocol, rawMessageDelivery: this.props.rawMessageDelivery, }); } diff --git a/packages/@aws-cdk/aws-sns-subscriptions/test/subs.test.ts b/packages/@aws-cdk/aws-sns-subscriptions/test/subs.test.ts index fd9ae3f04c05e..70dbacc1cacc1 100644 --- a/packages/@aws-cdk/aws-sns-subscriptions/test/subs.test.ts +++ b/packages/@aws-cdk/aws-sns-subscriptions/test/subs.test.ts @@ -19,7 +19,7 @@ beforeEach(() => { }); test('url subscription', () => { - topic.addSubscription(new subs.UrlSubscription('https://foobar.com/')); + topic.addSubscription(new subs.UrlSubscription('https://foobar.com/', sns.SubscriptionProtocol.Https)); expect(stack).toMatchTemplate({ "Resources": { @@ -45,7 +45,7 @@ test('url subscription', () => { }); test('url subscription (with raw delivery)', () => { - topic.addSubscription(new subs.UrlSubscription('https://foobar.com/', { + topic.addSubscription(new subs.UrlSubscription('https://foobar.com/', sns.SubscriptionProtocol.Https, { rawMessageDelivery: true }));