-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
[REQUIRED] Environment info
firebase-tools:
9.14.0
Platform:
macOS 11.4
[REQUIRED] Test case
Try to upload a picture to Storage Emulator with the following Storage Rules via iOS Simulator
allow read : if request.auth != null;
allow write : if request.auth != null;
allow delete : if request.auth != null;
[REQUIRED] Steps to reproduce
The Following function works fine with actual Firebase Storage. But it crashes the Emulator Suite entirely.
uploadImage = (imageUri, storagePath, mime = 'image/jpg') => {
return new Promise((resolve, reject) => {
const imageRef = storage().ref(storagePath);
return imageRef.putFile(imageUri)
.then(() => {
return imageRef.getDownloadURL();
})
.then((url) => {
resolve(url);
})
.catch((error) => {
return reject(error);
})
})
}
Crashes with the following storage.rules
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{uid}/{allPaths=**} {
allow read : if request.auth != null;
allow write : if request.auth != null;
allow delete : if request.auth != null;
}
}
}
But the same function works fine with Emulator if I change the storage.rules to the following:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{uid}/{allPaths=**} {
allow read : if true;
allow write : if true;
allow delete : if true;
}
}
}
The user uploading the photo is authenticated user as I used auth emulator to create the user, and it can read the storage data fine, with the same rules that crashes Emulator on write.
[REQUIRED] Expected behavior
Do not crash and upload the photo to Storage Emulator
[REQUIRED] Actual behavior
Crashes with following Error :
Error: An unexpected error has occurred.
Last few lines of firebase-debug.log
[debug] [2021-07-04T08:35:03.322Z] [work-queue] {"queueLength":0,"workRunningCount":0}
[debug] [2021-07-04T08:35:28.764Z] >>> [apiv2][query] POST http://localhost:5001/functions/projects/my-new-app/trigger_multicast [none]
[debug] [2021-07-04T08:35:28.765Z] >>> [apiv2][body] POST http://localhost:5001/functions/projects/my-new-app/trigger_multicast "{\"eventId\":\"1625387728764\",\"timestamp\":\"2021-07-04T14:05:28.764Z\",\"eventType\":\"google.storage.object.metadataUpdate\",\"resource\":{\"service\":\"storage.googleapis.com\",\"name\":\"projects/_/buckets/my-new-app.appspot.com/objects/aGtgkgT04cudlZXaPFC72R9tZMlv/INSPJ6MFM/jxRlG6mkqJAesWsyBpYb/1625387702/img/16253877290.jpeg\",\"type\":\"storage#object\"},\"data\":{\"kind\":\"#storage#object\",\"name\":\"aGtgkgT04cudlZXaPFC72R9tZMlv/INSPJ6MFM/jxRlG6mkqJAesWsyBpYb/1625387702/img/16253877290.jpeg\",\"bucket\":\"my-new-app.appspot.com\",\"generation\":\"1625387728761\",\"metageneration\":\"1\",\"contentType\":\"image/jpeg\",\"timeCreated\":\"2021-07-04T14:05:28.760Z\",\"updated\":\"2021-07-04T14:05:28.763Z\",\"storageClass\":\"STANDARD\",\"size\":\"146806\",\"md5Hash\":\"E2RcNNuWL698kBR3mKIDxw==\",\"etag\":\"someETag\",\"crc32c\":\"----MA==\",\"timeStorageClassUpdated\":\"2021-07-04T14:05:28.760Z\",\"id\":\"my-new-app.appspot.com/aGtgkgT04cudlZXaPFC72R9tZMlv/INSPJ6MFM/jxRlG6mkqJAesWsyBpYb/1625387702/img/16253877290.jpeg/1625387728761\",\"selfLink\":\"http://localhost:9199/storage/v1/b/my-new-app.appspot.com/o/aGtgkgT04cudlZXaPFC72R9tZMlv%2FINSPJ6MFM%2FjxRlG6mkqJAesWsyBpYb%2F1625387702%2Fimg%2F16253877290.jpeg\",\"mediaLink\":\"http://localhost:9199/download/storage/v1/b/my-new-app.appspot.com/o/aGtgkgT04cudlZXaPFC72R9tZMlv%2FINSPJ6MFM%2FjxRlG6mkqJAesWsyBpYb%2F1625387702%2Fimg%2F16253877290.jpeg?generation=1625387728761&alt=media\"}}"
[debug] [2021-07-04T08:35:28.768Z] >>> [apiv2][query] POST http://localhost:5001/functions/projects/my-new-app/trigger_multicast [none]
[debug] [2021-07-04T08:35:28.768Z] >>> [apiv2][body] POST http://localhost:5001/functions/projects/my-new-app/trigger_multicast "{\"eventId\":\"1625387728768\",\"timestamp\":\"2021-07-04T14:05:28.768Z\",\"eventType\":\"google.storage.object.finalize\",\"resource\":{\"service\":\"storage.googleapis.com\",\"name\":\"projects/_/buckets/my-new-app.appspot.com/objects/aGtgkgT04cudlZXaPFC72R9tZMlv/INSPJ6MFM/jxRlG6mkqJAesWsyBpYb/1625387702/img/16253877290.jpeg\",\"type\":\"storage#object\"},\"data\":{\"kind\":\"#storage#object\",\"name\":\"aGtgkgT04cudlZXaPFC72R9tZMlv/INSPJ6MFM/jxRlG6mkqJAesWsyBpYb/1625387702/img/16253877290.jpeg\",\"bucket\":\"my-new-app.appspot.com\",\"generation\":\"1625387728761\",\"metageneration\":\"1\",\"contentType\":\"image/jpeg\",\"timeCreated\":\"2021-07-04T14:05:28.760Z\",\"updated\":\"2021-07-04T14:05:28.763Z\",\"storageClass\":\"STANDARD\",\"size\":\"146806\",\"md5Hash\":\"E2RcNNuWL698kBR3mKIDxw==\",\"etag\":\"someETag\",\"crc32c\":\"----MA==\",\"timeStorageClassUpdated\":\"2021-07-04T14:05:28.760Z\",\"id\":\"my-new-app.appspot.com/aGtgkgT04cudlZXaPFC72R9tZMlv/INSPJ6MFM/jxRlG6mkqJAesWsyBpYb/1625387702/img/16253877290.jpeg/1625387728761\",\"selfLink\":\"http://localhost:9199/storage/v1/b/my-new-app.appspot.com/o/aGtgkgT04cudlZXaPFC72R9tZMlv%2FINSPJ6MFM%2FjxRlG6mkqJAesWsyBpYb%2F1625387702%2Fimg%2F16253877290.jpeg\",\"mediaLink\":\"http://localhost:9199/download/storage/v1/b/my-new-app.appspot.com/o/aGtgkgT04cudlZXaPFC72R9tZMlv%2FINSPJ6MFM%2FjxRlG6mkqJAesWsyBpYb%2F1625387702%2Fimg%2F16253877290.jpeg?generation=1625387728761&alt=media\"}}"
[debug] [2021-07-04T08:35:28.782Z] <<< [apiv2][status] POST http://localhost:5001/functions/projects/my-new-app/trigger_multicast 200
[debug] [2021-07-04T08:35:28.783Z] <<< [apiv2][body] POST http://localhost:5001/functions/projects/my-new-app/trigger_multicast {"status":"multicast_acknowledged"}
[debug] [2021-07-04T08:35:28.784Z] <<< [apiv2][status] POST http://localhost:5001/functions/projects/my-new-app/trigger_multicast 200
[debug] [2021-07-04T08:35:28.784Z] <<< [apiv2][body] POST http://localhost:5001/functions/projects/my-new-app/trigger_multicast {"status":"multicast_acknowledged"}
[debug] [2021-07-04T08:35:28.947Z] >>> [apiv2][query] POST http://localhost:5001/functions/projects/my-new-app/trigger_multicast [none]
[debug] [2021-07-04T08:35:28.947Z] >>> [apiv2][body] POST http://localhost:5001/functions/projects/my-new-app/trigger_multicast "{\"eventId\":\"1625387728947\",\"timestamp\":\"2021-07-04T14:05:28.947Z\",\"eventType\":\"google.storage.object.delete\",\"resource\":{\"service\":\"storage.googleapis.com\",\"name\":\"projects/_/buckets/my-new-app.appspot.com/objects/aGtgkgT04cudlZXaPFC72R9tZMlv/INSPJ6MFM/jxRlG6mkqJAesWsyBpYb/1625387702/img/16253877290.jpeg\",\"type\":\"storage#object\"},\"data\":{\"kind\":\"#storage#object\",\"name\":\"aGtgkgT04cudlZXaPFC72R9tZMlv/INSPJ6MFM/jxRlG6mkqJAesWsyBpYb/1625387702/img/16253877290.jpeg\",\"bucket\":\"my-new-app.appspot.com\",\"generation\":\"1625387728761\",\"metageneration\":\"1\",\"contentType\":\"image/jpeg\",\"timeCreated\":\"2021-07-04T14:05:28.760Z\",\"updated\":\"2021-07-04T14:05:28.763Z\",\"storageClass\":\"STANDARD\",\"size\":\"146806\",\"md5Hash\":\"E2RcNNuWL698kBR3mKIDxw==\",\"etag\":\"someETag\",\"crc32c\":\"----MA==\",\"timeStorageClassUpdated\":\"2021-07-04T14:05:28.760Z\",\"id\":\"my-new-app.appspot.com/aGtgkgT04cudlZXaPFC72R9tZMlv/INSPJ6MFM/jxRlG6mkqJAesWsyBpYb/1625387702/img/16253877290.jpeg/1625387728761\",\"selfLink\":\"http://localhost:9199/storage/v1/b/my-new-app.appspot.com/o/aGtgkgT04cudlZXaPFC72R9tZMlv%2FINSPJ6MFM%2FjxRlG6mkqJAesWsyBpYb%2F1625387702%2Fimg%2F16253877290.jpeg\",\"mediaLink\":\"http://localhost:9199/download/storage/v1/b/my-new-app.appspot.com/o/aGtgkgT04cudlZXaPFC72R9tZMlv%2FINSPJ6MFM%2FjxRlG6mkqJAesWsyBpYb%2F1625387702%2Fimg%2F16253877290.jpeg?generation=1625387728761&alt=media\"}}"
[debug] [2021-07-04T08:35:28.950Z] <<< [apiv2][status] POST http://localhost:5001/functions/projects/my-new-app/trigger_multicast 200
[debug] [2021-07-04T08:35:28.951Z] <<< [apiv2][body] POST http://localhost:5001/functions/projects/my-new-app/trigger_multicast {"status":"multicast_acknowledged"}
[debug] [2021-07-04T08:35:28.997Z] Error: ENOENT: no such file or directory, unlink '/var/folders/jt/rrd3wxwj09bd2twr6cxdx1z80000gn/T/firebase/storage/blobs/d08a3410-0980-4fbe-b46c-eb4111ad46e9_b_my-new-app.appspot.com_o_aGtgkgT04cudlZXaPFC72R9tZMlv%2FINSPJ6MFM%2FjxRlG6mkqJAesWsyBpYb%2F1625387702%2Fimg%2F16253877290.jpeg'
at Object.unlinkSync (node:fs:1708:3)
at Persistence.deleteFile (/usr/local/lib/node_modules/firebase-tools/lib/emulator/storage/files.js:478:18)
at StorageLayer.cancelUpload (/usr/local/lib/node_modules/firebase-tools/lib/emulator/storage/files.js:152:27)
at handleUpload (/usr/local/lib/node_modules/firebase-tools/lib/emulator/storage/apis/firebase.js:366:45)
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/storage/apis/firebase.js:443:24
at Layer.handle [as handle_request] (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/layer.js:95:5)
at next (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/layer.js:95:5)
at /usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:281:22
at param (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:354:14)
at param (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:365:14)
at param (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:365:14)
at Function.process_params (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:410:3)
at next (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/router/index.js:275:10)
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/storage/apis/firebase.js:89:9
[error]
[error] Error: An unexpected error has occurred.
alabdulaal, ggirotto, zakton5, corentingiraud, markszente and 2 more