2626import com .google .api .client .googleapis .util .Utils ;
2727import com .google .api .client .json .JsonFactory ;
2828import com .google .common .collect .ImmutableList ;
29+ import com .google .common .io .BaseEncoding ;
2930import com .google .firebase .auth .ListUsersPage .ListUsersResult ;
3031import com .google .firebase .auth .internal .DownloadAccountResponse ;
3132import java .io .IOException ;
3839
3940public class ListUsersPageTest {
4041
42+ private static final String REDACTED_BASE64 = BaseEncoding .base64Url ().encode (
43+ "REDACTED" .getBytes ());
44+
4145 @ Test
4246 public void testSinglePage () throws FirebaseAuthException , IOException {
4347 TestUserSource source = new TestUserSource (3 );
@@ -55,6 +59,30 @@ public void testSinglePage() throws FirebaseAuthException, IOException {
5559 assertNull (source .calls .get (0 ));
5660 }
5761
62+ @ Test
63+ public void testRedactedPasswords () throws FirebaseAuthException , IOException {
64+ ListUsersResult result = new ListUsersResult (
65+ ImmutableList .of (
66+ newUser ("user0" , REDACTED_BASE64 ),
67+ newUser ("user1" , REDACTED_BASE64 ),
68+ newUser ("user2" , REDACTED_BASE64 )),
69+ ListUsersPage .END_OF_LIST );
70+ TestUserSource source = new TestUserSource (result );
71+ ListUsersPage page = new ListUsersPage .PageFactory (source ).create ();
72+ assertFalse (page .hasNextPage ());
73+ assertEquals (ListUsersPage .END_OF_LIST , page .getNextPageToken ());
74+ assertNull (page .getNextPage ());
75+
76+ ImmutableList <ExportedUserRecord > users = ImmutableList .copyOf (page .getValues ());
77+ assertEquals (3 , users .size ());
78+ for (int i = 0 ; i < 3 ; i ++) {
79+ assertEquals ("user" + i , users .get (i ).getUid ());
80+ assertNull (users .get (i ).getPasswordHash ());
81+ }
82+ assertEquals (1 , source .calls .size ());
83+ assertNull (source .calls .get (0 ));
84+ }
85+
5886 @ Test
5987 public void testMultiplePages () throws FirebaseAuthException , IOException {
6088 ListUsersResult result = new ListUsersResult (
@@ -326,6 +354,14 @@ private static ExportedUserRecord newUser(String uid) throws IOException {
326354 return new ExportedUserRecord (parsed , jsonFactory );
327355 }
328356
357+ private static ExportedUserRecord newUser (String uid , String passwordHash ) throws IOException {
358+ JsonFactory jsonFactory = Utils .getDefaultJsonFactory ();
359+ DownloadAccountResponse .User parsed = jsonFactory .fromString (
360+ String .format ("{\" localId\" :\" %s\" , \" passwordHash\" :\" %s\" }" , uid , passwordHash ),
361+ DownloadAccountResponse .User .class );
362+ return new ExportedUserRecord (parsed , jsonFactory );
363+ }
364+
329365 private static class TestUserSource implements ListUsersPage .UserSource {
330366
331367 private ListUsersResult result ;
0 commit comments