1- import { promises as fs , existsSync } from 'fs' ;
1+ import { existsSync , promises as fs } from 'fs' ;
22import * as os from 'os' ;
33import * as path from 'path' ;
44import {
@@ -22,21 +22,22 @@ import { InvokeCommand } from '@aws-sdk/client-lambda';
2222import { PutObjectLockConfigurationCommand } from '@aws-sdk/client-s3' ;
2323import { CreateTopicCommand , DeleteTopicCommand } from '@aws-sdk/client-sns' ;
2424import { AssumeRoleCommand , GetCallerIdentityCommand } from '@aws-sdk/client-sts' ;
25+ import * as mockttp from 'mockttp' ;
2526import {
26- integTest ,
2727 cloneDirectory ,
28- shell ,
29- withDefaultFixture ,
30- retry ,
31- sleep ,
28+ integTest ,
3229 randomInteger ,
33- withSamIntegrationFixture ,
30+ randomString ,
3431 RESOURCES_DIR ,
32+ retry ,
33+ shell ,
34+ sleep ,
3535 withCDKMigrateFixture ,
36+ withDefaultFixture ,
3637 withExtendedTimeoutFixture ,
37- randomString ,
38- withSpecificFixture ,
3938 withoutBootstrap ,
39+ withSamIntegrationFixture ,
40+ withSpecificFixture ,
4041} from '../../lib' ;
4142
4243jest . setTimeout ( 2 * 60 * 60_000 ) ; // Includes the time to acquire locks, worst-case single-threaded runtime
@@ -2809,3 +2810,46 @@ integTest('cdk notices are displayed correctly', withDefaultFixture(async (fixtu
28092810 expect ( output ) . toContain ( `AffectedEnvironments:<aws://${ await fixture . aws . account ( ) } /${ fixture . aws . region } >` ) ;
28102811
28112812} ) ) ;
2813+
2814+ integTest ( 'requests go through a proxy when configured' ,
2815+ withDefaultFixture ( async ( fixture ) => {
2816+ // Set up key and certificate
2817+ const { key, cert } = await mockttp . generateCACertificate ( ) ;
2818+ const certDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'cdk-' ) ) ;
2819+ const certPath = path . join ( certDir , 'cert.pem' ) ;
2820+ const keyPath = path . join ( certDir , 'key.pem' ) ;
2821+ await fs . writeFile ( keyPath , key ) ;
2822+ await fs . writeFile ( certPath , cert ) ;
2823+
2824+ const proxyServer = mockttp . getLocal ( {
2825+ https : { keyPath, certPath } ,
2826+ } ) ;
2827+
2828+ // We don't need to modify any request, so the proxy
2829+ // passes through all requests to the host.
2830+ const endpoint = await proxyServer
2831+ . forAnyRequest ( )
2832+ . thenPassThrough ( ) ;
2833+
2834+ proxyServer . enableDebug ( ) ;
2835+ await proxyServer . start ( ) ;
2836+
2837+ // The proxy is now ready to intercept requests
2838+
2839+ try {
2840+ await fixture . cdkDeploy ( 'test-2' , {
2841+ captureStderr : true ,
2842+ options : [
2843+ '--proxy' , proxyServer . url ,
2844+ '--ca-bundle-path' , certPath ,
2845+ ] ,
2846+ } ) ;
2847+ } finally {
2848+ await fs . rm ( certDir , { recursive : true , force : true } ) ;
2849+ }
2850+
2851+ // Checking that there was some interaction with the proxy
2852+ const requests = await endpoint . getSeenRequests ( ) ;
2853+ expect ( requests . length ) . toBeGreaterThan ( 0 ) ;
2854+ } ) ,
2855+ ) ;
0 commit comments