Repository navigation
Expand file tree
/
Copy pathFirebaseProjectManagementIT.java
More file actions
256 lines (221 loc) · 10 KB
/
Copy pathFirebaseProjectManagementIT.java
File metadata and controls
256 lines (221 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.firebase.projectmanagement;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.google.common.base.Strings;
import com.google.firebase.testing.IntegrationTestUtils;
import java.util.List;
import java.util.Random;
import org.junit.BeforeClass;
import org.junit.Test;
public class FirebaseProjectManagementIT {
private static final String TEST_APP_DISPLAY_NAME_PREFIX =
"Created By Firebase AdminSDK Java Integration Testing";
private static final String TEST_APP_BUNDLE_ID = "com.firebase.adminsdk-java-integration-test";
private static final String TEST_APP_PACKAGE_NAME = "com.firebase.adminsdk_java_integration_test";
// Commenting out SHA1 tests until we have a fix for b/185268518
// private static final String TEST_SHA1_CERTIFICATE = "1111111111111111111111111111111111111111";
private static final String TEST_SHA256_CERTIFICATE =
"AAAACCCCAAAACCCCAAAACCCCAAAACCCCAAAACCCCAAAACCCCAAAACCCCAAAACCCC";
private static final Random random = new Random();
private static String testIosAppId;
private static String testAndroidAppId;
@BeforeClass
public static void setUpClass() throws Exception {
IntegrationTestUtils.ensureDefaultApp();
FirebaseProjectManagement projectManagement = FirebaseProjectManagement.getInstance();
// Ensure that we have created a Test iOS App.
List<IosApp> iosApps = projectManagement.listIosApps();
for (IosApp iosApp : iosApps) {
if (Strings.nullToEmpty(iosApp.getMetadata().getDisplayName())
.startsWith(TEST_APP_DISPLAY_NAME_PREFIX)) {
testIosAppId = iosApp.getAppId();
}
}
if (Strings.isNullOrEmpty(testIosAppId)) {
IosApp iosApp =
projectManagement.createIosApp(TEST_APP_BUNDLE_ID, TEST_APP_DISPLAY_NAME_PREFIX);
testIosAppId = iosApp.getAppId();
}
// Ensure that we have created a Test Android App.
List<AndroidApp> androidApps = projectManagement.listAndroidApps();
for (AndroidApp androidApp : androidApps) {
if (Strings.nullToEmpty(androidApp.getMetadata().getDisplayName())
.startsWith(TEST_APP_DISPLAY_NAME_PREFIX)) {
testAndroidAppId = androidApp.getAppId();
}
}
if (Strings.isNullOrEmpty(testAndroidAppId)) {
AndroidApp androidApp =
projectManagement.createAndroidApp(TEST_APP_PACKAGE_NAME, TEST_APP_DISPLAY_NAME_PREFIX);
testAndroidAppId = androidApp.getAppId();
}
}
/* Android App Integration Tests */
@Test
public void testAndroidSetDisplayNameAndGetMetadata() throws Exception {
FirebaseProjectManagement projectManagement = FirebaseProjectManagement.getInstance();
AndroidApp androidApp = projectManagement.getAndroidApp(testAndroidAppId);
// Use the synchronous version of the API.
{
int randomInt = Math.abs(random.nextInt());
String newDisplayName = TEST_APP_DISPLAY_NAME_PREFIX + " helloworld " + randomInt;
androidApp.setDisplayName(newDisplayName);
AndroidAppMetadata metadata = androidApp.getMetadata();
assertEquals(
String.format(
"projects/%s/androidApps/%s", IntegrationTestUtils.getProjectId(), testAndroidAppId),
metadata.getName());
assertEquals(IntegrationTestUtils.getProjectId(), metadata.getProjectId());
assertEquals(testAndroidAppId, metadata.getAppId());
assertEquals(newDisplayName, metadata.getDisplayName());
assertEquals(TEST_APP_PACKAGE_NAME, metadata.getPackageName());
}
// Change the display name back when done. Use the asynchronous version.
{
androidApp.setDisplayNameAsync(TEST_APP_DISPLAY_NAME_PREFIX).get();
AndroidAppMetadata metadata = androidApp.getMetadataAsync().get();
assertEquals(
String.format(
"projects/%s/androidApps/%s", IntegrationTestUtils.getProjectId(), testAndroidAppId),
metadata.getName());
assertEquals(IntegrationTestUtils.getProjectId(), metadata.getProjectId());
assertEquals(testAndroidAppId, metadata.getAppId());
assertEquals(TEST_APP_DISPLAY_NAME_PREFIX, metadata.getDisplayName());
assertEquals(TEST_APP_PACKAGE_NAME, metadata.getPackageName());
}
}
@Test
public void testAndroidCertificates() throws Exception {
FirebaseProjectManagement projectManagement = FirebaseProjectManagement.getInstance();
AndroidApp androidApp = projectManagement.getAndroidApp(testAndroidAppId);
// Commenting out SHA1 tests until we have a fix for b/185268518
// // Use the Synchronous version of the API.
// {
// // Add SHA-1 certificate.
// androidApp.createShaCertificate(ShaCertificate.create(TEST_SHA1_CERTIFICATE));
// List<ShaCertificate> certificates = androidApp.getShaCertificates();
// ShaCertificate expectedCertificate = null;
// for (ShaCertificate certificate : certificates) {
// if (certificate.getShaHash().equals(TEST_SHA1_CERTIFICATE.toLowerCase())) {
// expectedCertificate = certificate;
// }
// }
// assertNotNull(expectedCertificate);
// assertEquals(expectedCertificate.getCertType(), ShaCertificateType.SHA_1);
//
// // Delete SHA-1 certificate.
// androidApp.deleteShaCertificate(expectedCertificate);
// for (ShaCertificate certificate : androidApp.getShaCertificates()) {
// if (certificate.getShaHash().equals(TEST_SHA1_CERTIFICATE)) {
// fail("Test SHA-1 certificate is not deleted.");
// }
// }
// }
// Use the asynchronous version of the API.
{
// Add SHA-256 certificate.
androidApp.createShaCertificateAsync(ShaCertificate.create(TEST_SHA256_CERTIFICATE)).get();
List<ShaCertificate> certificates = androidApp.getShaCertificatesAsync().get();
ShaCertificate expectedCertificate = null;
for (ShaCertificate certificate : certificates) {
if (certificate.getShaHash().equals(TEST_SHA256_CERTIFICATE.toLowerCase())) {
expectedCertificate = certificate;
}
}
assertNotNull(expectedCertificate);
assertEquals(expectedCertificate.getCertType(), ShaCertificateType.SHA_256);
// Delete SHA-256 certificate.
androidApp.deleteShaCertificateAsync(expectedCertificate).get();
for (ShaCertificate certificate : androidApp.getShaCertificatesAsync().get()) {
if (certificate.getShaHash().equals(TEST_SHA256_CERTIFICATE)) {
fail("Test SHA-1 certificate is not deleted.");
}
}
}
}
@Test
public void testAndroidGetConfig() throws Exception {
FirebaseProjectManagement projectManagement = FirebaseProjectManagement.getInstance();
AndroidApp androidApp = projectManagement.getAndroidApp(testAndroidAppId);
// Test the synchronous version.
{
String config = androidApp.getConfig();
assertTrue(config.contains(IntegrationTestUtils.getProjectId()));
assertTrue(config.contains(testAndroidAppId));
}
// Test the asynchronous version.
{
String config = androidApp.getConfigAsync().get();
assertTrue(config.contains(IntegrationTestUtils.getProjectId()));
assertTrue(config.contains(testAndroidAppId));
}
}
/* iOS App Integration Tests */
@Test
public void testIosSetDisplayNameAndGetMetadata() throws Exception {
FirebaseProjectManagement projectManagement = FirebaseProjectManagement.getInstance();
IosApp iosApp = projectManagement.getIosApp(testIosAppId);
// Use the synchronous version of the API.
{
int randomInt = Math.abs(random.nextInt());
String newDisplayName = TEST_APP_DISPLAY_NAME_PREFIX + " helloworld " + randomInt;
iosApp.setDisplayName(newDisplayName);
IosAppMetadata metadata = iosApp.getMetadata();
assertEquals(
String.format(
"projects/%s/iosApps/%s", IntegrationTestUtils.getProjectId(), testIosAppId),
metadata.getName());
assertEquals(IntegrationTestUtils.getProjectId(), metadata.getProjectId());
assertEquals(testIosAppId, metadata.getAppId());
assertEquals(newDisplayName, metadata.getDisplayName());
assertEquals(TEST_APP_BUNDLE_ID, metadata.getBundleId());
}
// Change the display name back when done. Use the asynchronous version.
{
iosApp.setDisplayNameAsync(TEST_APP_DISPLAY_NAME_PREFIX).get();
IosAppMetadata metadata = iosApp.getMetadataAsync().get();
assertEquals(
String.format(
"projects/%s/iosApps/%s", IntegrationTestUtils.getProjectId(), testIosAppId),
metadata.getName());
assertEquals(IntegrationTestUtils.getProjectId(), metadata.getProjectId());
assertEquals(testIosAppId, metadata.getAppId());
assertEquals(TEST_APP_DISPLAY_NAME_PREFIX, metadata.getDisplayName());
assertEquals(TEST_APP_BUNDLE_ID, metadata.getBundleId());
}
}
@Test
public void testIosGetConfig() throws Exception {
FirebaseProjectManagement projectManagement = FirebaseProjectManagement.getInstance();
IosApp iosApp = projectManagement.getIosApp(testIosAppId);
// Test the synchronous version.
{
String config = iosApp.getConfig();
assertTrue(config.contains(IntegrationTestUtils.getProjectId()));
assertTrue(config.contains(testIosAppId));
}
// Test the asynchronous version.
{
String config = iosApp.getConfigAsync().get();
assertTrue(config.contains(IntegrationTestUtils.getProjectId()));
assertTrue(config.contains(testIosAppId));
}
}
}