Skip to content

Commit

Permalink
fix(aws-certificatemanager) export dns-validated-certificate (#1985)
Browse files Browse the repository at this point in the history
  • Loading branch information
spg authored and Elad Ben-Israel committed Mar 12, 2019
1 parent dfefb58 commit aa0042b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-certificatemanager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ zone `example.com` that provides authoritative records for the domain.

```ts
import { HostedZoneProvider } from '@aws-cdk/aws-route53';
import { DNSValidatedCertificate } from '@aws-cdk/aws-certificatemanager';
import { DnsValidatedCertificate } from '@aws-cdk/aws-certificatemanager';

const hostedZone = new HostedZoneProvider(this, {
domainName: 'example.com',
privateZone: false
}).findAndImport(this, 'ExampleDotCom');

const certificate = new DNSValidatedCertificate(this, 'TestCertificate', {
const certificate = new DnsValidatedCertificate(this, 'TestCertificate', {
domainName: 'test.example.com',
hostedZone: hostedZone
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import cdk = require('@aws-cdk/cdk');
import path = require('path');
import { CertificateImportProps, CertificateProps, ICertificate } from './certificate';

export interface DNSValidatedCertificateProps extends CertificateProps {
export interface DnsValidatedCertificateProps extends CertificateProps {
/**
* Route 53 Hosted Zone used to perform DNS validation of the request. The zone
* must be authoritative for the domain name specified in the Certificate Request.
Expand All @@ -18,13 +18,13 @@ export interface DNSValidatedCertificateProps extends CertificateProps {
* A certificate managed by AWS Certificate Manager. Will be automatically
* validated using DNS validation against the specified Route 53 hosted zone.
*/
export class DNSValidatedCertificate extends cdk.Construct implements ICertificate {
export class DnsValidatedCertificate extends cdk.Construct implements ICertificate {
public readonly certificateArn: string;
private normalizedZoneName: string;
private hostedZoneId: string;
private domainName: string;

constructor(scope: cdk.Construct, id: string, props: DNSValidatedCertificateProps) {
constructor(scope: cdk.Construct, id: string, props: DnsValidatedCertificateProps) {
super(scope, id);

this.domainName = props.domainName;
Expand Down Expand Up @@ -80,7 +80,7 @@ export class DNSValidatedCertificate extends cdk.Construct implements ICertifica
};
}

public validate(): string[] {
protected validate(): string[] {
const errors: string[] = [];
// Ensure the zone name is a parent zone of the certificate domain name
if (!this.domainName.endsWith('.' + this.normalizedZoneName)) {
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-certificatemanager/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './certificate';
export * from './dns-validated-certificate';

// AWS::CertificateManager CloudFormation Resources:
export * from './certificatemanager.generated';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, haveResource } from '@aws-cdk/assert';
import { PublicHostedZone } from '@aws-cdk/aws-route53';
import { Stack } from '@aws-cdk/cdk';
import { Test } from 'nodeunit';
import { DNSValidatedCertificate } from '../lib/dns-validated-certificate';
import { DnsValidatedCertificate } from '../lib/dns-validated-certificate';

export = {
'creates CloudFormation Custom Resource'(test: Test) {
Expand All @@ -12,7 +12,7 @@ export = {
zoneName: 'example.com'
});

const cert = new DNSValidatedCertificate(stack, 'Certificate', {
new DnsValidatedCertificate(stack, 'Certificate', {
domainName: 'test.example.com',
hostedZone: exampleDotComZone,
});
Expand Down Expand Up @@ -77,9 +77,6 @@ export = {
}
}));

const errors = cert.validate();
test.equal(errors.length, 0);

test.done();
},

Expand All @@ -90,7 +87,7 @@ export = {
zoneName: 'hello.com'
});

const refProps = new DNSValidatedCertificate(stack, 'Cert', {
const refProps = new DnsValidatedCertificate(stack, 'Cert', {
domainName: 'hello.com',
hostedZone: helloDotComZone,
}).export();
Expand All @@ -106,14 +103,13 @@ export = {
zoneName: 'hello.com'
});

const cert = new DNSValidatedCertificate(stack, 'Cert', {
new DnsValidatedCertificate(stack, 'Cert', {
domainName: 'example.com',
hostedZone: helloDotComZone,
});

const errors = cert.validate();
test.equal(errors.length, 1);

// a bit of a hack: expect(stack) will trigger validation.
test.throws(() => expect(stack), /DNS zone hello.com is not authoritative for certificate domain name example.com/);
test.done();
},
};

0 comments on commit aa0042b

Please sign in to comment.