Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storage, ios): resolve listAll promise once and only once on error #4688

Merged
merged 3 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

thank you so much for adding a test to support this change!

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