Skip to content

Commit f59f769

Browse files
author
rachaprince
authored
[App Distribution] Reset sign in flag on unauthorized error (#8270)
* [App Distribution] Reset sign in flag on unauthorized error * Fix formatting and update CHANGELOG
1 parent 5abd0c8 commit f59f769

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-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 unauthorized error (#8270).
3+
14
# v7.3.0-beta
25
- [changed] Sign out the Tester when the call to fetch releases fails with an unauthenticated error.
36
- [fixed] Crash caused by trying to parse response as JSON when response is nil (#6996).

FirebaseAppDistribution/Sources/FIRAppDistribution.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ - (void)fetchNewLatestRelease:(void (^)(FIRAppDistributionRelease *_Nullable rel
252252
FIRFADErrorLog(@"Tester authentication failed when fetching releases. Tester will need "
253253
@"to sign in again.");
254254
[self signOutTester];
255+
} else if ([error code] == FIRFADApiErrorUnauthorized) {
256+
FIRFADErrorLog(@"Tester is not authorized to view releases for this app. Tester will "
257+
@"need to sign in again.");
258+
[self signOutTester];
255259
}
256260

257261
dispatch_async(dispatch_get_main_queue(), ^{

FirebaseAppDistribution/Tests/Unit/FIRAppDistributionTests.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,33 @@ - (void)testFetchNewLatestReleaseUnauthenticatedFailure {
382382
OCMReject([_mockMachO codeHash]);
383383
}
384384

385+
- (void)testFetchNewLatestReleaseUnauthorizedFailure {
386+
NSError *mockError =
387+
[NSError errorWithDomain:kFIRFADApiErrorDomain
388+
code:FIRFADApiErrorUnauthorized
389+
userInfo:@{NSLocalizedDescriptionKey : @"This is unfortunate."}];
390+
[self mockFetchReleasesCompletion:nil error:mockError];
391+
OCMStub([_mockMachO codeHash]).andReturn(@"this-is-old");
392+
[[GULUserDefaults standardUserDefaults] setBool:YES forKey:@"FIRFADSignInState"];
393+
XCTAssertTrue([[self appDistribution] isTesterSignedIn]);
394+
395+
XCTestExpectation *expectation = [self expectationWithDescription:@"Fetch latest release fails."];
396+
397+
[[self appDistribution] fetchNewLatestRelease:^(FIRAppDistributionRelease *_Nullable release,
398+
NSError *_Nullable error) {
399+
XCTAssertNil(release);
400+
XCTAssertNotNil(error);
401+
XCTAssertEqual([error code], FIRAppDistributionErrorAuthenticationFailure);
402+
XCTAssertEqual([error domain], FIRAppDistributionErrorDomain);
403+
XCTAssertFalse([[self appDistribution] isTesterSignedIn]);
404+
[expectation fulfill];
405+
}];
406+
407+
[self waitForExpectations:@[ expectation ] timeout:5.0];
408+
[self verifyFetchReleasesCompletion];
409+
OCMReject([_mockMachO codeHash]);
410+
}
411+
385412
- (void)testCheckForUpdateWithCompletionTesterSignedIn {
386413
[self mockInstallationIdCompletion:_mockInstallationId error:nil];
387414
[self mockUIServiceRegistrationCompletion:nil];

0 commit comments

Comments
 (0)