Skip to content

Commit 24d79aa

Browse files
committed
Address Kai's feedback
1 parent 7b4bba8 commit 24d79aa

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/TesterApiHttpClient.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
class TesterApiHttpClient {
4040

4141
private static final String APP_TESTERS_HOST = "firebaseapptesters.googleapis.com";
42-
private static final String APP_TESTERS_UPLOAD_HOST = "firebaseapptesters.clients6.google.com";
4342
private static final String REQUEST_METHOD_GET = "GET";
4443
private static final String REQUEST_METHOD_POST = "POST";
4544
private static final String CONTENT_TYPE_HEADER_KEY = "Content-Type";
@@ -85,7 +84,7 @@ JSONObject makeGetRequest(String tag, String path, String token)
8584
throws FirebaseAppDistributionException {
8685
HttpsURLConnection connection = null;
8786
try {
88-
connection = openHttpsUrlConnection(getTesterApiUrl(APP_TESTERS_HOST, path), token);
87+
connection = openHttpsUrlConnection(getTesterApiUrl(path), token);
8988
return readResponse(tag, connection);
9089
} catch (IOException e) {
9190
throw getException(tag, ErrorMessages.NETWORK_ERROR, Status.NETWORK_FAILURE, e);
@@ -110,7 +109,7 @@ JSONObject makePostRequest(String tag, String path, String token, String request
110109
throw new FirebaseAppDistributionException(
111110
"Unsupported encoding: " + UTF_8, Status.UNKNOWN, e);
112111
}
113-
return makePostRequest(tag, APP_TESTERS_HOST, path, token, bytes, new HashMap<>());
112+
return makePostRequest(tag, path, token, bytes, new HashMap<>());
114113
}
115114

116115
/**
@@ -125,20 +124,19 @@ JSONObject makeUploadRequest(String tag, String path, String token, byte[] reque
125124
Map<String, String> extraHeaders = new HashMap<>();
126125
extraHeaders.put(X_GOOG_UPLOAD_PROTOCOL_HEADER, X_GOOG_UPLOAD_PROTOCOL_RAW);
127126
extraHeaders.put(X_GOOG_UPLOAD_FILE_NAME_HEADER, X_GOOG_UPLOAD_FILE_NAME);
128-
return makePostRequest(tag, APP_TESTERS_UPLOAD_HOST, path, token, requestBody, extraHeaders);
127+
return makePostRequest(tag, path, token, requestBody, extraHeaders);
129128
}
130129

131130
private JSONObject makePostRequest(
132131
String tag,
133-
String host,
134132
String path,
135133
String token,
136134
byte[] requestBody,
137135
Map<String, String> extraHeaders)
138136
throws FirebaseAppDistributionException {
139137
HttpsURLConnection connection = null;
140138
try {
141-
connection = openHttpsUrlConnection(getTesterApiUrl(host, path), token);
139+
connection = openHttpsUrlConnection(getTesterApiUrl(path), token);
142140
connection.setDoOutput(true);
143141
connection.setRequestMethod(REQUEST_METHOD_POST);
144142
connection.addRequestProperty(CONTENT_TYPE_HEADER_KEY, JSON_CONTENT_TYPE);
@@ -164,8 +162,8 @@ private JSONObject makePostRequest(
164162
}
165163
}
166164

167-
private static String getTesterApiUrl(String host, String path) {
168-
return String.format("https://%s/%s", host, path);
165+
private static String getTesterApiUrl(String path) {
166+
return String.format("https://%s/%s", APP_TESTERS_HOST, path);
169167
}
170168

171169
private static JSONObject readResponse(String tag, HttpsURLConnection connection)

firebase-appdistribution/src/test/java/com/google/firebase/appdistribution/impl/TesterApiHttpClientTest.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ public class TesterApiHttpClientTest {
5353
private static final String TEST_PATH = "some/url/path";
5454
private static final String TEST_URL =
5555
String.format("https://firebaseapptesters.googleapis.com/%s", TEST_PATH);
56-
private static final String TEST_UPLOAD_URL =
57-
String.format("https://firebaseapptesters.clients6.google.com/%s", TEST_PATH);
5856
private static final String TAG = "Test Tag";
5957
private static final String TEST_POST_BODY = "Post body";
6058

@@ -76,12 +74,13 @@ public void setup() throws Exception {
7674
.setApiKey(TEST_API_KEY)
7775
.build());
7876

77+
when(mockHttpsURLConnectionFactory.openConnection(TEST_URL)).thenReturn(mockHttpsURLConnection);
78+
7979
testerApiHttpClient = new TesterApiHttpClient(firebaseApp, mockHttpsURLConnectionFactory);
8080
}
8181

8282
@Test
8383
public void makeGetRequest_whenResponseSuccessful_returnsJsonResponse() throws Exception {
84-
when(mockHttpsURLConnectionFactory.openConnection(TEST_URL)).thenReturn(mockHttpsURLConnection);
8584
String responseJson = readTestFile("testSimpleResponse.json");
8685
InputStream responseInputStream =
8786
new ByteArrayInputStream(responseJson.getBytes(UTF_8));
@@ -97,7 +96,6 @@ public void makeGetRequest_whenResponseSuccessful_returnsJsonResponse() throws E
9796

9897
@Test
9998
public void makeGetRequest_whenConnectionFails_throwsError() throws Exception {
100-
when(mockHttpsURLConnectionFactory.openConnection(TEST_URL)).thenReturn(mockHttpsURLConnection);
10199
IOException caughtException = new IOException("error");
102100
when(mockHttpsURLConnectionFactory.openConnection(TEST_URL)).thenThrow(caughtException);
103101

@@ -113,7 +111,6 @@ public void makeGetRequest_whenConnectionFails_throwsError() throws Exception {
113111

114112
@Test
115113
public void makeGetRequest_whenInvalidJson_throwsError() throws Exception {
116-
when(mockHttpsURLConnectionFactory.openConnection(TEST_URL)).thenReturn(mockHttpsURLConnection);
117114
InputStream response =
118115
new ByteArrayInputStream(INVALID_RESPONSE.getBytes(UTF_8));
119116
when(mockHttpsURLConnection.getInputStream()).thenReturn(response);
@@ -132,7 +129,6 @@ public void makeGetRequest_whenInvalidJson_throwsError() throws Exception {
132129

133130
@Test
134131
public void makeGetRequest_whenResponseFailsWith401_throwsError() throws Exception {
135-
when(mockHttpsURLConnectionFactory.openConnection(TEST_URL)).thenReturn(mockHttpsURLConnection);
136132
when(mockHttpsURLConnection.getResponseCode()).thenReturn(401);
137133
when(mockHttpsURLConnection.getInputStream()).thenThrow(new IOException("error"));
138134

@@ -149,7 +145,6 @@ public void makeGetRequest_whenResponseFailsWith401_throwsError() throws Excepti
149145

150146
@Test
151147
public void makeGetRequest_whenResponseFailsWith403_throwsError() throws Exception {
152-
when(mockHttpsURLConnectionFactory.openConnection(TEST_URL)).thenReturn(mockHttpsURLConnection);
153148
when(mockHttpsURLConnection.getResponseCode()).thenReturn(403);
154149
when(mockHttpsURLConnection.getInputStream()).thenThrow(new IOException("error"));
155150

@@ -166,7 +161,6 @@ public void makeGetRequest_whenResponseFailsWith403_throwsError() throws Excepti
166161

167162
@Test
168163
public void makeGetRequest_whenResponseFailsWith404_throwsError() throws Exception {
169-
when(mockHttpsURLConnectionFactory.openConnection(TEST_URL)).thenReturn(mockHttpsURLConnection);
170164
when(mockHttpsURLConnection.getResponseCode()).thenReturn(404);
171165
when(mockHttpsURLConnection.getInputStream()).thenThrow(new IOException("error"));
172166

@@ -183,7 +177,6 @@ public void makeGetRequest_whenResponseFailsWith404_throwsError() throws Excepti
183177

184178
@Test
185179
public void makeGetRequest_whenResponseFailsWithUnknownCode_throwsError() throws Exception {
186-
when(mockHttpsURLConnectionFactory.openConnection(TEST_URL)).thenReturn(mockHttpsURLConnection);
187180
when(mockHttpsURLConnection.getResponseCode()).thenReturn(409);
188181
when(mockHttpsURLConnection.getInputStream()).thenThrow(new IOException("error"));
189182

@@ -200,7 +193,6 @@ public void makeGetRequest_whenResponseFailsWithUnknownCode_throwsError() throws
200193

201194
@Test
202195
public void makePostRequest_zipsRequestBodyAndSetsCorrectHeaders() throws Exception {
203-
when(mockHttpsURLConnectionFactory.openConnection(TEST_URL)).thenReturn(mockHttpsURLConnection);
204196
String responseJson = readTestFile("testSimpleResponse.json");
205197
InputStream responseInputStream =
206198
new ByteArrayInputStream(responseJson.getBytes(UTF_8));
@@ -224,7 +216,6 @@ public void makePostRequest_zipsRequestBodyAndSetsCorrectHeaders() throws Except
224216

225217
@Test
226218
public void makePostRequest_whenConnectionFails_throwsError() throws Exception {
227-
when(mockHttpsURLConnectionFactory.openConnection(TEST_URL)).thenReturn(mockHttpsURLConnection);
228219
IOException caughtException = new IOException("error");
229220
when(mockHttpsURLConnectionFactory.openConnection(TEST_URL)).thenThrow(caughtException);
230221

@@ -240,7 +231,6 @@ public void makePostRequest_whenConnectionFails_throwsError() throws Exception {
240231

241232
@Test
242233
public void makeUploadRequest_zipsRequestBodyAndSetsCorrectHeaders() throws Exception {
243-
when(mockHttpsURLConnectionFactory.openConnection(TEST_UPLOAD_URL)).thenReturn(mockHttpsURLConnection);
244234
String responseJson = readTestFile("testSimpleResponse.json");
245235
InputStream responseInputStream =
246236
new ByteArrayInputStream(responseJson.getBytes(UTF_8));

0 commit comments

Comments
 (0)