Skip to content

Commit

Permalink
fix(storage, ios): resolve listAll promise once and only once on error (
Browse files Browse the repository at this point in the history
#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 <github@mikehardy.net>
  • Loading branch information
TPXP and mikehardy authored Dec 18, 2020
1 parent fa28299 commit 762bf6f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/storage/e2e/StorageReference.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,20 @@ describe('storage() -> StorageReference', function() {
result.prefixes.length.should.be.greaterThan(0);
result.prefixes[0].constructor.name.should.eql('StorageReference');
});

it('should not crash if the user is not allowed to list the directory', async function() {
const storageReference = firebase.storage().ref('/forbidden');
try {
await storageReference.listAll();
return Promise.reject(new Error('listAll on a forbidden directory succeeded'));
} catch (error) {
error.code.should.equal('storage/unauthorized');
error.message.should.equal(
'[storage/unauthorized] User is not authorized to perform the desired action.',
);
return Promise.resolve();
}
});
});

describe('updateMetadata', function() {
Expand Down
9 changes: 9 additions & 0 deletions packages/storage/ios/RNFBStorage/RNFBStorageModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,16 @@ - (void)invalidate {
) {
FIRStorageReference *storageReference = [self getReferenceFromUrl:url app:firebaseApp];

__block bool alreadyCompleted = false;

id completionBlock = ^(FIRStorageListResult *result, NSError *error) {
// This may be called multiple times if an error occurs
// Make sure we won't try to resolve the promise twice in this case
// TODO - remove pending resolution of https://github.com/firebase/firebase-ios-sdk/issues/7197
if (alreadyCompleted) {
return;
}
alreadyCompleted = true;
if (error != nil) {
[self promiseRejectStorageException:reject error:error];
} else {
Expand Down

1 comment on commit 762bf6f

@vercel
Copy link

@vercel vercel bot commented on 762bf6f Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.