@@ -25,8 +25,20 @@ describe('determineAllowCrossAccountAssetPublishing', () => {
2525 } ) ;
2626 } ) ;
2727
28- AWSMock . mock ( 'CloudFormation' , 'describeStackResources' , ( _params : any , callback : Function ) => {
29- callback ( null , { StackResources : [ ] } ) ;
28+ const result = await determineAllowCrossAccountAssetPublishing ( mockSDK ) ;
29+ expect ( result ) . toBe ( true ) ;
30+ } ) ;
31+
32+ it . each ( [ '' , '-' , '*' , '---' ] ) ( 'should return true when the bucket output does not look like a real bucket' , async ( notABucketName ) => {
33+ AWSMock . mock ( 'CloudFormation' , 'describeStacks' , ( _params : any , callback : Function ) => {
34+ callback ( null , {
35+ Stacks : [ {
36+ Outputs : [
37+ { OutputKey : 'BootstrapVersion' , OutputValue : '1' } ,
38+ { OutputKey : 'BucketName' , OutputValue : notABucketName } ,
39+ ] ,
40+ } ] ,
41+ } ) ;
3042 } ) ;
3143
3244 const result = await determineAllowCrossAccountAssetPublishing ( mockSDK ) ;
@@ -37,13 +49,30 @@ describe('determineAllowCrossAccountAssetPublishing', () => {
3749 AWSMock . mock ( 'CloudFormation' , 'describeStacks' , ( _params : any , callback : Function ) => {
3850 callback ( null , {
3951 Stacks : [ {
40- Outputs : [ { OutputKey : 'BootstrapVersion' , OutputValue : '21' } ] ,
52+ Outputs : [
53+ { OutputKey : 'BootstrapVersion' , OutputValue : '21' } ,
54+ { OutputKey : 'BucketName' , OutputValue : 'some-bucket' } ,
55+ ] ,
4156 } ] ,
4257 } ) ;
4358 } ) ;
4459
45- AWSMock . mock ( 'CloudFormation' , 'describeStackResources' , ( _params : any , callback : Function ) => {
46- callback ( null , { StackResources : [ { ResourceType : 'AWS::S3::Bucket' , PhysicalResourceId : 'some-bucket' } ] } ) ;
60+ const result = await determineAllowCrossAccountAssetPublishing ( mockSDK ) ;
61+ expect ( result ) . toBe ( true ) ;
62+ } ) ;
63+
64+ it ( 'should return true if looking up the bootstrap stack fails' , async ( ) => {
65+ AWSMock . mock ( 'CloudFormation' , 'describeStacks' , ( _params : any , callback : Function ) => {
66+ callback ( new Error ( 'Could not read bootstrap stack' ) ) ;
67+ } ) ;
68+
69+ const result = await determineAllowCrossAccountAssetPublishing ( mockSDK ) ;
70+ expect ( result ) . toBe ( true ) ;
71+ } ) ;
72+
73+ it ( 'should return true if looking up the bootstrap stack fails' , async ( ) => {
74+ AWSMock . mock ( 'CloudFormation' , 'describeStacks' , ( _params : any , callback : Function ) => {
75+ callback ( new Error ( 'Could not read bootstrap stack' ) ) ;
4776 } ) ;
4877
4978 const result = await determineAllowCrossAccountAssetPublishing ( mockSDK ) ;
@@ -54,15 +83,14 @@ describe('determineAllowCrossAccountAssetPublishing', () => {
5483 AWSMock . mock ( 'CloudFormation' , 'describeStacks' , ( _params : any , callback : Function ) => {
5584 callback ( null , {
5685 Stacks : [ {
57- Outputs : [ { OutputKey : 'BootstrapVersion' , OutputValue : '20' } ] ,
86+ Outputs : [
87+ { OutputKey : 'BootstrapVersion' , OutputValue : '20' } ,
88+ { OutputKey : 'BucketName' , OutputValue : 'some-bucket' } ,
89+ ] ,
5890 } ] ,
5991 } ) ;
6092 } ) ;
6193
62- AWSMock . mock ( 'CloudFormation' , 'describeStackResources' , ( _params : any , callback : Function ) => {
63- callback ( null , { StackResources : [ { ResourceType : 'AWS::S3::Bucket' , PhysicalResourceId : 'some-bucket' } ] } ) ;
64- } ) ;
65-
6694 const result = await determineAllowCrossAccountAssetPublishing ( mockSDK ) ;
6795 expect ( result ) . toBe ( false ) ;
6896 } ) ;
@@ -85,15 +113,14 @@ describe('getBootstrapStackInfo', () => {
85113 AWSMock . mock ( 'CloudFormation' , 'describeStacks' , ( _params : any , callback : Function ) => {
86114 callback ( null , {
87115 Stacks : [ {
88- Outputs : [ { OutputKey : 'BootstrapVersion' , OutputValue : '21' } ] ,
116+ Outputs : [
117+ { OutputKey : 'BootstrapVersion' , OutputValue : '21' } ,
118+ { OutputKey : 'BucketName' , OutputValue : 'some-bucket' } ,
119+ ] ,
89120 } ] ,
90121 } ) ;
91122 } ) ;
92123
93- AWSMock . mock ( 'CloudFormation' , 'describeStackResources' , ( _params : any , callback : Function ) => {
94- callback ( null , { StackResources : [ { ResourceType : 'AWS::S3::Bucket' , PhysicalResourceId : 'some-bucket' } ] } ) ;
95- } ) ;
96-
97124 const result = await getBootstrapStackInfo ( mockSDK , 'CDKToolkit' ) ;
98125 expect ( result ) . toEqual ( {
99126 hasStagingBucket : true ,
0 commit comments