1
- import { promises as fs , existsSync } from 'fs' ;
1
+ import { existsSync , promises as fs } from 'fs' ;
2
2
import * as os from 'os' ;
3
3
import * as path from 'path' ;
4
4
import {
@@ -22,21 +22,22 @@ import { InvokeCommand } from '@aws-sdk/client-lambda';
22
22
import { PutObjectLockConfigurationCommand } from '@aws-sdk/client-s3' ;
23
23
import { CreateTopicCommand , DeleteTopicCommand } from '@aws-sdk/client-sns' ;
24
24
import { AssumeRoleCommand , GetCallerIdentityCommand } from '@aws-sdk/client-sts' ;
25
+ import * as mockttp from 'mockttp' ;
25
26
import {
26
- integTest ,
27
27
cloneDirectory ,
28
- shell ,
29
- withDefaultFixture ,
30
- retry ,
31
- sleep ,
28
+ integTest ,
32
29
randomInteger ,
33
- withSamIntegrationFixture ,
30
+ randomString ,
34
31
RESOURCES_DIR ,
32
+ retry ,
33
+ shell ,
34
+ sleep ,
35
35
withCDKMigrateFixture ,
36
+ withDefaultFixture ,
36
37
withExtendedTimeoutFixture ,
37
- randomString ,
38
- withSpecificFixture ,
39
38
withoutBootstrap ,
39
+ withSamIntegrationFixture ,
40
+ withSpecificFixture ,
40
41
} from '../../lib' ;
41
42
42
43
jest . 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
2809
2810
expect ( output ) . toContain ( `AffectedEnvironments:<aws://${ await fixture . aws . account ( ) } /${ fixture . aws . region } >` ) ;
2810
2811
2811
2812
} ) ) ;
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