26
26
import com .google .api .client .googleapis .util .Utils ;
27
27
import com .google .api .client .json .JsonFactory ;
28
28
import com .google .common .collect .ImmutableList ;
29
+ import com .google .common .io .BaseEncoding ;
29
30
import com .google .firebase .auth .ListUsersPage .ListUsersResult ;
30
31
import com .google .firebase .auth .internal .DownloadAccountResponse ;
31
32
import java .io .IOException ;
38
39
39
40
public class ListUsersPageTest {
40
41
42
+ private static final String REDACTED_BASE64 = BaseEncoding .base64Url ().encode (
43
+ "REDACTED" .getBytes ());
44
+
41
45
@ Test
42
46
public void testSinglePage () throws FirebaseAuthException , IOException {
43
47
TestUserSource source = new TestUserSource (3 );
@@ -55,6 +59,30 @@ public void testSinglePage() throws FirebaseAuthException, IOException {
55
59
assertNull (source .calls .get (0 ));
56
60
}
57
61
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
+
58
86
@ Test
59
87
public void testMultiplePages () throws FirebaseAuthException , IOException {
60
88
ListUsersResult result = new ListUsersResult (
@@ -326,6 +354,14 @@ private static ExportedUserRecord newUser(String uid) throws IOException {
326
354
return new ExportedUserRecord (parsed , jsonFactory );
327
355
}
328
356
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
+
329
365
private static class TestUserSource implements ListUsersPage .UserSource {
330
366
331
367
private ListUsersResult result ;
0 commit comments