|
20 | 20 | import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
|
21 | 21 | import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
|
22 | 22 | import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
|
| 23 | +import static com.google.common.truth.Truth.assertThat; |
23 | 24 | import static com.google.common.truth.Truth.assertWithMessage;
|
24 | 25 | import static org.mockito.ArgumentMatchers.any;
|
25 | 26 | import static org.mockito.ArgumentMatchers.anyBoolean;
|
|
52 | 53 | import org.junit.Rule;
|
53 | 54 | import org.junit.Test;
|
54 | 55 | import org.junit.runner.RunWith;
|
| 56 | +import org.mockito.ArgumentCaptor; |
55 | 57 | import org.mockito.Mock;
|
56 | 58 | import org.mockito.MockitoAnnotations;
|
57 | 59 | import org.robolectric.RobolectricTestRunner;
|
@@ -708,6 +710,38 @@ public void downloadService_unauthenticatedToken() {
|
708 | 710 | any(), eq(false), eq(ErrorCode.MODEL_INFO_DOWNLOAD_CONNECTION_FAILED.getValue()));
|
709 | 711 | }
|
710 | 712 |
|
| 713 | + @Test |
| 714 | + public void downloadService_nullModelHashPassedUnauthenticatedToken() { |
| 715 | + when(installationsApiMock.getToken(anyBoolean())) |
| 716 | + .thenReturn(Tasks.forException(new IllegalArgumentException("bad request"))); |
| 717 | + |
| 718 | + CustomModelDownloadService service = |
| 719 | + new CustomModelDownloadService( |
| 720 | + ApplicationProvider.getApplicationContext(), |
| 721 | + installationsApiMock, |
| 722 | + directExecutor, |
| 723 | + API_KEY, |
| 724 | + PACKAGE_FINGERPRINT_HASH, |
| 725 | + TEST_ENDPOINT, |
| 726 | + mockEventLogger); |
| 727 | + |
| 728 | + Task<CustomModel> modelTask = service.getCustomModelDetails(PROJECT_ID, MODEL_NAME, null); |
| 729 | + |
| 730 | + Assert.assertTrue(modelTask.getException() instanceof FirebaseMlException); |
| 731 | + Assert.assertEquals( |
| 732 | + ((FirebaseMlException) modelTask.getException()).getCode(), |
| 733 | + FirebaseMlException.UNAUTHENTICATED); |
| 734 | + Assert.assertTrue(modelTask.getException().getMessage().contains("authentication error")); |
| 735 | + |
| 736 | + ArgumentCaptor<CustomModel> captor = ArgumentCaptor.forClass(CustomModel.class); |
| 737 | + verify(mockEventLogger, times(1)) |
| 738 | + .logDownloadFailureWithReason( |
| 739 | + captor.capture(), |
| 740 | + eq(false), |
| 741 | + eq(ErrorCode.MODEL_INFO_DOWNLOAD_CONNECTION_FAILED.getValue())); |
| 742 | + assertThat(captor.getValue().getModelHash()).isNotNull(); |
| 743 | + } |
| 744 | + |
711 | 745 | @Test
|
712 | 746 | public void downloadService_malFormedUrl() {
|
713 | 747 | CustomModelDownloadService service =
|
|
0 commit comments