-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(apigateway): base path url cannot contain upper case characters (#…
…11799) We're migrating an existing API Gateway application to CDK and have [hit this error](https://github.com/aws/aws-cdk/blob/2f0a598720f7ecf4dfea7dde97182940fcbe8d9a/packages/%40aws-cdk/aws-apigateway/lib/base-path-mapping.ts#L52), because our base paths include capitalised characters. This PR resolves that issue and I've included some basics tests for the `BasePathMapping` resource. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
2 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import '@aws-cdk/assert/jest'; | ||
import * as acm from '@aws-cdk/aws-certificatemanager'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as apigw from '../lib'; | ||
|
||
describe('BasePathMapping', () => { | ||
test('default setup', () => { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
const api = new apigw.RestApi(stack, 'MyApi'); | ||
api.root.addMethod('GET'); // api must have atleast one method. | ||
const domain = new apigw.DomainName(stack, 'MyDomain', { | ||
domainName: 'example.com', | ||
certificate: acm.Certificate.fromCertificateArn(stack, 'cert', 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d'), | ||
endpointType: apigw.EndpointType.REGIONAL, | ||
}); | ||
|
||
// WHEN | ||
new apigw.BasePathMapping(stack, 'MyBasePath', { | ||
restApi: api, | ||
domainName: domain, | ||
}); | ||
|
||
// THEN | ||
expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { | ||
DomainName: { Ref: 'MyDomainE4943FBC' }, | ||
RestApiId: { Ref: 'MyApi49610EDF' }, | ||
}); | ||
}); | ||
|
||
test('specify basePath property', () => { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
const api = new apigw.RestApi(stack, 'MyApi'); | ||
api.root.addMethod('GET'); // api must have atleast one method. | ||
const domain = new apigw.DomainName(stack, 'MyDomain', { | ||
domainName: 'example.com', | ||
certificate: acm.Certificate.fromCertificateArn(stack, 'cert', 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d'), | ||
endpointType: apigw.EndpointType.REGIONAL, | ||
}); | ||
|
||
// WHEN | ||
new apigw.BasePathMapping(stack, 'MyBasePath', { | ||
restApi: api, | ||
domainName: domain, | ||
basePath: 'My_B45E-P4th', | ||
}); | ||
|
||
// THEN | ||
expect(stack).toHaveResourceLike('AWS::ApiGateway::BasePathMapping', { | ||
BasePath: 'My_B45E-P4th', | ||
}); | ||
}); | ||
|
||
test('throw error for invalid basePath property', () => { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
const api = new apigw.RestApi(stack, 'MyApi'); | ||
api.root.addMethod('GET'); // api must have atleast one method. | ||
const domain = new apigw.DomainName(stack, 'MyDomain', { | ||
domainName: 'example.com', | ||
certificate: acm.Certificate.fromCertificateArn(stack, 'cert', 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d'), | ||
endpointType: apigw.EndpointType.REGIONAL, | ||
}); | ||
|
||
// WHEN | ||
const invalidBasePath = '/invalid-/base-path'; | ||
|
||
// THEN | ||
expect(() => { | ||
new apigw.BasePathMapping(stack, 'MyBasePath', { | ||
restApi: api, | ||
domainName: domain, | ||
basePath: invalidBasePath, | ||
}); | ||
}).toThrowError(/base path may only contain/); | ||
}); | ||
|
||
test('specify stage property', () => { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
const api = new apigw.RestApi(stack, 'MyApi'); | ||
api.root.addMethod('GET'); // api must have atleast one method. | ||
const domain = new apigw.DomainName(stack, 'MyDomain', { | ||
domainName: 'example.com', | ||
certificate: acm.Certificate.fromCertificateArn(stack, 'cert', 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d'), | ||
endpointType: apigw.EndpointType.REGIONAL, | ||
}); | ||
const stage = new apigw.Stage(stack, 'MyStage', { | ||
deployment: new apigw.Deployment(stack, 'MyDeplouyment', { | ||
api, | ||
}), | ||
}); | ||
|
||
// WHEN | ||
new apigw.BasePathMapping(stack, 'MyBasePathMapping', { | ||
restApi: api, | ||
domainName: domain, | ||
stage, | ||
}); | ||
|
||
// THEN | ||
expect(stack).toHaveResourceLike('AWS::ApiGateway::BasePathMapping', { | ||
Stage: { Ref: 'MyStage572B0482' }, | ||
}); | ||
}); | ||
}); |