Skip to content
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
3 changes: 3 additions & 0 deletions FirebaseAppDistribution/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [changed] Sign out the Tester when the call to fetch releases fails with an unauthorized error (#8270).

# v7.3.0-beta
- [changed] Sign out the Tester when the call to fetch releases fails with an unauthenticated error.
- [fixed] Crash caused by trying to parse response as JSON when response is nil (#6996).
Expand Down
4 changes: 4 additions & 0 deletions FirebaseAppDistribution/Sources/FIRAppDistribution.m
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ - (void)fetchNewLatestRelease:(void (^)(FIRAppDistributionRelease *_Nullable rel
FIRFADErrorLog(@"Tester authentication failed when fetching releases. Tester will need "
@"to sign in again.");
[self signOutTester];
} else if ([error code] == FIRFADApiErrorUnauthorized) {
FIRFADErrorLog(@"Tester is not authorized to view releases for this app. Tester will "
@"need to sign in again.");
[self signOutTester];
}

dispatch_async(dispatch_get_main_queue(), ^{
Expand Down
27 changes: 27 additions & 0 deletions FirebaseAppDistribution/Tests/Unit/FIRAppDistributionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,33 @@ - (void)testFetchNewLatestReleaseUnauthenticatedFailure {
OCMReject([_mockMachO codeHash]);
}

- (void)testFetchNewLatestReleaseUnauthorizedFailure {
NSError *mockError =
[NSError errorWithDomain:kFIRFADApiErrorDomain
code:FIRFADApiErrorUnauthorized
userInfo:@{NSLocalizedDescriptionKey : @"This is unfortunate."}];
[self mockFetchReleasesCompletion:nil error:mockError];
OCMStub([_mockMachO codeHash]).andReturn(@"this-is-old");
[[GULUserDefaults standardUserDefaults] setBool:YES forKey:@"FIRFADSignInState"];
XCTAssertTrue([[self appDistribution] isTesterSignedIn]);

XCTestExpectation *expectation = [self expectationWithDescription:@"Fetch latest release fails."];

[[self appDistribution] fetchNewLatestRelease:^(FIRAppDistributionRelease *_Nullable release,
NSError *_Nullable error) {
XCTAssertNil(release);
XCTAssertNotNil(error);
XCTAssertEqual([error code], FIRAppDistributionErrorAuthenticationFailure);
XCTAssertEqual([error domain], FIRAppDistributionErrorDomain);
XCTAssertFalse([[self appDistribution] isTesterSignedIn]);
[expectation fulfill];
}];

[self waitForExpectations:@[ expectation ] timeout:5.0];
[self verifyFetchReleasesCompletion];
OCMReject([_mockMachO codeHash]);
}

- (void)testCheckForUpdateWithCompletionTesterSignedIn {
[self mockInstallationIdCompletion:_mockInstallationId error:nil];
[self mockUIServiceRegistrationCompletion:nil];
Expand Down