Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mazyu36 committed Mar 2, 2025
1 parent 3385a64 commit fd90aa2
Showing 1 changed file with 80 additions and 1 deletion.
81 changes: 80 additions & 1 deletion packages/aws-cdk-lib/aws-efs/test/efs-file-system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ test('one zone file system with vpcSubnets.availabilityZones empty.', () => {

test.each([
ReplicationOverwriteProtection.ENABLED, ReplicationOverwriteProtection.DISABLED,
])('create read-only file system for replication destination', ( replicationOverwriteProtection ) => {
])('create read-only file system for replication destination', (replicationOverwriteProtection) => {
// WHEN
new FileSystem(stack, 'EfsFileSystem', {
vpc,
Expand Down Expand Up @@ -1106,3 +1106,82 @@ describe('replication configuration', () => {
}).toThrow('Cannot configure \'replicationConfiguration\' when \'replicationOverwriteProtection\' is set to \'DISABLED\'');
});
});

describe('test EFS_DEFAULT_ALLOW_CLIENT_MOUNT feature flag', () => {
test.each([false, undefined])('FileSystem Policy should not include ClientMount action when flag is %s', (value) => {
// WHEN
const app = new App({
context: {
[cxapi.EFS_DEFAULT_ALLOW_CLIENT_MOUNT]: value,
},
});
const customStack = new Stack(app);
const customVpc = new ec2.Vpc(customStack, 'VPC');
new FileSystem(customStack, 'EfsFileSystem', {
vpc: customVpc,
allowAnonymousAccess: false,
});

// THEN
Template.fromStack(customStack).hasResourceProperties('AWS::EFS::FileSystem', {
FileSystemPolicy: {
Statement: [
{
Effect: 'Allow',
Principal: {
AWS: '*',
},
Action: [
'elasticfilesystem:ClientWrite',
'elasticfilesystem:ClientRootAccess',
],
Condition: {
Bool: {
'elasticfilesystem:AccessedViaMountTarget': 'true',
},
},
},
],
},
});
});

test('FileSystem Policy should include ClientMount action when flag is true', () => {
// WHEN
const app = new App({
context: {
[cxapi.EFS_DEFAULT_ALLOW_CLIENT_MOUNT]: true,
},
});
const customStack = new Stack(app);
const customVpc = new ec2.Vpc(customStack, 'VPC');
new FileSystem(customStack, 'EfsFileSystem', {
vpc: customVpc,
allowAnonymousAccess: false,
});

// THEN
Template.fromStack(customStack).hasResourceProperties('AWS::EFS::FileSystem', {
FileSystemPolicy: {
Statement: [
{
Effect: 'Allow',
Principal: {
AWS: '*',
},
Action: [
'elasticfilesystem:ClientMount',
'elasticfilesystem:ClientWrite',
'elasticfilesystem:ClientRootAccess',
],
Condition: {
Bool: {
'elasticfilesystem:AccessedViaMountTarget': 'true',
},
},
},
],
},
});
});
});

0 comments on commit fd90aa2

Please sign in to comment.