|
| 1 | +import { PublicHostedZone } from '@aws-cdk/aws-route53'; |
| 2 | +import { App, Stack } from '@aws-cdk/core'; |
1 | 3 | import { Test } from 'nodeunit';
|
2 |
| -import { apexDomain } from '../lib/util'; |
| 4 | +import { Certificate, DnsValidatedCertificate } from '../lib'; |
| 5 | +import { apexDomain, getCertificateRegion, isDnsValidatedCertificate } from '../lib/util'; |
3 | 6 |
|
4 | 7 | export = {
|
5 |
| - 'apex domain returns right domain'(test: Test) { |
6 |
| - test.equals('domain.com', apexDomain('domain.com')); |
7 |
| - test.equals('domain.com', apexDomain('test.domain.com')); |
8 |
| - test.done(); |
| 8 | + 'apex domain': { |
| 9 | + 'returns right domain'(test: Test) { |
| 10 | + test.equals('domain.com', apexDomain('domain.com')); |
| 11 | + test.equals('domain.com', apexDomain('test.domain.com')); |
| 12 | + test.done(); |
| 13 | + }, |
| 14 | + |
| 15 | + 'understands eTLDs'(test: Test) { |
| 16 | + test.equals('domain.co.uk', apexDomain('test.domain.co.uk')); |
| 17 | + test.done(); |
| 18 | + }, |
| 19 | + }, |
| 20 | + 'isDnsValidatedCertificate': { |
| 21 | + 'new DnsValidatedCertificate is a DnsValidatedCertificate'(test: Test) { |
| 22 | + const stack = new Stack(); |
| 23 | + |
| 24 | + const hostedZone = new PublicHostedZone(stack, 'ExampleDotCom', { |
| 25 | + zoneName: 'example.com' |
| 26 | + }); |
| 27 | + const cert = new DnsValidatedCertificate(stack, 'Certificate', { |
| 28 | + domainName: 'test.example.com', |
| 29 | + hostedZone |
| 30 | + }); |
| 31 | + |
| 32 | + test.ok(isDnsValidatedCertificate(cert)); |
| 33 | + test.done(); |
| 34 | + }, |
| 35 | + 'new Certificate is not a DnsValidatedCertificate'(test: Test) { |
| 36 | + const stack = new Stack(); |
| 37 | + |
| 38 | + const cert = new Certificate(stack, 'Certificate', { |
| 39 | + domainName: 'test.example.com' |
| 40 | + }); |
| 41 | + |
| 42 | + test.ok(!isDnsValidatedCertificate(cert)); |
| 43 | + test.done(); |
| 44 | + }, |
| 45 | + 'fromCertificateArn is not a DnsValidatedCertificate'(test: Test) { |
| 46 | + const stack = new Stack(); |
| 47 | + |
| 48 | + const cert = Certificate.fromCertificateArn(stack, 'Certificate', 'cert-arn'); |
| 49 | + |
| 50 | + test.ok(!isDnsValidatedCertificate(cert)); |
| 51 | + test.done(); |
| 52 | + }, |
9 | 53 | },
|
| 54 | + 'getCertificateRegion': { |
| 55 | + 'from stack'(test: Test) { |
| 56 | + // GIVEN |
| 57 | + const app = new App(); |
| 58 | + const stack = new Stack(app, 'RegionStack', {env: {region: 'eu-west-1'}}); |
10 | 59 |
|
11 |
| - 'apex domain understands eTLDs'(test: Test) { |
12 |
| - test.equals('domain.co.uk', apexDomain('test.domain.co.uk')); |
13 |
| - test.done(); |
14 |
| - } |
| 60 | + const certificate = new Certificate(stack, 'TestCertificate', { |
| 61 | + domainName: 'www.example.com', |
| 62 | + }); |
| 63 | + |
| 64 | + test.equals(getCertificateRegion(certificate), 'eu-west-1'); |
| 65 | + test.done(); |
| 66 | + }, |
| 67 | + 'from DnsValidatedCertificate region'(test: Test) { |
| 68 | + // GIVEN |
| 69 | + const app = new App(); |
| 70 | + const stack = new Stack(app, 'RegionStack', {env: {region: 'eu-west-1'}}); |
| 71 | + const hostedZone = new PublicHostedZone(stack, 'ExampleDotCom', { |
| 72 | + zoneName: 'example.com' |
| 73 | + }); |
| 74 | + |
| 75 | + const certificate = new DnsValidatedCertificate(stack, 'TestCertificate', { |
| 76 | + domainName: 'www.example.com', |
| 77 | + hostedZone, |
| 78 | + region: 'eu-west-3' |
| 79 | + }); |
| 80 | + |
| 81 | + test.equals(getCertificateRegion(certificate), 'eu-west-3'); |
| 82 | + test.done(); |
| 83 | + }, |
| 84 | + 'fromCertificateArn'(test: Test) { |
| 85 | + // GIVEN |
| 86 | + const app = new App(); |
| 87 | + const stack = new Stack(app, 'RegionStack', {env: {region: 'eu-west-1'}}); |
| 88 | + |
| 89 | + const certificate = Certificate.fromCertificateArn( |
| 90 | + stack, 'TestCertificate', 'arn:aws:acm:us-east-2:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d' |
| 91 | + ); |
| 92 | + |
| 93 | + test.equals(getCertificateRegion(certificate), 'us-east-2'); |
| 94 | + test.done(); |
| 95 | + }, |
| 96 | + 'region agnostic stack'(test: Test) { |
| 97 | + // GIVEN |
| 98 | + const stack = new Stack(); |
| 99 | + |
| 100 | + const certificate = new Certificate(stack, 'TestCertificate', { |
| 101 | + domainName: 'www.example.com', |
| 102 | + }); |
| 103 | + |
| 104 | + test.equals(getCertificateRegion(certificate), '${Token[AWS::Region.4]}'); |
| 105 | + test.done(); |
| 106 | + }, |
| 107 | + }, |
15 | 108 | };
|
0 commit comments