1616
1717package com .google .firebase .database .integration ;
1818
19- import static org .junit .Assert .assertEquals ;
2019import static org .junit .Assert .assertTrue ;
2120
2221import com .google .api .core .ApiFutureCallback ;
3332import com .google .firebase .database .TestHelpers ;
3433import com .google .firebase .database .ValueEventListener ;
3534import com .google .firebase .testing .IntegrationTestUtils ;
36- import com .google .firebase .testing .IntegrationTestUtils .AppHttpClient ;
37- import com .google .firebase .testing .IntegrationTestUtils .ResponseInfo ;
3835import com .google .firebase .testing .ServiceAccount ;
3936import com .google .firebase .testing .TestUtils ;
4037import java .io .IOException ;
4946import org .junit .Test ;
5047
5148public class FirebaseDatabaseAuthTestIT {
52-
49+
5350 private static FirebaseApp masterApp ;
54-
51+
5552 @ BeforeClass
56- public static void setUpClass () throws IOException {
53+ public static void setUpClass () throws IOException {
5754 masterApp = IntegrationTestUtils .ensureDefaultApp ();
5855 setDatabaseRules ();
5956 }
@@ -74,7 +71,7 @@ public void testAuthWithValidCertificateCredential() throws InterruptedException
7471 assertWriteSucceeds (db .getReference ());
7572 assertReadSucceeds (db .getReference ());
7673 }
77-
74+
7875 @ Test
7976 public void testAuthWithInvalidCertificateCredential () throws InterruptedException , IOException {
8077 FirebaseOptions options =
@@ -87,7 +84,7 @@ public void testAuthWithInvalidCertificateCredential() throws InterruptedExcepti
8784 // TODO: Ideally, we would find a way to verify the correct log output.
8885 assertWriteTimeout (db .getReference ());
8986 }
90-
87+
9188 @ Test
9289 public void testDatabaseAuthVariablesAuthorization () throws InterruptedException {
9390 Map <String , Object > authVariableOverrides = ImmutableMap .<String , Object >of (
@@ -110,7 +107,7 @@ public void testDatabaseAuthVariablesAuthorization() throws InterruptedException
110107 assertWriteSucceeds (testAuthOverridesDb .getReference ("test-custom-field-only" ));
111108 assertReadSucceeds (testAuthOverridesDb .getReference ("test-custom-field-only" ));
112109 }
113-
110+
114111 @ Test
115112 public void testDatabaseAuthVariablesNoAuthorization () throws InterruptedException {
116113 FirebaseOptions options = masterApp .getOptions ().toBuilder ()
@@ -128,25 +125,25 @@ public void testDatabaseAuthVariablesNoAuthorization() throws InterruptedExcepti
128125 assertReadFails (testAuthOverridesDb .getReference ("test-uid-only" ));
129126 assertWriteFails (testAuthOverridesDb .getReference ("test-custom-field-only" ));
130127 assertReadFails (testAuthOverridesDb .getReference ("test-custom-field-only" ));
131- assertWriteSucceeds (testAuthOverridesDb .getReference ("test-noauth-only" ));
128+ assertWriteSucceeds (testAuthOverridesDb .getReference ("test-noauth-only" ));
132129 }
133-
130+
134131 private static void assertWriteSucceeds (DatabaseReference ref ) throws InterruptedException {
135132 doWrite (ref , /*shouldSucceed=*/ true , /*shouldTimeout=*/ false );
136133 }
137-
134+
138135 private static void assertWriteFails (DatabaseReference ref ) throws InterruptedException {
139136 doWrite (ref , /*shouldSucceed=*/ false , /*shouldTimeout=*/ false );
140137 }
141-
138+
142139 private static void assertWriteTimeout (DatabaseReference ref ) throws InterruptedException {
143140 doWrite (ref , /*shouldSucceed=*/ false , /*shouldTimeout=*/ true );
144141 }
145-
142+
146143 private static void assertReadSucceeds (DatabaseReference ref ) throws InterruptedException {
147144 doRead (ref , /*shouldSucceed=*/ true , /*shouldTimeout=*/ false );
148145 }
149-
146+
150147 private static void assertReadFails (DatabaseReference ref ) throws InterruptedException {
151148 doRead (ref , /*shouldSucceed=*/ false , /*shouldTimeout=*/ false );
152149 }
@@ -180,7 +177,7 @@ public void onSuccess(Void result) {
180177 assertTrue ("Write successful (expected to fail)." , !success .get ());
181178 }
182179 }
183-
180+
184181 private static void doRead (
185182 DatabaseReference ref , final boolean shouldSucceed , final boolean shouldTimeout )
186183 throws InterruptedException {
@@ -211,9 +208,9 @@ public void onCancelled(DatabaseError databaseError) {
211208 assertTrue ("Read successful (expected to fail)." , !success .get ());
212209 }
213210 }
214-
211+
215212 private static void setDatabaseRules () throws IOException {
216- // TODO: Use more than uid in rule Set rules so the only allowed operation is writing to
213+ // TODO: Use more than uid in rule Set rules so the only allowed operation is writing to
217214 // /test-uid-only by user with uid 'test'.
218215 String rules =
219216 "{\n "
@@ -232,8 +229,7 @@ private static void setDatabaseRules() throws IOException {
232229 + " }\n "
233230 + "}" ;
234231
235- AppHttpClient client = new AppHttpClient ();
236- ResponseInfo info = client .put ("/.settings/rules.json" , rules );
237- assertEquals (200 , info .getStatus ());
232+ RulesClient client = new RulesClient ();
233+ client .updateRules (rules );
238234 }
239235}
0 commit comments