Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.

# 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
5 changes: 5 additions & 0 deletions FirebaseAppDistribution/Sources/FIRAppDistribution.m
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ - (void)fetchNewLatestRelease:(void (^)(FIRAppDistributionRelease *_Nullable rel
@"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(), ^{
completion(nil, [self mapFetchReleasesError:error]);
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