@@ -3300,4 +3300,145 @@ describe('Bucket', () => {
33003300 done ( ) ;
33013301 } ) ;
33023302 } ) ;
3303+
3304+ describe ( 'setMetadata' , ( ) => {
3305+ describe ( 'encryption enforcement' , ( ) => {
3306+ it ( 'should correctly format restrictionMode for all enforcement types' , ( ) => {
3307+ const effectiveTime = '2026-02-02T12:00:00Z' ;
3308+ const encryptionMetadata = {
3309+ encryption : {
3310+ defaultKmsKeyName : 'kms-key-name' ,
3311+ googleManagedEncryptionEnforcementConfig : {
3312+ restrictionMode : 'FullyRestricted' ,
3313+ effectiveTime : effectiveTime ,
3314+ } ,
3315+ customerManagedEncryptionEnforcementConfig : {
3316+ restrictionMode : 'NotRestricted' ,
3317+ effectiveTime : effectiveTime ,
3318+ } ,
3319+ customerSuppliedEncryptionEnforcementConfig : {
3320+ restrictionMode : 'FullyRestricted' ,
3321+ effectiveTime : effectiveTime ,
3322+ } ,
3323+ } ,
3324+ } ;
3325+
3326+ bucket . setMetadata = ( metadata : BucketMetadata ) => {
3327+ assert . strictEqual (
3328+ metadata . encryption ?. defaultKmsKeyName ,
3329+ encryptionMetadata . encryption . defaultKmsKeyName
3330+ ) ;
3331+
3332+ assert . deepStrictEqual (
3333+ metadata . encryption ?. googleManagedEncryptionEnforcementConfig ,
3334+ { restrictionMode : 'FullyRestricted' , effectiveTime : effectiveTime }
3335+ ) ;
3336+
3337+ assert . deepStrictEqual (
3338+ metadata . encryption ?. customerManagedEncryptionEnforcementConfig ,
3339+ { restrictionMode : 'NotRestricted' , effectiveTime : effectiveTime }
3340+ ) ;
3341+
3342+ assert . deepStrictEqual (
3343+ metadata . encryption ?. customerSuppliedEncryptionEnforcementConfig ,
3344+ { restrictionMode : 'FullyRestricted' , effectiveTime : effectiveTime }
3345+ ) ;
3346+ } ;
3347+ bucket . setMetadata ( encryptionMetadata , assert . ifError ) ;
3348+ } ) ;
3349+
3350+ it ( 'should preserve existing encryption fields during a partial update' , done => {
3351+ bucket . metadata = {
3352+ encryption : {
3353+ defaultKmsKeyName : 'kms-key-name' ,
3354+ googleManagedEncryptionEnforcementConfig : {
3355+ restrictionMode : 'FullyRestricted' ,
3356+ } ,
3357+ } ,
3358+ } ;
3359+
3360+ const patch = {
3361+ encryption : {
3362+ customerSuppliedEncryptionEnforcementConfig : {
3363+ restrictionMode : 'FullyRestricted' ,
3364+ } ,
3365+ } ,
3366+ } ;
3367+
3368+ bucket . setMetadata = ( metadata : BucketMetadata ) => {
3369+ assert . strictEqual (
3370+ metadata . encryption ?. customerSuppliedEncryptionEnforcementConfig
3371+ ?. restrictionMode ,
3372+ 'FullyRestricted'
3373+ ) ;
3374+ done ( ) ;
3375+ } ;
3376+
3377+ bucket . setMetadata ( patch , assert . ifError ) ;
3378+ } ) ;
3379+
3380+ it ( 'should reject or handle invalid restrictionMode values' , done => {
3381+ const invalidMetadata = {
3382+ encryption : {
3383+ googleManagedEncryptionEnforcementConfig : {
3384+ restrictionMode : 'fully_restricted' ,
3385+ } ,
3386+ } ,
3387+ } ;
3388+
3389+ bucket . setMetadata = ( metadata : BucketMetadata ) => {
3390+ assert . strictEqual (
3391+ metadata . encryption ?. googleManagedEncryptionEnforcementConfig
3392+ ?. restrictionMode ,
3393+ 'fully_restricted'
3394+ ) ;
3395+ done ( ) ;
3396+ } ;
3397+
3398+ bucket . setMetadata ( invalidMetadata , assert . ifError ) ;
3399+ } ) ;
3400+
3401+ it ( 'should not include enforcement configs that are not provided' , done => {
3402+ const partialMetadata = {
3403+ encryption : {
3404+ defaultKmsKeyName : 'test-key' ,
3405+ googleManagedEncryptionEnforcementConfig : {
3406+ restrictionMode : 'FullyRestricted' ,
3407+ } ,
3408+ } ,
3409+ } ;
3410+
3411+ bucket . setMetadata = ( metadata : BucketMetadata ) => {
3412+ assert . ok ( metadata . encryption ?. defaultKmsKeyName ) ;
3413+ assert . ok (
3414+ metadata . encryption ?. googleManagedEncryptionEnforcementConfig
3415+ ) ;
3416+ assert . strictEqual (
3417+ metadata . encryption ?. customerManagedEncryptionEnforcementConfig ,
3418+ undefined
3419+ ) ;
3420+ assert . strictEqual (
3421+ metadata . encryption ?. customerSuppliedEncryptionEnforcementConfig ,
3422+ undefined
3423+ ) ;
3424+ done ( ) ;
3425+ } ;
3426+
3427+ bucket . setMetadata ( partialMetadata , assert . ifError ) ;
3428+ } ) ;
3429+
3430+ it ( 'should allow nullifying encryption enforcement' , done => {
3431+ const clearMetadata = {
3432+ encryption : null ,
3433+ } ;
3434+
3435+ bucket . setMetadata = ( metadata : BucketMetadata ) => {
3436+ assert . strictEqual ( metadata . encryption , null ) ;
3437+ done ( ) ;
3438+ } ;
3439+
3440+ bucket . setMetadata ( clearMetadata , assert . ifError ) ;
3441+ } ) ;
3442+ } ) ;
3443+ } ) ;
33033444} ) ;
0 commit comments