Skip to content

Commit 6c84675

Browse files
authored
Add check for unauthenticated error and sign out in fetchNewLatestRelease (#6648)
* Add check for unauthenticated error and sign out in fetchNewRelase method * Update CHANGELOG * Add check for Tester sign in before calling fetch
1 parent 12c9e3f commit 6c84675

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

FirebaseAppDistribution/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [changed] Sign out the Tester when the call to fetch releases fails with an unauthenticated error.
3+
14
# v0.9.3
25
- [changed] Updated error log for non-200 API Service calls.
36

FirebaseAppDistribution/Sources/FIRAppDistribution.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ - (void)fetchNewLatestRelease:(void (^)(FIRAppDistributionRelease *_Nullable rel
252252
[FIRFADApiService
253253
fetchReleasesWithCompletion:^(NSArray *_Nullable releases, NSError *_Nullable error) {
254254
if (error) {
255+
if ([error code] == FIRFADApiErrorUnauthenticated) {
256+
FIRFADErrorLog(@"Tester authentication failed when fetching releases. Tester will need "
257+
@"to sign in again.");
258+
[self signOutTester];
259+
}
260+
255261
dispatch_async(dispatch_get_main_queue(), ^{
256262
completion(nil, [self mapFetchReleasesError:error]);
257263
});

FirebaseAppDistribution/Tests/Unit/FIRAppDistributionTests.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,33 @@ - (void)testFetchNewLatestReleaseFailure {
355355
OCMReject([_mockMachO codeHash]);
356356
}
357357

358+
- (void)testFetchNewLatestReleaseUnauthenticatedFailure {
359+
NSError *mockError =
360+
[NSError errorWithDomain:kFIRFADApiErrorDomain
361+
code:FIRFADApiErrorUnauthenticated
362+
userInfo:@{NSLocalizedDescriptionKey : @"This is unfortunate."}];
363+
[self mockFetchReleasesCompletion:nil error:mockError];
364+
OCMStub([_mockMachO codeHash]).andReturn(@"this-is-old");
365+
[[GULUserDefaults standardUserDefaults] setBool:YES forKey:@"FIRFADSignInState"];
366+
XCTAssertTrue([[self appDistribution] isTesterSignedIn]);
367+
368+
XCTestExpectation *expectation = [self expectationWithDescription:@"Fetch latest release fails."];
369+
370+
[[self appDistribution] fetchNewLatestRelease:^(FIRAppDistributionRelease *_Nullable release,
371+
NSError *_Nullable error) {
372+
XCTAssertNil(release);
373+
XCTAssertNotNil(error);
374+
XCTAssertEqual([error code], FIRAppDistributionErrorAuthenticationFailure);
375+
XCTAssertEqual([error domain], FIRAppDistributionErrorDomain);
376+
XCTAssertFalse([[self appDistribution] isTesterSignedIn]);
377+
[expectation fulfill];
378+
}];
379+
380+
[self waitForExpectations:@[ expectation ] timeout:5.0];
381+
[self verifyFetchReleasesCompletion];
382+
OCMReject([_mockMachO codeHash]);
383+
}
384+
358385
- (void)testCheckForUpdateWithCompletionTesterSignedIn {
359386
[self mockInstallationIdCompletion:_mockInstallationId error:nil];
360387
[self mockUIServiceRegistrationCompletion:nil];

0 commit comments

Comments
 (0)