Skip to content

Commit 12ded2a

Browse files
authored
Prevent 2nd listAll callback (#7199)
1 parent 5502a08 commit 12ded2a

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

FirebaseStorage/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 7.4.0
2+
- [Fixed] Prevent second `listAll` callback. (#7197)
3+
14
# 7.3.0
25
- [Fixed] Verify block is still alive before calling it in task callbacks. (#7051)
36

FirebaseStorage/Sources/FIRStorageReference.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ - (void)listAllWithCompletion:(FIRStorageVoidListError)completion {
415415
^(FIRStorageListResult *listResult, NSError *error) {
416416
if (error) {
417417
completion(nil, error);
418+
return;
418419
}
419420

420421
FIRStorageReference *strongSelf = weakSelf;

FirebaseStorage/Tests/Unit/FIRStorageListTests.m

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,29 @@ - (void)testValidatesInput {
7979
[FIRStorageTestHelpers waitForExpectation:self];
8080
}
8181

82+
- (void)testListAllCallbackOnlyCalledOnce {
83+
XCTestExpectation *expectation =
84+
[self expectationWithDescription:@"testListAllCallbackOnlyCalledOnce"];
85+
expectation.expectedFulfillmentCount = 1;
86+
87+
FIRStoragePath *path = [FIRStorageTestHelpers objectPath];
88+
FIRStorageReference *ref = [[FIRStorageReference alloc] initWithStorage:self.storage path:path];
89+
90+
FIRStorageVoidListError errorBlock = ^(FIRStorageListResult *result, NSError *error) {
91+
XCTAssertNil(result);
92+
XCTAssertNotNil(error);
93+
94+
XCTAssertEqualObjects(error.domain, @"FIRStorageErrorDomain");
95+
XCTAssertEqual(error.code, FIRStorageErrorCodeUnknown);
96+
97+
[expectation fulfill];
98+
};
99+
100+
[ref listAllWithCompletion:errorBlock];
101+
102+
[FIRStorageTestHelpers waitForExpectation:self];
103+
}
104+
82105
- (void)testDefaultList {
83106
XCTestExpectation *expectation = [self expectationWithDescription:@"testDefaultList"];
84107
NSURL *expectedURL = [NSURL
@@ -251,7 +274,7 @@ - (void)testListWithResponse {
251274
- (void)testListWithErrorResponse {
252275
XCTestExpectation *expectation = [self expectationWithDescription:@"testListWithErrorResponse"];
253276

254-
NSError *error = [NSError errorWithDomain:@"com.google.firebase.storage" code:-1 userInfo:nil];
277+
NSError *error = [NSError errorWithDomain:@"com.google.firebase.storage" code:404 userInfo:nil];
255278

256279
self.fetcherService.testBlock =
257280
^(GTMSessionFetcher *fetcher, GTMSessionFetcherTestResponse response) {
@@ -276,6 +299,7 @@ - (void)testListWithErrorResponse {
276299
XCTAssertNil(result);
277300

278301
XCTAssertEqualObjects(error.domain, @"FIRStorageErrorDomain");
302+
XCTAssertEqual(error.code, FIRStorageErrorCodeObjectNotFound);
279303

280304
[expectation fulfill];
281305
}];

0 commit comments

Comments
 (0)