Skip to content

Commit 762bf6f

Browse files
TPXPmikehardy
andauthored
fix(storage, ios): resolve listAll promise once and only once on error (invertase#4688)
* FIX: [Storage] Don't try resolving the promise twice if an error occurs in listAll() See https://github.com/firebase/firebase-ios-sdk/blob/14764b8d60a6ad023d8fa5b7f81d42378d92e6fe/FirebaseStorage/Sources/FIRStorageReference.m#L417 * TST: Make sure listAll behaves as expected when the user is not authorized * Apply suggestions from code review Co-authored-by: Mike Hardy <[email protected]>
1 parent fa28299 commit 762bf6f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/storage/e2e/StorageReference.e2e.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,20 @@ describe('storage() -> StorageReference', function() {
346346
result.prefixes.length.should.be.greaterThan(0);
347347
result.prefixes[0].constructor.name.should.eql('StorageReference');
348348
});
349+
350+
it('should not crash if the user is not allowed to list the directory', async function() {
351+
const storageReference = firebase.storage().ref('/forbidden');
352+
try {
353+
await storageReference.listAll();
354+
return Promise.reject(new Error('listAll on a forbidden directory succeeded'));
355+
} catch (error) {
356+
error.code.should.equal('storage/unauthorized');
357+
error.message.should.equal(
358+
'[storage/unauthorized] User is not authorized to perform the desired action.',
359+
);
360+
return Promise.resolve();
361+
}
362+
});
349363
});
350364

351365
describe('updateMetadata', function() {

packages/storage/ios/RNFBStorage/RNFBStorageModule.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,16 @@ - (void)invalidate {
194194
) {
195195
FIRStorageReference *storageReference = [self getReferenceFromUrl:url app:firebaseApp];
196196

197+
__block bool alreadyCompleted = false;
198+
197199
id completionBlock = ^(FIRStorageListResult *result, NSError *error) {
200+
// This may be called multiple times if an error occurs
201+
// Make sure we won't try to resolve the promise twice in this case
202+
// TODO - remove pending resolution of https://github.com/firebase/firebase-ios-sdk/issues/7197
203+
if (alreadyCompleted) {
204+
return;
205+
}
206+
alreadyCompleted = true;
198207
if (error != nil) {
199208
[self promiseRejectStorageException:reject error:error];
200209
} else {

0 commit comments

Comments
 (0)