@@ -502,7 +502,7 @@ describe('storage', function () {
502502 } ) ;
503503
504504 it ( 'should set custom encryption during the upload' , async ( ) => {
505- const key = '12345678901234567890123456789012' ;
505+ const key = crypto . randomBytes ( 32 ) ;
506506 const [ file ] = await bucket . upload ( FILES . big . path , {
507507 encryptionKey : key ,
508508 resumable : false ,
@@ -2730,20 +2730,8 @@ describe('storage', function () {
27302730 const { name : tmpGzFilePath } = tmp . fileSync ( { postfix : '.gz' } ) ;
27312731 fs . writeFileSync ( tmpGzFilePath , gzipSync ( expectedContents ) ) ;
27322732
2733- const file : File = await new Promise ( ( resolve , reject ) => {
2734- bucket . upload ( tmpGzFilePath , options , ( err , file ) => {
2735- if ( err || ! file ) return reject ( err ) ;
2736- resolve ( file ) ;
2737- } ) ;
2738- } ) ;
2739-
2740- const contents : Buffer = await new Promise ( ( resolve , reject ) => {
2741- return file . download ( ( error , content ) => {
2742- if ( error ) return reject ( error ) ;
2743- resolve ( content ) ;
2744- } ) ;
2745- } ) ;
2746-
2733+ const [ file ] = await bucket . upload ( tmpGzFilePath , options ) ;
2734+ const [ contents ] = await file . download ( { decompress : false } ) ;
27472735 assert . strictEqual ( contents . toString ( ) , expectedContents ) ;
27482736 await file . delete ( ) ;
27492737 } ) ;
@@ -2755,23 +2743,13 @@ describe('storage', function () {
27552743 gzip : true ,
27562744 } ) ;
27572745
2758- tmp . setGracefulCleanup ( ) ;
2759- const { name : tmpFilePath } = tmp . fileSync ( ) ;
2760-
27612746 const file = bucket . file ( filename ) ;
27622747
2763- await new Promise < void > ( ( resolve , reject ) => {
2764- file
2765- . createReadStream ( { decompress : true } )
2766- . on ( 'error' , reject )
2767- . on ( 'response' , ( raw : GaxiosResponse ) => {
2768- assert . strictEqual ( raw . headers . get ( 'content-encoding' ) , undefined ) ;
2769- } )
2770- . pipe ( fs . createWriteStream ( tmpFilePath ) )
2771- . on ( 'error' , reject )
2772- . on ( 'finish' , ( ) => resolve ( ) ) ;
2748+ const [ contents ] = await file . download ( {
2749+ decompress : false ,
27732750 } ) ;
2774-
2751+ const expectedContents = fs . readFileSync ( FILES . logo . path ) ;
2752+ assert . ok ( expectedContents . equals ( contents ) ) ;
27752753 await file . delete ( ) ;
27762754 } ) ;
27772755
@@ -2890,13 +2868,15 @@ describe('storage', function () {
28902868
28912869 describe ( 'customer-supplied encryption keys' , ( ) => {
28922870 const encryptionKey = crypto . randomBytes ( 32 ) ;
2893-
2894- const file = bucket . file ( 'encrypted-file' , {
2895- encryptionKey,
2896- } ) ;
2897- const unencryptedFile = bucket . file ( file . name ) ;
2871+ const fileName = `encrypted-file-${ Date . now ( ) } ` ;
2872+ let file : File ;
2873+ let unencryptedFile : File ;
28982874
28992875 before ( async ( ) => {
2876+ file = bucket . file ( fileName , {
2877+ encryptionKey,
2878+ } ) ;
2879+ unencryptedFile = bucket . file ( file . name ) ;
29002880 await file . save ( 'secret data' , { resumable : false } ) ;
29012881 } ) ;
29022882
@@ -2937,6 +2917,7 @@ describe('storage', function () {
29372917 it ( 'should rotate encryption keys' , async ( ) => {
29382918 const newEncryptionKey = crypto . randomBytes ( 32 ) ;
29392919 await file . rotateEncryptionKey ( newEncryptionKey ) ;
2920+ file . setEncryptionKey ( newEncryptionKey ) ;
29402921 const [ contents ] = await file . download ( ) ;
29412922 assert . strictEqual ( contents . toString ( ) , 'secret data' ) ;
29422923 } ) ;
@@ -2952,9 +2933,6 @@ describe('storage', function () {
29522933 const keyRingId = generateName ( ) ;
29532934 const cryptoKeyId = generateName ( ) ;
29542935
2955- //const request = promisify(storage.request).bind(storage);
2956- // eslint-disable-next-line no-empty-pattern
2957- // const request = ({}) => {};
29582936 // eslint-disable-next-line @typescript-eslint/no-explicit-any
29592937 const request = ( opts : any ) => {
29602938 // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -3117,12 +3095,21 @@ describe('storage', function () {
31173095
31183096 it ( 'should convert CSEK to KMS key' , async ( ) => {
31193097 const encryptionKey = crypto . randomBytes ( 32 ) ;
3120- const file = bucket . file ( 'encrypted-file' , { encryptionKey} ) ;
3121- await file . save ( FILE_CONTENTS , { resumable : false } ) ;
3122- await file . rotateEncryptionKey ( { kmsKeyName} ) ;
3123- const [ contents ] = await file . download ( ) ;
3124- assert . strictEqual ( contents . toString ( ) , 'secret data' ) ;
3098+ const originalName = `csek-to-kms-${ Date . now ( ) } ` ;
3099+ const csekFile = bucket . file ( originalName , { encryptionKey} ) ;
3100+
3101+ await csekFile . save ( FILE_CONTENTS , { resumable : false } ) ;
3102+ await csekFile . rotateEncryptionKey ( { kmsKeyName} ) ;
3103+ const kmsFile = bucket . file ( originalName ) ;
3104+ const [ contents ] = await kmsFile . download ( ) ;
3105+ assert . strictEqual ( contents . toString ( ) , FILE_CONTENTS ) ;
3106+ const [ metadata ] = await kmsFile . getMetadata ( ) ;
3107+ assert . ok (
3108+ metadata . kmsKeyName && metadata . kmsKeyName . includes ( kmsKeyName ) ,
3109+ ) ;
3110+ assert . strictEqual ( metadata . customerEncryption , undefined ) ;
31253111 } ) ;
3112+
31263113 } ) ;
31273114
31283115 describe ( 'buckets' , ( ) => {
0 commit comments