Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(defaultStackSynthesizer): prevent App level synthesizer from propagating assets across stacks #29073

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ export class DefaultStackSynthesizer extends StackSynthesizer implements IReusab
*/
public reusableBind(stack: Stack): IBoundStackSynthesizer {
// Create a copy of the current object and bind that
const copy = Object.create(this);
const copy = Object.create(this) as DefaultStackSynthesizer;
copy.assetManifest = new AssetManifestBuilder();
copy.bind(stack);
return copy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,39 @@ describe('new style synthesis', () => {
}
});

test('app level synthesizer does not leak assets between stacks', () => {
// GIVEN
const myapp = new App({
defaultStackSynthesizer: new DefaultStackSynthesizer(),
});

// WHEN
const stack1 = new Stack(myapp, 'Stack1');
const stack2 = new Stack(myapp, 'Stack2');

stack1.synthesizer.addFileAsset({
fileName: __filename,
packaging: FileAssetPackaging.FILE,
sourceHash: 'hash1',
});
stack2.synthesizer.addFileAsset({
fileName: __filename,
packaging: FileAssetPackaging.FILE,
sourceHash: 'hash2',
});

// THEN
const asm = myapp.synth();

const manifest1 = readAssetManifest(getAssetManifest(asm, 0));
expect(manifest1.files).toHaveProperty('hash1');
expect(manifest1.files).not.toHaveProperty('hash2');

const manifest2 = readAssetManifest(getAssetManifest(asm, 1));
expect(manifest2.files).toHaveProperty('hash2');
expect(manifest2.files).not.toHaveProperty('hash1');
});

/**
* Evaluate a possibly string-containing value the same way CFN would do
*
Expand Down Expand Up @@ -506,8 +539,8 @@ function isAssetManifest(x: cxapi.CloudArtifact): x is cxapi.AssetManifestArtifa
return x instanceof cxapi.AssetManifestArtifact;
}

function getAssetManifest(asm: cxapi.CloudAssembly): cxapi.AssetManifestArtifact {
const manifestArtifact = asm.artifacts.filter(isAssetManifest)[0];
function getAssetManifest(asm: cxapi.CloudAssembly, stackIndex: number = 0): cxapi.AssetManifestArtifact {
const manifestArtifact = asm.artifacts.filter(isAssetManifest)[stackIndex];
if (!manifestArtifact) { throw new Error('no asset manifest in assembly'); }
return manifestArtifact;
}
Expand Down
Loading